blob: 34ec8923ebe4eb9d6ed03c99f62a91d245e7d5d8 [file] [log] [blame]
[email protected]7e7414ae2010-01-26 20:19:291// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]a92b8642009-05-05 23:38:569#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1110#include "app/resource_bundle.h"
[email protected]39553442010-09-09 00:01:5511#if defined(OS_MACOSX)
12#include "app/surface/io_surface_support_mac.h"
13#endif
[email protected]614519812010-03-19 08:20:5614#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4915#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3216#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0117#include "base/i18n/rtl.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]420ae012009-04-24 05:16:3219#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5420#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3721#include "base/string_util.h"
[email protected]440b37b22010-08-30 05:31:4022#include "base/utf_string_conversions.h"
[email protected]96d185d2009-04-24 03:28:5423#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4524#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2125#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4026#include "chrome/browser/blocked_content_container.h"
[email protected]420ae012009-04-24 05:16:3227#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5428#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5529#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1031#include "chrome/browser/character_encoding.h"
[email protected]5f24f212010-12-02 14:47:4532#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3333#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5434#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1435#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3236#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5437#include "chrome/browser/dom_ui/dom_ui.h"
38#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0239#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3240#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0141#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4942#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0843#include "chrome/browser/extensions/extensions_service.h"
[email protected]ec0b6c42010-08-26 03:16:5844#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4245#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2546#include "chrome/browser/host_zoom_map.h"
[email protected]0189bc722009-08-28 21:56:4847#include "chrome/browser/favicon_service.h"
[email protected]ba70d082010-09-10 16:54:4948#include "chrome/browser/file_select_helper.h"
[email protected]f7578f52010-08-30 22:22:4949#include "chrome/browser/google/google_util.h"
[email protected]8897c382009-05-06 17:53:2650#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0751#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3252#include "chrome/browser/load_from_memory_cache_details.h"
53#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4454#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0555#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1056#include "chrome/browser/omnibox_search_hint.h"
[email protected]14a000d2010-04-29 21:44:2457#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5758#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0259#include "chrome/browser/prefs/pref_service.h"
[email protected]33f74972010-12-08 16:40:3660#include "chrome/browser/prerender/prerender_manager.h"
[email protected]dbeebd52010-11-16 20:34:1661#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0962#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3363#include "chrome/browser/profiles/profile.h"
[email protected]1db6ff152009-10-12 15:32:0764#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1665#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5466#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3767#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0768#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5469#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3270#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1171#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1672#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1273#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1674#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1775#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1776#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5477#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1678#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4379#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1680#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4981#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5782#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]3c9e1872010-11-18 16:17:4983#include "chrome/browser/tab_contents/web_navigation_observer.h"
[email protected]152b8ba32010-03-29 19:40:1684#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3585#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]45300ad42010-12-02 15:51:1486#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]54ec6472010-04-09 19:39:5887#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2788#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2189#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4990#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5791#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4892#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1493#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0994#include "chrome/common/extensions/url_pattern.h"
95#include "chrome/common/navigation_types.h"
96#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5697#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2998#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3299#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:02100#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:18101#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:54102#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:37103#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:26104#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32105#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06106#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37107#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32108#include "net/base/mime_util.h"
109#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29110#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32111#include "net/base/registry_controlled_domain.h"
[email protected]b75b8292010-10-01 07:28:25112#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]1ee614862009-07-06 20:29:18113#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03114#include "webkit/glue/password_form.h"
[email protected]45446a52010-11-04 17:41:00115#include "webkit/glue/plugins/plugin_list.h"
[email protected]3e45ba92009-02-20 21:09:00116
[email protected]420ae012009-04-24 05:16:32117// Cross-Site Navigations
118//
119// If a TabContents is told to navigate to a different web site (as determined
120// by SiteInstance), it will replace its current RenderViewHost with a new
121// RenderViewHost dedicated to the new SiteInstance. This works as follows:
122//
123// - Navigate determines whether the destination is cross-site, and if so,
124// it creates a pending_render_view_host_ and moves into the PENDING
125// RendererState.
126// - The pending RVH is "suspended," so that no navigation messages are sent to
127// its renderer until the onbeforeunload JavaScript handler has a chance to
128// run in the current RVH.
129// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
130// that it has a pending cross-site request. ResourceDispatcherHost will
131// check for this when the response arrives.
132// - The current RVH runs its onbeforeunload handler. If it returns false, we
133// cancel all the pending logic and go back to NORMAL. Otherwise we allow
134// the pending RVH to send the navigation request to its renderer.
135// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
136// checks CrossSiteRequestManager to see that the RVH responsible has a
137// pending cross-site request, and then installs a CrossSiteEventHandler.
138// - When RDH receives a response, the BufferedEventHandler determines whether
139// it is a download. If so, it sends a message to the new renderer causing
140// it to cancel the request, and the download proceeds in the download
141// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34142// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32143// doesn't affect any functionality.
144// - After RDH receives a response and determines that it is safe and not a
145// download, it pauses the response to first run the old page's onunload
146// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34147// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32148// to the current RVH.
149// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
150// the ResourceDispatcherHost, who unpauses the response. Data is then sent
151// to the pending RVH.
152// - The pending renderer sends a FrameNavigate message that invokes the
153// DidNavigate method. This replaces the current RVH with the
154// pending RVH and goes back to the NORMAL RendererState.
155
156namespace {
157
158// Amount of time we wait between when a key event is received and the renderer
159// is queried for its state and pushed to the NavigationEntry.
160const int kQueryStateDelay = 5000;
161
[email protected]6ebdc9b2010-09-27 16:55:57162const int kSyncWaitDelay = 40;
163
[email protected]420ae012009-04-24 05:16:32164// If another javascript message box is displayed within
165// kJavascriptMessageExpectedDelay of a previous javascript message box being
166// dismissed, display an option to suppress future message boxes from this
167// contents.
168const int kJavascriptMessageExpectedDelay = 1000;
169
[email protected]420ae012009-04-24 05:16:32170// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51171const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32172 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17173 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32174 prefs::kWebKitJavaEnabled,
175 prefs::kWebKitJavascriptEnabled,
176 prefs::kWebKitLoadsImagesAutomatically,
177 prefs::kWebKitPluginsEnabled,
178 prefs::kWebKitUsesUniversalDetector,
179 prefs::kWebKitSerifFontFamily,
180 prefs::kWebKitSansSerifFontFamily,
181 prefs::kWebKitFixedFontFamily,
182 prefs::kWebKitDefaultFontSize,
183 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13184 prefs::kWebKitMinimumFontSize,
185 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36186 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32187 prefs::kDefaultCharset
188 // kWebKitStandardFontIsSerif needs to be added
189 // if we let users pick which font to use, serif or sans-serif when
190 // no font is specified or a CSS generic family (serif or sans-serif)
191 // is not specified.
192};
193
194const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
195
[email protected]420ae012009-04-24 05:16:32196// Returns true if the entry's transition type is FORM_SUBMIT.
197bool IsFormSubmit(const NavigationEntry* entry) {
198 return (PageTransition::StripQualifier(entry->transition_type()) ==
199 PageTransition::FORM_SUBMIT);
200}
201
202#if defined(OS_WIN)
203
204BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
205 // Note: erase is required to properly paint some widgets borders. This can
206 // be seen with textfields.
207 InvalidateRect(hwnd, NULL, TRUE);
208 return TRUE;
209}
210#endif
211
[email protected]5e369672009-11-03 23:48:30212ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16213 Profile* profile, const NavigationEntry& entry,
214 NavigationController::ReloadType reload_type) {
215 switch (reload_type) {
216 case NavigationController::RELOAD:
217 return ViewMsg_Navigate_Params::RELOAD;
218 case NavigationController::RELOAD_IGNORING_CACHE:
219 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
220 case NavigationController::NO_RELOAD:
221 break; // Fall through to rest of function.
222 }
[email protected]5e369672009-11-03 23:48:30223
224 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
225 profile->DidLastSessionExitCleanly())
226 return ViewMsg_Navigate_Params::RESTORE;
227
228 return ViewMsg_Navigate_Params::NORMAL;
229}
230
[email protected]876bc832010-09-07 16:29:54231void MakeNavigateParams(const NavigationEntry& entry,
232 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16233 NavigationController::ReloadType reload_type,
234 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34235 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54236 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00237 params->current_history_list_offset = controller.last_committed_entry_index();
238 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34239 params->url = entry.url();
240 params->referrer = entry.referrer();
241 params->transition = entry.transition_type();
242 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00243 params->navigation_type =
244 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34245 params->request_time = base::Time::Now();
246}
247
[email protected]851b1eb2010-08-09 13:32:29248class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
249 public:
250 DisabledPluginInfoBar(TabContents* tab_contents,
251 const string16& name,
252 const GURL& update_url)
253 : ConfirmInfoBarDelegate(tab_contents),
254 tab_contents_(tab_contents),
255 name_(name),
256 update_url_(update_url) {
257 tab_contents->AddInfoBar(this);
258 }
259
260 virtual int GetButtons() const {
261 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
262 }
263
[email protected]e23d3a32010-08-13 19:39:58264 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29265 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58266 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29267 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58268 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29269 return ConfirmInfoBarDelegate::GetButtonLabel(button);
270 }
271
[email protected]e23d3a32010-08-13 19:39:58272 virtual string16 GetMessageText() const {
273 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29274 }
275
[email protected]e23d3a32010-08-13 19:39:58276 virtual string16 GetLinkText() {
277 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29278 }
279
280 virtual SkBitmap* GetIcon() const {
281 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
282 IDR_INFOBAR_PLUGIN_INSTALL);
283 }
284
285 virtual bool Accept() {
286 tab_contents_->OpenURL(update_url_, GURL(),
[email protected]57b66d02010-09-30 11:24:51287 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29288 return false;
289 }
290
291 virtual bool Cancel() {
292 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
[email protected]57b66d02010-09-30 11:24:51293 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29294 return false;
295 }
296
297 virtual bool LinkClicked(WindowOpenDisposition disposition) {
298 // TODO(bauerb): Navigate to a help page explaining why we disabled
299 // the plugin, once we have one.
300 return false;
301 }
302
303 private:
304 TabContents* tab_contents_;
305 string16 name_;
306 GURL update_url_;
307};
308
[email protected]420ae012009-04-24 05:16:32309} // namespace
310
311// -----------------------------------------------------------------------------
312
[email protected]fdd61c62009-04-22 19:22:57313// static
314int TabContents::find_request_id_counter_ = -1;
315
[email protected]420ae012009-04-24 05:16:32316
[email protected]420ae012009-04-24 05:16:32317TabContents::TabContents(Profile* profile,
318 SiteInstance* site_instance,
319 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07320 const TabContents* base_tab_contents,
321 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42322 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07323 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
324 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13325 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22326 TabContentsView::Create(this))),
327 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57328 property_bag_(),
329 registrar_(),
[email protected]12802702010-07-09 19:43:09330 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
331 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57332 save_package_(),
[email protected]6db0def92010-03-02 19:55:45333 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21334 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57335 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06336 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22337 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34338 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29339 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34340 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34341 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57342 current_load_start_(),
343 load_state_(net::LOAD_STATE_IDLE),
344 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56345 upload_size_(0),
346 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57347 received_page_title_(false),
348 is_starred_(false),
349 contents_mime_type_(),
350 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40351 blocked_contents_(NULL),
352 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49353 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47354 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57355 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57356 find_ui_active_(false),
357 find_op_aborted_(false),
358 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12359 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12360 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08361 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57362 capturing_contents_(false),
363 is_being_destroyed_(false),
364 notify_disconnection_(false),
365 history_requests_(),
366#if defined(OS_WIN)
367 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
368#endif
369 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44370 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01371 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54372 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54373 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16374 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38375 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25376 minimum_zoom_percent_(
377 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
378 maximum_zoom_percent_(
379 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00380 temporary_zoom_settings_(false),
381 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54382 renderer_preferences_util::UpdateFromSystemSettings(
383 &renderer_preferences_, profile);
384
[email protected]9fb83e82010-07-02 18:24:55385 content_settings_delegate_.reset(
386 new TabSpecificContentSettings(this, profile));
387
[email protected]12636df2009-09-28 22:32:21388 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32389
[email protected]34ac70502009-09-25 17:07:23390 // We have the initial size of the view be based on the size of the passed in
391 // tab contents (normally a tab from the same window).
392 view_->CreateView(base_tab_contents ?
393 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32394
395 // Register for notifications about all interested prefs change.
396 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28397 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32398 if (prefs) {
399 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28400 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32401 }
402
403 // Register for notifications about URL starredness changing on any profile.
404 registrar_.Add(this, NotificationType::URLS_STARRED,
405 NotificationService::AllSources());
406 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
407 NotificationService::AllSources());
408 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
409 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09410#if defined(OS_LINUX)
411 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
412 NotificationService::AllSources());
413#endif
[email protected]420ae012009-04-24 05:16:32414
[email protected]6c32ce72010-03-08 05:18:06415 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
416 NotificationService::AllSources());
417
[email protected]79580c62010-02-02 02:36:25418 // Register for notifications about content setting changes.
419 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
420 NotificationService::AllSources());
421
[email protected]a888b29e62010-04-01 13:38:57422 // Listen for extension changes so we can update extension_for_current_page_.
423 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
424 NotificationService::AllSources());
425 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
426 NotificationService::AllSources());
427 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
428 NotificationService::AllSources());
429
[email protected]88152052010-10-01 04:05:18430 // Listen for Google URL changes
431 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
432 NotificationService::AllSources());
433
[email protected]c8865482009-07-23 20:40:10434 // Set-up the showing of the omnibox search infobar if applicable.
435 if (OmniboxSearchHint::IsEnabled(profile))
436 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35437}
initial.commit09911bf2008-07-26 23:55:29438
439TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32440 is_being_destroyed_ = true;
441
[email protected]bfe4c1582009-10-02 18:11:09442 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32443 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28444 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32445
[email protected]420ae012009-04-24 05:16:32446 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00447 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32448
[email protected]420ae012009-04-24 05:16:32449 // First cleanly close all child windows.
450 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
451 // some of these to close. CloseWindows is async, so it might get called
452 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49453 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32454
[email protected]c65e2f152010-10-14 15:30:40455 // Close all blocked contents.
456 if (blocked_contents_)
457 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13458
[email protected]420ae012009-04-24 05:16:32459 // Notify any observer that have a reference on this tab contents.
460 NotificationService::current()->Notify(
461 NotificationType::TAB_CONTENTS_DESTROYED,
462 Source<TabContents>(this),
463 NotificationService::NoDetails());
464
[email protected]1e5e74f2009-05-27 20:55:12465 // Notify any lasting InfobarDelegates that have not yet been removed that
466 // whatever infobar they were handling in this TabContents has closed,
467 // because the TabContents is going away entirely.
468 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
469 // notification may trigger infobars calls that access their delegate. (and
470 // some implementations of InfoBarDelegate do delete themselves on
471 // InfoBarClosed()).
472 for (int i = 0; i < infobar_delegate_count(); ++i) {
473 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
474 delegate->InfoBarClosed();
475 }
476 infobar_delegates_.clear();
477
[email protected]420ae012009-04-24 05:16:32478 // TODO(brettw) this should be moved to the view.
479#if defined(OS_WIN)
480 // If we still have a window handle, destroy it. GetNativeView can return
481 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42482 if (GetNativeView()) {
483 RenderViewHost* host = render_view_host();
484 if (host && host->view()) {
485 host->view()->WillWmDestroy();
486 }
[email protected]420ae012009-04-24 05:16:32487 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42488 }
[email protected]420ae012009-04-24 05:16:32489#endif
[email protected]7ab1e7d62009-10-14 23:32:01490
491 // OnCloseStarted isn't called in unit tests.
492 if (!tab_close_start_time_.is_null()) {
493 UMA_HISTOGRAM_TIMES("Tab.Close",
494 base::TimeTicks::Now() - tab_close_start_time_);
495 }
initial.commit09911bf2008-07-26 23:55:29496}
497
[email protected]d5f942ba2008-09-26 19:30:34498// static
499void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32500 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
501
502 WebPreferences pref_defaults;
503 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
504 pref_defaults.javascript_enabled);
505 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
506 pref_defaults.web_security_enabled);
507 prefs->RegisterBooleanPref(
508 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
509 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
510 pref_defaults.loads_images_automatically);
511 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
512 pref_defaults.plugins_enabled);
513 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
514 pref_defaults.dom_paste_enabled);
515 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
516 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14517 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32518 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
519 pref_defaults.text_areas_are_resizable);
520 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
521 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36522 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
523 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32524
525 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
526 IDS_ACCEPT_LANGUAGES);
527 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
528 IDS_DEFAULT_ENCODING);
529 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
530 IDS_STANDARD_FONT_IS_SERIF);
531 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
532 IDS_FIXED_FONT_FAMILY);
533 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
534 IDS_SERIF_FONT_FAMILY);
535 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
536 IDS_SANS_SERIF_FONT_FAMILY);
537 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
538 IDS_CURSIVE_FONT_FAMILY);
539 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
540 IDS_FANTASY_FONT_FAMILY);
541 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
542 IDS_DEFAULT_FONT_SIZE);
543 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
544 IDS_DEFAULT_FIXED_FONT_SIZE);
545 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
546 IDS_MINIMUM_FONT_SIZE);
547 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
548 IDS_MINIMUM_LOGICAL_FONT_SIZE);
549 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
550 IDS_USES_UNIVERSAL_DETECTOR);
551 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
552 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29553}
554
[email protected]13367f72009-07-08 16:39:02555// Returns true if contains content rendered by an extension.
556bool TabContents::HostsExtension() const {
557 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34558}
559
[email protected]cf28ec52010-04-09 22:56:34560AutoFillManager* TabContents::GetAutoFillManager() {
561 if (autofill_manager_.get() == NULL)
562 autofill_manager_.reset(new AutoFillManager(this));
563 return autofill_manager_.get();
564}
565
[email protected]6e95706d2009-04-23 22:55:01566PluginInstaller* TabContents::GetPluginInstaller() {
567 if (plugin_installer_.get() == NULL)
568 plugin_installer_.reset(new PluginInstaller(this));
569 return plugin_installer_.get();
570}
571
[email protected]1f18184a2010-07-21 19:34:49572TabContentsSSLHelper* TabContents::GetSSLHelper() {
573 if (ssl_helper_.get() == NULL)
574 ssl_helper_.reset(new TabContentsSSLHelper(this));
575 return ssl_helper_.get();
576}
577
[email protected]8cb5d5b2010-02-09 11:36:16578RenderProcessHost* TabContents::GetRenderProcessHost() const {
579 return render_manager_.current_host()->process();
580}
581
[email protected]9adb9692010-10-29 23:14:02582void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46583 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08584 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10585
[email protected]98aa0b52010-05-06 17:03:08586 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57587
[email protected]fca656c2010-02-10 20:30:10588 NotificationService::current()->Notify(
589 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
590 Source<TabContents>(this),
591 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49592}
593
[email protected]98aa0b52010-05-06 17:03:08594void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
595 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40596 return;
597
598 ExtensionsService* extension_service = profile()->GetExtensionsService();
[email protected]fa6a9102010-11-22 15:38:50599 if (!extension_service || !extension_service->is_ready())
600 return;
601
602 const Extension* extension =
603 extension_service->GetExtensionById(extension_app_id, false);
604 if (extension)
605 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40606}
607
[email protected]98aa0b52010-05-06 17:03:08608SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08609 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51610 return NULL;
611
[email protected]98aa0b52010-05-06 17:03:08612 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51613}
614
[email protected]d5f942ba2008-09-26 19:30:34615const GURL& TabContents::GetURL() const {
616 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57617 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54618 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34619}
620
[email protected]96d185d2009-04-24 03:28:54621const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55622 // Transient entries take precedence. They are used for interstitial pages
623 // that are shown on top of existing pages.
624 NavigationEntry* entry = controller_.GetTransientEntry();
625 if (entry)
626 return entry->GetTitleForDisplay(&controller_);
627
[email protected]96d185d2009-04-24 03:28:54628 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
629 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
630 if (our_dom_ui) {
631 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55632 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54633 if (!(entry && entry->IsViewSourceMode())) {
634 // Give the DOM UI the chance to override our title.
635 const string16& title = our_dom_ui->overridden_title();
636 if (!title.empty())
637 return title;
638 }
639 }
640
641 // We use the title for the last committed entry rather than a pending
642 // navigation entry. For example, when the user types in a URL, we want to
643 // keep the old page's title until the new load has committed and we get a new
644 // title.
[email protected]96d185d2009-04-24 03:28:54645 entry = controller_.GetLastCommittedEntry();
646 if (entry)
647 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54648 return EmptyString16();
649}
650
[email protected]bbbc1ef2010-02-12 18:03:41651// static
652string16 TabContents::GetDefaultTitle() {
653 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
654}
655
[email protected]d5f942ba2008-09-26 19:30:34656int32 TabContents::GetMaxPageID() {
657 if (GetSiteInstance())
658 return GetSiteInstance()->max_page_id();
659 else
660 return max_page_id_;
661}
662
663void TabContents::UpdateMaxPageID(int32 page_id) {
664 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34665 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34666 // testing.
667 if (GetSiteInstance())
668 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16669 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34670}
671
[email protected]96d185d2009-04-24 03:28:54672SiteInstance* TabContents::GetSiteInstance() const {
673 return render_manager_.current_host()->site_instance();
674}
675
[email protected]96d185d2009-04-24 03:28:54676bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15677 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54678 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15679 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01680 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54681 return true;
[email protected]8ab24cc2009-11-13 20:56:15682 }
[email protected]83e3895b2009-06-11 00:07:16683
[email protected]96d185d2009-04-24 03:28:54684 DOMUI* dom_ui = GetDOMUIForCurrentState();
685 if (dom_ui)
686 return !dom_ui->should_hide_url();
687 return true;
688}
689
[email protected]d5f942ba2008-09-26 19:30:34690SkBitmap TabContents::GetFavIcon() const {
691 // Like GetTitle(), we also want to use the favicon for the last committed
692 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57693 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47694 if (entry)
695 return entry->favicon().bitmap();
696
[email protected]ce3fa3c2009-04-20 19:55:57697 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34698 if (entry)
699 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34700 return SkBitmap();
701}
702
[email protected]0b303cc2009-09-28 22:35:15703bool TabContents::FavIconIsValid() const {
704 NavigationEntry* entry = controller_.GetTransientEntry();
705 if (entry)
706 return entry->favicon().is_valid();
707
708 entry = controller_.GetLastCommittedEntry();
709 if (entry)
710 return entry->favicon().is_valid();
711
712 return false;
713}
714
[email protected]96d185d2009-04-24 03:28:54715bool TabContents::ShouldDisplayFavIcon() {
716 // Always display a throbber during pending loads.
717 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
718 return true;
719
720 DOMUI* dom_ui = GetDOMUIForCurrentState();
721 if (dom_ui)
722 return !dom_ui->hide_favicon();
723 return true;
724}
725
[email protected]96d185d2009-04-24 03:28:54726std::wstring TabContents::GetStatusText() const {
727 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
728 return std::wstring();
729
730 switch (load_state_) {
731 case net::LOAD_STATE_WAITING_FOR_CACHE:
732 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04733 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
734 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54735 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
736 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
737 case net::LOAD_STATE_RESOLVING_HOST:
738 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
739 case net::LOAD_STATE_CONNECTING:
740 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06741 case net::LOAD_STATE_SSL_HANDSHAKE:
742 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54743 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56744 if (upload_size_)
745 return l10n_util::GetStringF(
746 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
747 static_cast<int>((100 * upload_position_) / upload_size_));
748 else
749 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54750 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
751 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
752 load_state_host_);
753 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
754 case net::LOAD_STATE_IDLE:
755 case net::LOAD_STATE_READING_RESPONSE:
756 break;
757 }
758
759 return std::wstring();
760}
761
[email protected]3c9e1872010-11-18 16:17:49762void TabContents::AddNavigationObserver(WebNavigationObserver* observer) {
763 web_navigation_observers_.AddObserver(observer);
764}
765
766void TabContents::RemoveNavigationObserver(WebNavigationObserver* observer) {
767 web_navigation_observers_.RemoveObserver(observer);
768}
769
[email protected]d5f942ba2008-09-26 19:30:34770void TabContents::SetIsCrashed(bool state) {
771 if (state == is_crashed_)
772 return;
773
774 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50775 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34776}
777
[email protected]744ef172009-10-16 21:53:46778void TabContents::PageActionStateChanged() {
779 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00780}
[email protected]ce5c4502009-05-06 16:46:11781
[email protected]d5f942ba2008-09-26 19:30:34782void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
783 if (delegate_)
784 delegate_->NavigationStateChanged(this, changed_flags);
785}
786
[email protected]96d185d2009-04-24 03:28:54787void TabContents::DidBecomeSelected() {
788 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16789 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
790 if (rwhv) {
791 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43792#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16793 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43794#endif
795 }
[email protected]96d185d2009-04-24 03:28:54796
[email protected]8cb5d5b2010-02-09 11:36:16797 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11798 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54799}
800
[email protected]1b072562010-12-13 19:37:45801void TabContents::FadeForInstant() {
802 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
803 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
804 if (rwhv)
805 rwhv->SetVisuallyDeemphasized(&whitish, true);
806}
807
808void TabContents::CancelInstantFade() {
809 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
810 if (rwhv)
811 rwhv->SetVisuallyDeemphasized(NULL, false);
812}
813
[email protected]96d185d2009-04-24 03:28:54814void TabContents::WasHidden() {
815 if (!capturing_contents()) {
816 // |render_view_host()| can be NULL if the user middle clicks a link to open
817 // a tab in then background, then closes the tab before selecting it. This
818 // is because closing the tab calls TabContents::Destroy(), which removes
819 // the |render_view_host()|; then when we actually destroy the window,
820 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16821 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
822 if (rwhv)
823 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54824 }
825
826 NotificationService::current()->Notify(
827 NotificationType::TAB_CONTENTS_HIDDEN,
828 Source<TabContents>(this),
829 NotificationService::NoDetails());
830}
831
[email protected]d5f942ba2008-09-26 19:30:34832void TabContents::Activate() {
833 if (delegate_)
834 delegate_->ActivateContents(this);
835}
836
[email protected]ea42e7782010-08-23 23:58:12837void TabContents::Deactivate() {
838 if (delegate_)
839 delegate_->DeactivateContents(this);
840}
841
[email protected]96d185d2009-04-24 03:28:54842void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16843 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
844 if (rwhv)
845 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54846}
847
848void TabContents::HideContents() {
849 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
850 // our superclass HideContents(), because some callers want to be very picky
851 // about the order in which these get called. In addition to making the code
852 // here practically impossible to understand, this also means we end up
853 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34854 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54855 WasHidden();
856}
857
[email protected]5aab5e22010-12-08 22:13:29858bool TabContents::NeedToFireBeforeUnload() {
859 // TODO(creis): Should we fire even for interstitial pages?
860 return notify_disconnection() &&
861 !showing_interstitial_page() &&
862 !render_view_host()->SuddenTerminationAllowed();
863}
864
[email protected]c0588052008-10-27 23:01:50865void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34866 WindowOpenDisposition disposition,
867 PageTransition::Type transition) {
868 if (delegate_)
[email protected]c0588052008-10-27 23:01:50869 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34870}
871
[email protected]1ccb3568d2010-02-19 10:51:16872bool TabContents::NavigateToPendingEntry(
873 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54874 return NavigateToEntry(*controller_.pending_entry(), reload_type);
875}
[email protected]96d185d2009-04-24 03:28:54876
[email protected]876bc832010-09-07 16:29:54877bool TabContents::NavigateToEntry(
878 const NavigationEntry& entry,
879 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54880 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
881 if (!dest_render_view_host)
882 return false; // Unable to create the desired render view host.
883
[email protected]770dd8b2010-05-24 18:11:39884 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
885 dest_render_view_host->EnablePreferredSizeChangedMode(
886 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
887 }
[email protected]9fb325e2010-05-06 18:23:24888
[email protected]05fdd492010-11-15 17:52:07889 // For security, we should never send non-DOM-UI URLs to a DOM UI renderer.
890 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58891 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40892 bool is_allowed_in_dom_ui_renderer =
[email protected]05fdd492010-11-15 17:52:07893 DOMUIFactory::IsURLAcceptableForDOMUI(profile(), entry.url());
[email protected]54ec6472010-04-09 19:39:58894 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40895 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58896
[email protected]96d185d2009-04-24 03:28:54897 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12898 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32899 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00900 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
901 dest_render_view_host,
902 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32903 }
[email protected]96d185d2009-04-24 03:28:54904
905 // Used for page load time metrics.
906 current_load_start_ = base::TimeTicks::Now();
907
908 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34909 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54910 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04911 if (delegate_) {
912 navigate_params.extra_headers =
913 delegate_->GetNavigationHeaders(navigate_params.url);
914 }
[email protected]056de2d2009-06-26 16:41:34915 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54916
917 if (entry.page_id() == -1) {
918 // HACK!! This code suppresses javascript: URLs from being added to
919 // session history, which is what we want to do for javascript: URLs that
920 // do not generate content. What we really need is a message from the
921 // renderer telling us that a new page was not created. The same message
922 // could be used for mailto: URLs and the like.
923 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
924 return false;
925 }
926
[email protected]3c9e1872010-11-18 16:17:49927 // Notify observers about navigation.
928 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
929 NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54930
[email protected]1ccb3568d2010-02-19 10:51:16931 if (reload_type != NavigationController::NO_RELOAD &&
932 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48933 FaviconService* favicon_service =
934 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
935 if (favicon_service)
936 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54937 }
938
[email protected]d5f942ba2008-09-26 19:30:34939 return true;
940}
941
[email protected]96d185d2009-04-24 03:28:54942void TabContents::Stop() {
943 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09944 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54945}
946
[email protected]96d185d2009-04-24 03:28:54947void TabContents::DisassociateFromPopupCount() {
948 render_view_host()->DisassociateFromPopupCount();
949}
950
951TabContents* TabContents::Clone() {
952 // We create a new SiteInstance so that the new tab won't share processes
953 // with the old one. This can be changed in the future if we need it to share
954 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32955 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54956 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07957 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54958 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08959 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08960 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54961 return tc;
962}
963
[email protected]4d677202009-07-19 07:37:12964void TabContents::ShowPageInfo(const GURL& url,
965 const NavigationEntry::SSLStatus& ssl,
966 bool show_history) {
967 if (!delegate_)
968 return;
969
[email protected]bb678332009-07-21 00:15:50970 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12971}
972
initial.commit09911bf2008-07-26 23:55:29973ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28974 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29975 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28976 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29977 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44978
979 if (child_windows_.size() == 1) {
980 window->ShowConstrainedWindow();
981 BlockTabContent(true);
982 }
983
initial.commit09911bf2008-07-26 23:55:29984 return window;
985}
986
[email protected]fa1cf0b82010-01-15 21:49:44987void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55988 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45989 // 70% opaque grey.
990 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55991 if (rwhv)
[email protected]1b072562010-12-13 19:37:45992 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44993 render_view_host()->set_ignore_input_events(blocked);
994 if (delegate_)
995 delegate_->SetTabContentBlocked(this, blocked);
996}
997
initial.commit09911bf2008-07-26 23:55:29998void TabContents::AddNewContents(TabContents* new_contents,
999 WindowOpenDisposition disposition,
1000 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:291001 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:401002 if (all_contents_blocked_) {
1003 if (!blocked_contents_)
1004 blocked_contents_ = new BlockedContentContainer(this);
1005 blocked_contents_->AddTabContents(
1006 new_contents, disposition, initial_pos, user_gesture);
1007 return;
1008 }
1009
initial.commit09911bf2008-07-26 23:55:291010 if (!delegate_)
1011 return;
1012
[email protected]35f7d212009-04-29 21:19:271013 if ((disposition == NEW_POPUP) && !user_gesture &&
1014 !CommandLine::ForCurrentProcess()->HasSwitch(
1015 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:221016 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:311017 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:291018 delegate_->GetConstrainingContents(this)->AddPopup(
1019 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:311020 } else {
[email protected]0aa55312008-10-17 21:53:081021 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:291022 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1023 user_gesture);
[email protected]7f37dd92009-09-15 16:35:491024 NotificationService::current()->Notify(
1025 NotificationType::TAB_ADDED,
1026 Source<TabContentsDelegate>(delegate_),
1027 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291028 }
initial.commit09911bf2008-07-26 23:55:291029
[email protected]8cc8d492010-02-02 10:40:491030 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401031 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291032}
1033
[email protected]bcd9dc42010-01-23 16:38:181034bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201035 bool is_js_code, const std::string& code_string,
1036 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511037 RenderViewHost* host = render_view_host();
1038 if (!host)
1039 return false;
1040
1041 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171042 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511043 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351044}
1045
[email protected]96d185d2009-04-24 03:28:541046void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491047 if (is_being_destroyed_)
1048 return;
[email protected]9fb83e82010-07-02 18:24:551049 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491050 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401051 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541052}
1053
[email protected]5c9e97a2009-09-09 23:48:301054gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541055 return view_->GetContentNativeView();
1056}
1057
1058gfx::NativeView TabContents::GetNativeView() const {
1059 return view_->GetNativeView();
1060}
1061
1062void TabContents::GetContainerBounds(gfx::Rect *out) const {
1063 view_->GetContainerBounds(out);
1064}
1065
1066void TabContents::Focus() {
1067 view_->Focus();
1068}
1069
[email protected]90daadb42009-06-08 21:27:281070void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541071 if (showing_interstitial_page()) {
1072 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1073 return;
1074 }
[email protected]96d185d2009-04-24 03:28:541075 render_view_host()->SetInitialFocus(reverse);
1076}
1077
1078bool TabContents::FocusLocationBarByDefault() {
1079 DOMUI* dom_ui = GetDOMUIForCurrentState();
1080 if (dom_ui)
1081 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431082 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251083 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431084 return true;
[email protected]96d185d2009-04-24 03:28:541085 return false;
1086}
1087
[email protected]a26dc362010-04-23 01:48:581088void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381089 if (delegate())
[email protected]a26dc362010-04-23 01:48:581090 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381091}
1092
[email protected]616ed5a2008-11-21 22:27:241093void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321094 if (delegate_ && !delegate_->infobars_enabled()) {
1095 delegate->InfoBarClosed();
1096 return;
1097 }
1098
[email protected]616ed5a2008-11-21 22:27:241099 // Look through the existing InfoBarDelegates we have for a match. If we've
1100 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051101 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451102 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1103 // Tell the new infobar to close so that it can clean itself up.
1104 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241105 return;
[email protected]6d27a7b2009-12-18 23:25:451106 }
[email protected]616ed5a2008-11-21 22:27:241107 }
1108
1109 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561110 NotificationService::current()->Notify(
1111 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1112 Source<TabContents>(this),
1113 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241114
1115 // Add ourselves as an observer for navigations the first time a delegate is
1116 // added. We use this notification to expire InfoBars that need to expire on
1117 // page transitions.
1118 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561119 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571120 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241121 }
1122}
1123
1124void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321125 if (delegate_ && !delegate_->infobars_enabled()) {
1126 return;
1127 }
1128
[email protected]616ed5a2008-11-21 22:27:241129 std::vector<InfoBarDelegate*>::iterator it =
1130 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1131 if (it != infobar_delegates_.end()) {
1132 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561133 NotificationService::current()->Notify(
1134 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1135 Source<TabContents>(this),
1136 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241137
[email protected]cdadf6f2010-08-20 16:36:081138 // Just to be safe, make sure the delegate was not removed by an observer.
1139 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1140 if (it != infobar_delegates_.end()) {
1141 infobar_delegates_.erase(it);
1142 // Remove ourselves as an observer if we are tracking no more InfoBars.
1143 if (infobar_delegates_.empty()) {
1144 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1145 Source<NavigationController>(&controller_));
1146 }
1147 } else {
1148 // If you hit this NOTREACHED, please comment in bug
1149 // http://crbug.com/50428 how you got there.
1150 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031151 }
[email protected]616ed5a2008-11-21 22:27:241152 }
1153}
[email protected]3edd9522009-03-04 22:19:411154
[email protected]f81821c2009-08-07 01:29:471155void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1156 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321157 if (delegate_ && !delegate_->infobars_enabled()) {
1158 new_delegate->InfoBarClosed();
1159 return;
1160 }
1161
[email protected]f81821c2009-08-07 01:29:471162 std::vector<InfoBarDelegate*>::iterator it =
1163 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1164 DCHECK(it != infobar_delegates_.end());
1165
1166 // Notify the container about the change of plans.
1167 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1168 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1169 old_delegate, new_delegate));
1170 NotificationService::current()->Notify(
1171 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1172 Source<TabContents>(this),
1173 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1174
[email protected]cdadf6f2010-08-20 16:36:081175 // Just to be safe, make sure the delegate was not removed by an observer.
1176 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1177 if (it != infobar_delegates_.end()) {
1178 // Remove the old one.
1179 infobar_delegates_.erase(it);
1180 } else {
1181 // If you hit this NOTREACHED, please comment in bug
1182 // http://crbug.com/50428 how you got there.
1183 NOTREACHED();
1184 }
[email protected]f81821c2009-08-07 01:29:471185
1186 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081187 DCHECK(find(infobar_delegates_.begin(),
1188 infobar_delegates_.end(), new_delegate) ==
1189 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471190 infobar_delegates_.push_back(new_delegate);
1191}
1192
[email protected]20ede072009-10-06 00:28:351193bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271194 if (showing_interstitial_page())
1195 return false;
1196
[email protected]c8f74942010-09-03 10:04:141197 // Do not show bookmarks bar if bookmarks aren't enabled.
1198 if (!browser_defaults::bookmarks_enabled)
1199 return false;
1200
[email protected]96d185d2009-04-24 03:28:541201 // See GetDOMUIForCurrentState() comment for more info. This case is very
1202 // similar, but for non-first loads, we want to use the committed entry. This
1203 // is so the bookmarks bar disappears at the same time the page does.
1204 if (controller_.GetLastCommittedEntry()) {
1205 // Not the first load, always use the committed DOM UI.
[email protected]d6219912010-11-17 19:47:371206 return (render_manager_.dom_ui() == NULL) ?
1207 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541208 }
1209
1210 // When it's the first load, we know either the pending one or the committed
1211 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1212 // of them will be valid, so we can just check both.
1213 if (render_manager_.pending_dom_ui())
1214 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
[email protected]d6219912010-11-17 19:47:371215 return (render_manager_.dom_ui() == NULL) ?
1216 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541217}
1218
[email protected]3edd9522009-03-04 22:19:411219void TabContents::ToolbarSizeChanged(bool is_animating) {
1220 TabContentsDelegate* d = delegate();
1221 if (d)
1222 d->ToolbarSizeChanged(this, is_animating);
1223}
[email protected]616ed5a2008-11-21 22:27:241224
[email protected]fc6fb7fb2009-11-07 02:35:041225bool TabContents::CanDownload(int request_id) {
1226 TabContentsDelegate* d = delegate();
1227 if (d)
1228 return d->CanDownload(request_id);
1229 return true;
1230}
1231
[email protected]d5f942ba2008-09-26 19:30:341232void TabContents::OnStartDownload(DownloadItem* download) {
1233 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341234
1235 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311236 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341237
[email protected]5b928b62010-08-03 11:46:511238 if (tab_contents && tab_contents->delegate())
1239 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411240}
[email protected]3edd9522009-03-04 22:19:411241
[email protected]d5f942ba2008-09-26 19:30:341242void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371243 ConstrainedWindowList::iterator i(
1244 std::find(child_windows_.begin(), child_windows_.end(), window));
1245 bool removed_topmost_window = i == child_windows_.begin();
1246 if (i != child_windows_.end())
1247 child_windows_.erase(i);
1248 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441249 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371250 } else {
1251 if (removed_topmost_window)
1252 child_windows_[0]->ShowConstrainedWindow();
1253 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441254 }
[email protected]66ba4932009-06-04 19:22:131255}
[email protected]d5f942ba2008-09-26 19:30:341256
[email protected]c65e2f152010-10-14 15:30:401257void TabContents::WillCloseBlockedContentContainer(
1258 BlockedContentContainer* container) {
1259 DCHECK(blocked_contents_ == container);
1260 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491261 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341262}
1263
[email protected]d5f942ba2008-09-26 19:30:341264void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351265#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061266 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351267#endif
[email protected]d5f942ba2008-09-26 19:30:341268}
1269
[email protected]c1dc9f132009-11-20 23:13:211270void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121271 bool forward_direction,
1272 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211273 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011274 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211275 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531276 string16 last_search_prepopulate_text =
1277 FindBarState::GetLastPrepopulateText(profile());
1278
[email protected]87fae512009-12-11 02:20:211279 // Try the last thing we searched for on this tab, then the last thing
1280 // searched for on any tab.
1281 if (!previous_find_text_.empty())
1282 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531283 else if (!last_search_prepopulate_text.empty())
1284 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211285 else
[email protected]e491f1c2009-05-22 20:28:121286 return;
[email protected]e491f1c2009-05-22 20:28:121287 }
[email protected]6e95706d2009-04-23 22:55:011288
[email protected]101c90e2009-10-26 21:14:441289 // Keep track of the previous search.
1290 previous_find_text_ = find_text_;
1291
[email protected]6e95706d2009-04-23 22:55:011292 // This is a FindNext operation if we are searching for the same text again,
1293 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1294 // exception to this is if the Find was aborted (then we don't want FindNext
1295 // because the highlighting has been cleared and we need it to reappear). We
1296 // therefore treat FindNext after an aborted Find operation as a full fledged
1297 // Find.
[email protected]c1dc9f132009-11-20 23:13:211298 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121299 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011300 !find_op_aborted_;
1301 if (!find_next)
1302 current_find_request_id_ = find_request_id_counter_++;
1303
[email protected]c1dc9f132009-11-20 23:13:211304 if (!search_string.empty())
1305 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121306 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011307
1308 find_op_aborted_ = false;
1309
1310 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531311 FindBarState* find_bar_state = profile()->GetFindBarState();
1312 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011313 render_view_host()->StartFinding(current_find_request_id_,
1314 find_text_,
1315 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121316 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011317 find_next);
1318}
1319
[email protected]5bc8fe92010-03-11 18:19:001320void TabContents::StopFinding(
1321 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011322 if (selection_action == FindBarController::kClearSelection) {
1323 // kClearSelection means the find string has been cleared by the user, but
1324 // the UI has not been dismissed. In that case we want to clear the
1325 // previously remembered search (http://crbug.com/42639).
1326 previous_find_text_ = string16();
1327 } else {
[email protected]2d2dffc2009-06-09 21:41:001328 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011329 if (!find_text_.empty())
1330 previous_find_text_ = find_text_;
1331 }
[email protected]101c90e2009-10-26 21:14:441332 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011333 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121334 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001335 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011336}
1337
[email protected]420ae012009-04-24 05:16:321338void TabContents::OnSavePage() {
1339 // If we can not save the page, try to download it.
1340 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1341 DownloadManager* dlm = profile()->GetDownloadManager();
1342 const GURL& current_page_url = GetURL();
1343 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221344 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321345 return;
1346 }
1347
1348 Stop();
1349
1350 // Create the save package and possibly prompt the user for the name to save
1351 // the page as. The user prompt is an asynchronous operation that runs on
1352 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221353 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321354 save_package_->GetSaveInfo();
1355}
1356
1357// Used in automated testing to bypass prompting the user for file names.
1358// Instead, the names and paths are hard coded rather than running them through
1359// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111360bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321361 SavePackage::SavePackageType save_type) {
1362 // Stop the page from navigating.
1363 Stop();
1364
[email protected]828cabe2009-09-26 22:47:111365 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591366 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321367}
1368
[email protected]89d6e6e2009-12-03 23:06:511369void TabContents::EmailPageLocation() {
1370 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1371 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1372 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1373 title + "&body=%0A%0A" + page_url;
1374 platform_util::OpenExternal(GURL(mailto));
1375}
1376
[email protected]420ae012009-04-24 05:16:321377void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161378 if (CommandLine::ForCurrentProcess()->HasSwitch(
1379 switches::kEnablePrintPreview)) {
1380 if (showing_interstitial_page())
1381 return;
1382 render_view_host()->PrintPreview();
1383 } else {
1384 PrintNow();
1385 }
[email protected]420ae012009-04-24 05:16:321386}
1387
1388bool TabContents::PrintNow() {
1389 // We can't print interstitial page for now.
1390 if (showing_interstitial_page())
1391 return false;
1392
1393 return render_view_host()->PrintPages();
1394}
1395
[email protected]82270452009-06-19 15:58:011396void TabContents::PrintingDone(int document_cookie, bool success) {
1397 render_view_host()->PrintingDone(document_cookie, success);
1398}
1399
[email protected]420ae012009-04-24 05:16:321400bool TabContents::IsActiveEntry(int32 page_id) {
1401 NavigationEntry* active_entry = controller_.GetActiveEntry();
1402 return (active_entry != NULL &&
1403 active_entry->site_instance() == GetSiteInstance() &&
1404 active_entry->page_id() == page_id);
1405}
1406
[email protected]b2fe07d12010-02-09 14:38:081407void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161408 set_encoding(encoding);
1409 render_view_host()->SetPageEncoding(encoding);
1410}
1411
[email protected]b2fe07d12010-02-09 14:38:081412void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161413 reset_encoding();
1414 render_view_host()->ResetPageEncodingToDefault();
1415}
1416
1417void TabContents::WindowMoveOrResizeStarted() {
1418 render_view_host()->WindowMoveOrResizeStarted();
1419}
1420
[email protected]c65e2f152010-10-14 15:30:401421void TabContents::SetAllContentsBlocked(bool value) {
1422 if (all_contents_blocked_ == value)
1423 return;
1424
1425 all_contents_blocked_ = value;
1426 if (!all_contents_blocked_ && blocked_contents_) {
1427 std::vector<TabContents*> blocked;
1428 blocked_contents_->GetBlockedContents(&blocked);
1429 for (size_t i = 0; i < blocked.size(); ++i)
1430 blocked_contents_->LaunchForContents(blocked[i]);
1431 }
1432}
1433
[email protected]3f8eb7f2009-10-02 23:58:051434void TabContents::LogNewTabTime(const std::string& event_name) {
1435 // Not all new tab pages get timed. In those cases, we don't have a
1436 // new_tab_start_time_.
1437 if (new_tab_start_time_.is_null())
1438 return;
1439
1440 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441441 MetricEventDurationDetails details(event_name,
1442 static_cast<int>(duration.InMilliseconds()));
1443
[email protected]7ab1e7d62009-10-14 23:32:011444 if (event_name == "Tab.NewTabScriptStart") {
1445 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1446 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1447 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1448 } else if (event_name == "Tab.NewTabOnload") {
1449 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051450 // The new tab page has finished loading; reset it.
1451 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441452 } else {
1453 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051454 }
[email protected]84abba62009-10-07 17:01:441455 NotificationService::current()->Notify(
1456 NotificationType::METRIC_EVENT_DURATION,
1457 Source<TabContents>(this),
1458 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051459}
1460
[email protected]7ab1e7d62009-10-14 23:32:011461void TabContents::OnCloseStarted() {
1462 if (tab_close_start_time_.is_null())
1463 tab_close_start_time_ = base::TimeTicks::Now();
1464}
1465
[email protected]46624bf2010-06-09 16:04:191466bool TabContents::ShouldAcceptDragAndDrop() const {
1467#if defined(OS_CHROMEOS)
1468 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1469 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201470 if (delegate() && delegate()->IsPopup(this))
1471 return false;
1472 return true;
[email protected]46624bf2010-06-09 16:04:191473#else
1474 return true;
1475#endif
1476}
1477
[email protected]ec0b6c42010-08-26 03:16:581478void TabContents::UpdateHistoryForNavigation(
1479 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1480 if (profile()->IsOffTheRecord())
1481 return;
1482
1483 // Add to history service.
1484 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1485 if (hs)
1486 hs->AddPage(*add_page_args);
1487}
1488
1489void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1490 if (profile()->IsOffTheRecord())
1491 return;
1492
1493 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1494 if (hs)
1495 hs->SetPageTitle(entry.virtual_url(), entry.title());
1496}
1497
[email protected]d0b8d092010-10-25 04:05:171498double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251499 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1500 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171501 return 0;
[email protected]b75b8292010-10-01 07:28:251502
1503 double zoom_level;
1504 if (temporary_zoom_settings_) {
1505 zoom_level = zoom_map->GetTemporaryZoomLevel(
1506 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1507 } else {
1508 zoom_level = zoom_map->GetZoomLevel(GetURL());
1509 }
[email protected]d0b8d092010-10-25 04:05:171510 return zoom_level;
1511}
[email protected]b75b8292010-10-01 07:28:251512
[email protected]d0b8d092010-10-25 04:05:171513int TabContents::GetZoomPercent(bool* enable_increment,
1514 bool* enable_decrement) {
1515 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251516 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171517 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251518 *enable_decrement = percent > minimum_zoom_percent_;
1519 *enable_increment = percent < maximum_zoom_percent_;
1520 return percent;
1521}
1522
[email protected]96d185d2009-04-24 03:28:541523// Notifies the RenderWidgetHost instance about the fact that the page is
1524// loading, or done loading and calls the base implementation.
1525void TabContents::SetIsLoading(bool is_loading,
1526 LoadNotificationDetails* details) {
1527 if (is_loading == is_loading_)
1528 return;
1529
1530 if (!is_loading) {
1531 load_state_ = net::LOAD_STATE_IDLE;
1532 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561533 upload_size_ = 0;
1534 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541535 }
1536
1537 render_manager_.SetIsLoading(is_loading);
1538
1539 is_loading_ = is_loading;
1540 waiting_for_response_ = is_loading;
1541
[email protected]6ebdc9b2010-09-27 16:55:571542 if (delegate_)
1543 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351544 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541545
1546 NotificationType type = is_loading ? NotificationType::LOAD_START :
1547 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111548 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541549 if (details)
1550 det = Details<LoadNotificationDetails>(details);
1551 NotificationService::current()->Notify(type,
1552 Source<NavigationController>(&controller_),
1553 det);
1554}
1555
[email protected]b6c874582009-05-08 19:38:311556void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291557 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061558 // A page can't spawn popups (or do anything else, either) until its load
1559 // commits, so when we reach here, the popup was spawned by the
1560 // NavigationController's last committed entry, not the active entry. For
1561 // example, if a page opens a popup in an onunload() handler, then the active
1562 // entry is the page to be loaded as we navigate away from the unloading
1563 // page. For this reason, we can't use GetURL() to get the opener URL,
1564 // because it returns the active entry.
1565 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1566 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1567
1568 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491569 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091570 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491571 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1572 } else {
[email protected]c65e2f152010-10-14 15:30:401573 if (!blocked_contents_)
1574 blocked_contents_ = new BlockedContentContainer(this);
1575 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1576 true);
[email protected]55126132010-08-19 14:53:281577 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1578 std::string());
[email protected]8cc8d492010-02-02 10:40:491579 }
[email protected]b9681312008-11-07 00:08:261580}
[email protected]616ed5a2008-11-21 22:27:241581
[email protected]616ed5a2008-11-21 22:27:241582void TabContents::ExpireInfoBars(
1583 const NavigationController::LoadCommittedDetails& details) {
1584 // Only hide InfoBars when the user has done something that makes the main
1585 // frame load. We don't want various automatic or subframe navigations making
1586 // it disappear.
1587 if (!details.is_user_initiated_main_frame_load())
1588 return;
1589
[email protected]f86a07022008-11-25 01:06:051590 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241591 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081592 if (!delegate) {
1593 // If you hit this NOTREACHED, please comment in bug
1594 // http://crbug.com/50428 how you got there.
1595 NOTREACHED();
1596 continue;
1597 }
1598
[email protected]f86a07022008-11-25 01:06:051599 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241600 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241601 }
1602}
[email protected]fdd61c62009-04-22 19:22:571603
[email protected]96d185d2009-04-24 03:28:541604DOMUI* TabContents::GetDOMUIForCurrentState() {
1605 // When there is a pending navigation entry, we want to use the pending DOMUI
1606 // that goes along with it to control the basic flags. For example, we want to
1607 // show the pending URL in the URL bar, so we want the display_url flag to
1608 // be from the pending entry.
1609 //
1610 // The confusion comes because there are multiple possibilities for the
1611 // initial load in a tab as a side effect of the way the RenderViewHostManager
1612 // works.
1613 //
1614 // - For the very first tab the load looks "normal". The new tab DOM UI is
1615 // the pending one, and we want it to apply here.
1616 //
1617 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1618 // get switched to the one previously associated with the new tab pages.
1619 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1620 // have a committed DOM UI in this case.
1621 //
1622 // This condition handles all of these cases:
1623 //
1624 // - First load in first tab: no committed nav entry + pending nav entry +
1625 // pending dom ui:
1626 // -> Use pending DOM UI if any.
1627 //
1628 // - First load in second tab: no committed nav entry + pending nav entry +
1629 // no pending DOM UI:
1630 // -> Use the committed DOM UI if any.
1631 //
1632 // - Second navigation in any tab: committed nav entry + pending nav entry:
1633 // -> Use pending DOM UI if any.
1634 //
1635 // - Normal state with no load: committed nav entry + no pending nav entry:
1636 // -> Use committed DOM UI.
1637 if (controller_.pending_entry() &&
1638 (controller_.GetLastCommittedEntry() ||
1639 render_manager_.pending_dom_ui()))
1640 return render_manager_.pending_dom_ui();
1641 return render_manager_.dom_ui();
1642}
[email protected]420ae012009-04-24 05:16:321643
1644void TabContents::DidNavigateMainFramePostCommit(
1645 const NavigationController::LoadCommittedDetails& details,
1646 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441647 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1648 // If this is a window.open navigation, use the same DOMUI as the renderer
1649 // that opened the window, as long as both renderers have the same
1650 // privileges.
[email protected]583d45c12010-08-31 02:48:121651 if (opener_dom_ui_type_ ==
1652 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441653 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1654 // dom_ui might be NULL if the URL refers to a non-existent extension.
1655 if (dom_ui) {
1656 render_manager_.SetDOMUIPostCommit(dom_ui);
1657 dom_ui->RenderViewCreated(render_view_host());
1658 }
1659 }
1660 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1661 }
1662
[email protected]420ae012009-04-24 05:16:321663 if (details.is_user_initiated_main_frame_load()) {
1664 // Clear the status bubble. This is a workaround for a bug where WebKit
1665 // doesn't let us know that the cursor left an element during a
1666 // transition (this is also why the mouse cursor remains as a hand after
1667 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1668 // clear the bubble when a user navigates to a named anchor in the same
1669 // page.
1670 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321671 }
1672
1673 // The keyword generator uses the navigation entries, so must be called after
1674 // the commit.
1675 GenerateKeywordIfNecessary(params);
1676
1677 // Allow the new page to set the title again.
1678 received_page_title_ = false;
1679
1680 // Get the favicon, either from history or request it from the net.
1681 fav_icon_helper_.FetchFavIcon(details.entry->url());
1682
[email protected]0de80162010-02-03 04:52:351683 // Clear all page actions, blocked content notifications and browser actions
1684 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141685 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081686 ExtensionsService* service = profile()->GetExtensionsService();
1687 if (service) {
1688 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571689 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081690 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521691 if (browser_action) {
1692 browser_action->ClearAllValuesForTab(controller().session_id().id());
1693 NotificationService::current()->Notify(
1694 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571695 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521696 NotificationService::NoDetails());
1697 }
[email protected]92c6f9b92009-10-24 04:35:081698
[email protected]5d246db22009-10-27 06:17:571699 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521700 service->extensions()->at(i)->page_action();
1701 if (page_action) {
1702 page_action->ClearAllValuesForTab(controller().session_id().id());
1703 PageActionStateChanged();
1704 }
[email protected]92c6f9b92009-10-24 04:35:081705 }
[email protected]aece2c7f2009-08-27 20:43:171706 }
[email protected]0de80162010-02-03 04:52:351707
1708 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401709 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341710 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401711 blocked_contents_->Destroy();
1712 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351713 }
1714
1715 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411716 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551717 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471718
1719 // Once the main frame is navigated, we're no longer considered to have
1720 // displayed insecure content.
1721 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171722 }
[email protected]ce5c4502009-05-06 16:46:111723
[email protected]8cc8d492010-02-02 10:40:491724 // Close constrained windows if necessary.
1725 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1726 details.previous_url, details.entry->url()))
1727 CloseConstrainedWindows();
1728
[email protected]420ae012009-04-24 05:16:321729 // Update the starred state.
1730 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531731
[email protected]3c9e1872010-11-18 16:17:491732 // Notify observers about navigation.
1733 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1734 DidNavigateMainFramePostCommit(details, params));
1735
[email protected]c07c9752010-03-12 05:57:531736 // Clear the cache of forms in AutoFill.
1737 if (autofill_manager_.get())
1738 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321739}
1740
1741void TabContents::DidNavigateAnyFramePostCommit(
1742 RenderViewHost* render_view_host,
1743 const NavigationController::LoadCommittedDetails& details,
1744 const ViewHostMsg_FrameNavigate_Params& params) {
1745 // If we navigate, start showing messages again. This does nothing to prevent
1746 // a malicious script from spamming messages, since the script could just
1747 // reload the page to stop blocking.
1748 suppress_javascript_messages_ = false;
1749
[email protected]3c9e1872010-11-18 16:17:491750 // Notify observers about navigation.
1751 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1752 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551753
1754 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581755 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321756}
1757
[email protected]8cc8d492010-02-02 10:40:491758void TabContents::CloseConstrainedWindows() {
1759 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321760 // We use indices instead of iterators in case CloseWindow does something
1761 // that may invalidate an iterator.
1762 int size = static_cast<int>(child_windows_.size());
1763 for (int i = size - 1; i >= 0; --i) {
1764 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441765 if (window) {
[email protected]420ae012009-04-24 05:16:321766 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441767 BlockTabContent(false);
1768 }
[email protected]420ae012009-04-24 05:16:321769 }
1770}
1771
1772void TabContents::UpdateStarredStateForCurrentURL() {
1773 BookmarkModel* model = profile()->GetBookmarkModel();
1774 const bool old_state = is_starred_;
1775 is_starred_ = (model && model->IsBookmarked(GetURL()));
1776
1777 if (is_starred_ != old_state && delegate())
1778 delegate()->URLStarredChanged(this, is_starred_);
1779}
1780
1781void TabContents::UpdateAlternateErrorPageURL() {
1782 GURL url = GetAlternateErrorPageURL();
1783 render_view_host()->SetAlternateErrorPageURL(url);
1784}
1785
1786void TabContents::UpdateWebPreferences() {
1787 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1788}
1789
[email protected]d0b8d092010-10-25 04:05:171790void TabContents::UpdateZoomLevel() {
1791 render_view_host()->SetZoomLevel(GetZoomLevel());
1792}
1793
[email protected]420ae012009-04-24 05:16:321794void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1795 RenderViewHost* rvh) {
1796 // If we are creating a RVH for a restored controller, then we might
1797 // have more page IDs than the SiteInstance's current max page ID. We must
1798 // make sure that the max page ID is larger than any restored page ID.
1799 // Note that it is ok for conflicting page IDs to exist in another tab
1800 // (i.e., NavigationController), but if any page ID is larger than the max,
1801 // the back/forward list will get confused.
1802 int max_restored_page_id = controller_.max_restored_page_id();
1803 if (max_restored_page_id > 0) {
1804 int curr_max_page_id = site_instance->max_page_id();
1805 if (max_restored_page_id > curr_max_page_id) {
1806 // Need to update the site instance immediately.
1807 site_instance->UpdateMaxPageID(max_restored_page_id);
1808
1809 // Also tell the renderer to update its internal representation. We
1810 // need to reserve enough IDs to make all restored page IDs less than
1811 // the max.
1812 if (curr_max_page_id < 0)
1813 curr_max_page_id = 0;
1814 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1815 }
1816 }
1817}
1818
[email protected]ec0b6c42010-08-26 03:16:581819scoped_refptr<history::HistoryAddPageArgs>
1820TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541821 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471822 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321823 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581824 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1825 new history::HistoryAddPageArgs(
1826 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1827 params.redirects, params.transition, history::SOURCE_BROWSED,
1828 details.did_replace_entry));
1829 if (PageTransition::IsMainFrame(params.transition) &&
1830 virtual_url != params.url) {
1831 // Hack on the "virtual" URL so that it will appear in history. For some
1832 // types of URLs, we will display a magic URL that is different from where
1833 // the page is actually navigated. We want the user to see in history what
1834 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1835 // only applies to the main frame, as the virtual URL doesn't apply to
1836 // sub-frames.
1837 add_page_args->url = virtual_url;
1838 if (!add_page_args->redirects.empty())
1839 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321840 }
[email protected]ec0b6c42010-08-26 03:16:581841 return add_page_args;
[email protected]420ae012009-04-24 05:16:321842}
1843
1844bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1845 const std::wstring& title) {
1846 // For file URLs without a title, use the pathname instead. In the case of a
1847 // synthesized title, we don't want the update to count toward the "one set
1848 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251849 string16 final_title;
[email protected]420ae012009-04-24 05:16:321850 bool explicit_set;
1851 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251852 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321853 explicit_set = false; // Don't count synthetic titles toward the set limit.
1854 } else {
[email protected]e53668962010-06-23 15:35:251855 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321856 explicit_set = true;
1857 }
1858
[email protected]e53668962010-06-23 15:35:251859 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321860 return false; // Nothing changed, don't bother.
1861
[email protected]e53668962010-06-23 15:35:251862 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321863
[email protected]ec0b6c42010-08-26 03:16:581864 if (!received_page_title_) {
1865 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321866 received_page_title_ = explicit_set;
1867 }
1868
1869 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251870 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321871
[email protected]cbc0e1b2010-04-12 18:33:041872 NotificationService::current()->Notify(
1873 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1874 Source<TabContents>(this),
1875 NotificationService::NoDetails());
1876
[email protected]420ae012009-04-24 05:16:321877 return true;
1878}
1879
1880void TabContents::NotifySwapped() {
1881 // After sending out a swap notification, we need to send a disconnect
1882 // notification so that clients that pick up a pointer to |this| can NULL the
1883 // pointer. See Bug 1230284.
1884 notify_disconnection_ = true;
1885 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341886 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221887 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321888 NotificationService::NoDetails());
1889}
1890
1891void TabContents::NotifyConnected() {
1892 notify_disconnection_ = true;
1893 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341894 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221895 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321896 NotificationService::NoDetails());
1897}
1898
1899void TabContents::NotifyDisconnected() {
1900 if (!notify_disconnection_)
1901 return;
1902
1903 notify_disconnection_ = false;
1904 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341905 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221906 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321907 NotificationService::NoDetails());
1908}
1909
1910void TabContents::GenerateKeywordIfNecessary(
1911 const ViewHostMsg_FrameNavigate_Params& params) {
1912 if (!params.searchable_form_url.is_valid())
1913 return;
1914
1915 if (profile()->IsOffTheRecord())
1916 return;
1917
1918 int last_index = controller_.last_committed_entry_index();
1919 // When there was no previous page, the last index will be 0. This is
1920 // normally due to a form submit that opened in a new tab.
1921 // TODO(brettw) bug 916126: we should support keywords when form submits
1922 // happen in new tabs.
1923 if (last_index <= 0)
1924 return;
1925 const NavigationEntry* previous_entry =
1926 controller_.GetEntryAtIndex(last_index - 1);
1927 if (IsFormSubmit(previous_entry)) {
1928 // Only generate a keyword if the previous page wasn't itself a form
1929 // submit.
1930 return;
1931 }
1932
1933 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1934 previous_entry->user_typed_url() : previous_entry->url();
1935 std::wstring keyword =
1936 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1937 if (keyword.empty())
1938 return;
1939
1940 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1941 if (!url_model)
1942 return;
1943
1944 if (!url_model->loaded()) {
1945 url_model->Load();
1946 return;
1947 }
1948
1949 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191950 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321951 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1952 return;
1953
1954 if (current_url) {
1955 if (current_url->originating_url().is_valid()) {
1956 // The existing keyword was generated from an OpenSearch description
1957 // document, don't regenerate.
1958 return;
1959 }
1960 url_model->Remove(current_url);
1961 }
1962 TemplateURL* new_url = new TemplateURL();
1963 new_url->set_keyword(keyword);
1964 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191965 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321966 new_url->add_input_encoding(params.searchable_form_encoding);
1967 DCHECK(controller_.GetLastCommittedEntry());
1968 const GURL& favicon_url =
1969 controller_.GetLastCommittedEntry()->favicon().url();
1970 if (favicon_url.is_valid()) {
1971 new_url->SetFavIconURL(favicon_url);
1972 } else {
1973 // The favicon url isn't valid. This means there really isn't a favicon,
1974 // or the favicon url wasn't obtained before the load started. This assumes
1975 // the later.
1976 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1977 // its url.
1978 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1979 }
1980 new_url->set_safe_for_autoreplace(true);
1981 url_model->Add(new_url);
1982}
1983
[email protected]bf5c2ff392009-07-08 16:24:331984void TabContents::OnUserGesture() {
1985 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011986 DownloadRequestLimiter* limiter =
1987 g_browser_process->download_request_limiter();
1988 if (limiter)
1989 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261990 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331991}
1992
1993void TabContents::OnFindReply(int request_id,
1994 int number_of_matches,
1995 const gfx::Rect& selection_rect,
1996 int active_match_ordinal,
1997 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421998 // Ignore responses for requests that have been aborted.
1999 if (find_op_aborted_)
2000 return;
2001
[email protected]bf5c2ff392009-07-08 16:24:332002 // Ignore responses for requests other than the one we have most recently
2003 // issued. That way we won't act on stale results when the user has
2004 // already typed in another query.
2005 if (request_id != current_find_request_id_)
2006 return;
2007
2008 if (number_of_matches == -1)
2009 number_of_matches = last_search_result_.number_of_matches();
2010 if (active_match_ordinal == -1)
2011 active_match_ordinal = last_search_result_.active_match_ordinal();
2012
2013 gfx::Rect selection = selection_rect;
2014 if (selection.IsEmpty())
2015 selection = last_search_result_.selection_rect();
2016
2017 // Notify the UI, automation and any other observers that a find result was
2018 // found.
2019 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
2020 selection, active_match_ordinal,
2021 final_update);
2022 NotificationService::current()->Notify(
2023 NotificationType::FIND_RESULT_AVAILABLE,
2024 Source<TabContents>(this),
2025 Details<FindNotificationDetails>(&last_search_result_));
2026}
2027
2028void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542029 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2030 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2031 if (!entry)
2032 return;
2033 // Note that we don't call NavigationController::GotToOffset() as we don't
2034 // want to create a pending navigation entry (it might end up lingering
2035 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522036 entry->set_transition_type(entry->transition_type() |
2037 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542038 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2039 }
[email protected]bf5c2ff392009-07-08 16:24:332040}
2041
[email protected]bf5c2ff392009-07-08 16:24:332042void TabContents::OnMissingPluginStatus(int status) {
2043#if defined(OS_WIN)
2044// TODO(PORT): pull in when plug-ins work
2045 GetPluginInstaller()->OnMissingPluginStatus(status);
2046#endif
2047}
2048
2049void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332050 DCHECK(!plugin_path.value().empty());
2051
2052 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]45446a52010-11-04 17:41:002053 WebPluginInfo plugin_info;
2054 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
2055 plugin_path, &plugin_info) &&
2056 !plugin_info.name.empty()) {
2057 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372058#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002059 // Many plugins on the Mac have .plugin in the actual name, which looks
2060 // terrible, so look for that and strip it off if present.
2061 const std::wstring plugin_extension(L".plugin");
2062 if (EndsWith(plugin_name, plugin_extension, true))
2063 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372064#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332065 }
[email protected]2ae8a922010-06-28 20:27:532066 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2067 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332068 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582069 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2070 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532071 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332072}
2073
2074void TabContents::OnCrashedWorker() {
2075 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582076 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422077 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332078}
2079
[email protected]38789d82010-11-17 06:03:442080void TabContents::OnDidGetApplicationInfo(int32 page_id,
2081 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512082 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332083
[email protected]ed5431872009-11-17 08:39:512084 if (delegate())
2085 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332086}
2087
[email protected]bb461532010-11-26 21:50:232088void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
2089 if (delegate())
2090 delegate()->OnInstallApplication(this, info);
2091}
2092
[email protected]851b1eb2010-08-09 13:32:292093void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2094 const GURL& update_url) {
2095 new DisabledPluginInfoBar(this, name, update_url);
2096}
2097
[email protected]a2cf65eb2010-01-18 08:20:382098void TabContents::OnPageContents(const GURL& url,
2099 int renderer_process_id,
2100 int32 page_id,
[email protected]e5106202010-06-11 21:12:362101 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102102 const std::string& language,
2103 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382104 // Don't index any https pages. People generally don't want their bank
2105 // accounts, etc. indexed on their computer, especially since some of these
2106 // things are not marked cachable.
2107 // TODO(brettw) we may want to consider more elaborate heuristics such as
2108 // the cachability of the page. We may also want to consider subframes (this
2109 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272110 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2111 // content indexing for chromeos in some future releases.
2112#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382113 if (!url.SchemeIsSecure()) {
2114 Profile* p = profile();
2115 if (p && !p->IsOffTheRecord()) {
2116 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2117 if (hs)
2118 hs->SetPageContents(url, contents);
2119 }
2120 }
[email protected]ccd40a52010-05-11 16:15:272121#endif
[email protected]a8a81292010-01-21 00:32:452122
[email protected]1c57b7b2010-07-12 17:38:102123 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452124
2125 std::string lang = language;
2126 NotificationService::current()->Notify(
2127 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152128 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452129 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382130}
2131
[email protected]7e0831b2010-02-01 08:45:152132void TabContents::OnPageTranslated(int32 page_id,
2133 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162134 const std::string& translated_lang,
2135 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552136 language_state_.set_current_language(translated_lang);
2137 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162138 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152139 NotificationService::current()->Notify(
2140 NotificationType::PAGE_TRANSLATED,
2141 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162142 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152143}
2144
[email protected]ce833282010-11-04 15:48:392145void TabContents::OnSetSuggestions(
2146 int32 page_id,
2147 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262148 if (delegate())
[email protected]ce833282010-11-04 15:48:392149 delegate()->OnSetSuggestions(page_id, suggestions);
2150}
2151
2152void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2153 if (delegate())
2154 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262155}
2156
[email protected]bf5c2ff392009-07-08 16:24:332157void TabContents::DidStartProvisionalLoadForFrame(
2158 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182159 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332160 bool is_main_frame,
[email protected]ea51f1f2010-12-01 10:07:272161 bool is_error_page,
[email protected]bf5c2ff392009-07-08 16:24:332162 const GURL& url) {
2163 ProvisionalLoadDetails details(is_main_frame,
2164 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412165 url, std::string(), false,
2166 is_error_page, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332167 NotificationService::current()->Notify(
2168 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2169 Source<NavigationController>(&controller_),
2170 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142171 if (is_main_frame) {
[email protected]ea51f1f2010-12-01 10:07:272172 // If we're displaying a network error page do not reset the content
2173 // settings delegate's cookies so the user has a chance to modify cookie
2174 // settings.
2175 if (!is_error_page)
2176 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142177 content_settings_delegate_->ClearGeolocationContentSettings();
2178 }
[email protected]bf5c2ff392009-07-08 16:24:332179}
2180
2181void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202182 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332183 NotificationService::current()->Notify(
2184 NotificationType::RESOURCE_RESPONSE_STARTED,
2185 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202186 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332187}
2188
[email protected]3dbb80b2010-02-09 22:41:202189void TabContents::DidRedirectResource(
2190 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332191 NotificationService::current()->Notify(
2192 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2193 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202194 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332195}
2196
2197void TabContents::DidLoadResourceFromMemoryCache(
2198 const GURL& url,
2199 const std::string& frame_origin,
2200 const std::string& main_frame_origin,
2201 const std::string& security_info) {
2202 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442203 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332204 SSLManager::DeserializeSecurityInfo(security_info,
2205 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042206 &security_bits,
2207 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332208 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162209 GetRenderProcessHost()->id(), cert_id,
2210 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332211
2212 NotificationService::current()->Notify(
2213 NotificationType::LOAD_FROM_MEMORY_CACHE,
2214 Source<NavigationController>(&controller_),
2215 Details<LoadFromMemoryCacheDetails>(&details));
2216}
2217
[email protected]e3d60e5d2009-09-25 21:08:292218void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472219 displayed_insecure_content_ = true;
2220 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292221}
2222
2223void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592224 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292225}
2226
[email protected]bf5c2ff392009-07-08 16:24:332227void TabContents::DidFailProvisionalLoadWithError(
2228 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182229 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332230 bool is_main_frame,
2231 int error_code,
2232 const GURL& url,
2233 bool showing_repost_interstitial) {
2234 if (net::ERR_ABORTED == error_code) {
2235 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2236 // This means that the interstitial won't be torn down properly, which is
2237 // bad. But if we have an interstitial, go back to another tab type, and
2238 // then load the same interstitial again, we could end up getting the first
2239 // interstitial's "failed" message (as a result of the cancel) when we're on
2240 // the second one.
2241 //
2242 // We can't tell this apart, so we think we're tearing down the current page
2243 // which will cause a crash later one. There is also some code in
2244 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2245 // out because of this problem.
2246 //
2247 // http://code.google.com/p/chromium/issues/detail?id=2855
2248 // Because this will not tear down the interstitial properly, if "back" is
2249 // back to another tab type, the interstitial will still be somewhat alive
2250 // in the previous tab type. If you navigate somewhere that activates the
2251 // tab with the interstitial again, you'll see a flash before the new load
2252 // commits of the interstitial page.
2253 if (showing_interstitial_page()) {
2254 LOG(WARNING) << "Discarding message during interstitial.";
2255 return;
2256 }
2257
2258 // This will discard our pending entry if we cancelled the load (e.g., if we
2259 // decided to download the file instead of load it). Only discard the
2260 // pending entry if the URLs match, otherwise the user initiated a navigate
2261 // before the page loaded so that the discard would discard the wrong entry.
2262 NavigationEntry* pending_entry = controller_.pending_entry();
2263 if (pending_entry && pending_entry->url() == url) {
2264 controller_.DiscardNonCommittedEntries();
2265 // Update the URL display.
2266 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2267 }
2268
2269 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2270 }
2271
2272 // Send out a notification that we failed a provisional load with an error.
2273 ProvisionalLoadDetails details(is_main_frame,
2274 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412275 url, std::string(), false, false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332276 details.set_error_code(error_code);
2277
2278 NotificationService::current()->Notify(
2279 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2280 Source<NavigationController>(&controller_),
2281 Details<ProvisionalLoadDetails>(&details));
2282}
2283
[email protected]4b8e2b02010-11-30 09:15:182284void TabContents::DocumentLoadedInFrame(int64 frame_id) {
[email protected]bf5c2ff392009-07-08 16:24:332285 controller_.DocumentLoadedInFrame();
[email protected]622474d2010-11-04 09:21:082286 NotificationService::current()->Notify(
2287 NotificationType::FRAME_DOM_CONTENT_LOADED,
2288 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182289 Details<int64>(&frame_id));
[email protected]bf5c2ff392009-07-08 16:24:332290}
2291
[email protected]4b8e2b02010-11-30 09:15:182292void TabContents::DidFinishLoad(int64 frame_id) {
[email protected]fdd94a02010-11-05 08:07:172293 NotificationService::current()->Notify(
2294 NotificationType::FRAME_DID_FINISH_LOAD,
2295 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182296 Details<int64>(&frame_id));
[email protected]fdd94a02010-11-05 08:07:172297}
2298
[email protected]dcd5b332010-08-11 08:55:182299void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562300 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242301 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562302}
2303
[email protected]8d3347f2009-07-09 22:00:212304RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322305 return view_.get();
2306}
2307
[email protected]8d3347f2009-07-09 22:00:212308RenderViewHostDelegate::RendererManagement*
2309TabContents::GetRendererManagementDelegate() {
2310 return &render_manager_;
2311}
2312
[email protected]bf5c2ff392009-07-08 16:24:332313RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212314 TabContents::GetBrowserIntegrationDelegate() {
2315 return this;
[email protected]bf5c2ff392009-07-08 16:24:332316}
2317
[email protected]8d3347f2009-07-09 22:00:212318RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2319 return this;
[email protected]bf5c2ff392009-07-08 16:24:332320}
2321
[email protected]46ba9082010-06-22 10:00:582322RenderViewHostDelegate::ContentSettings*
2323TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552324 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582325}
2326
[email protected]8d3347f2009-07-09 22:00:212327RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322328 return save_package_.get(); // May be NULL, but we can return NULL.
2329}
2330
[email protected]8d3347f2009-07-09 22:00:212331RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092332 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212333}
2334
2335RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2336 return &fav_icon_helper_;
2337}
2338
[email protected]e8dbd674b2010-03-11 18:34:402339RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452340 if (autocomplete_history_manager_.get() == NULL)
2341 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2342 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332343}
2344
[email protected]21674df2009-10-28 19:51:212345RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342346 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212347}
2348
[email protected]1f18184a2010-07-21 19:34:492349RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2350 return GetSSLHelper();
2351}
2352
[email protected]b5977a0c2010-08-24 19:46:262353RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2354 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492355 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262356 return file_select_helper_.get();
2357}
2358
[email protected]fd571bb2010-03-19 01:23:542359AutomationResourceRoutingDelegate*
2360TabContents::GetAutomationResourceRoutingDelegate() {
2361 return delegate();
2362}
2363
[email protected]ced90ae12010-02-20 02:06:162364RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2365 return bookmark_drag_;
2366}
2367
2368void TabContents::SetBookmarkDragDelegate(
2369 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2370 bookmark_drag_ = bookmark_drag;
2371}
2372
[email protected]9fb83e82010-07-02 18:24:552373TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2374 return content_settings_delegate_.get();
2375}
2376
[email protected]93623c5d2009-12-10 21:40:322377RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462378 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512379}
2380
[email protected]57c6a652009-05-04 07:58:342381TabContents* TabContents::GetAsTabContents() {
2382 return this;
2383}
2384
[email protected]7b291f92009-08-14 05:43:532385ViewType::Type TabContents::GetRenderViewType() const {
2386 return ViewType::TAB_CONTENTS;
2387}
2388
2389int TabContents::GetBrowserWindowID() const {
2390 return controller().window_id().id();
2391}
2392
[email protected]420ae012009-04-24 05:16:322393void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062394 NotificationService::current()->Notify(
2395 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2396 Source<TabContents>(this),
2397 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322398 NavigationEntry* entry = controller_.GetActiveEntry();
2399 if (!entry)
2400 return;
2401
2402 // When we're creating views, we're still doing initial setup, so we always
2403 // use the pending DOM UI rather than any possibly existing committed one.
2404 if (render_manager_.pending_dom_ui()) {
2405 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2406 }
2407
2408 if (entry->IsViewSourceMode()) {
2409 // Put the renderer in view source mode.
2410 render_view_host->Send(
2411 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2412 }
[email protected]0666aef2009-05-13 19:48:082413
2414 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322415}
2416
2417void TabContents::RenderViewReady(RenderViewHost* rvh) {
2418 if (rvh != render_view_host()) {
2419 // Don't notify the world, since this came from a renderer in the
2420 // background.
2421 return;
2422 }
2423
2424 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302425 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322426 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302427
2428 // Restore the focus to the tab (otherwise the focus will be on the top
2429 // window).
[email protected]484ae5912010-09-29 19:16:142430 if (was_crashed && !FocusLocationBarByDefault() &&
2431 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302432 Focus();
[email protected]484ae5912010-09-29 19:16:142433 }
[email protected]420ae012009-04-24 05:16:322434}
2435
2436void TabContents::RenderViewGone(RenderViewHost* rvh) {
2437 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092438 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322439 return;
2440 if (rvh != render_view_host()) {
2441 // The pending page's RenderViewHost is gone.
2442 return;
2443 }
2444
2445 SetIsLoading(false, NULL);
2446 NotifyDisconnected();
2447 SetIsCrashed(true);
2448
[email protected]ff9efc62010-02-18 22:10:542449 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212450 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542451 RemoveInfoBar(GetInfoBarDelegateAt(i));
2452
[email protected]8e537302009-06-10 21:19:582453 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552454 // Only do this if we're not in browser shutdown, so that TabContents
2455 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2456 // visible do not flash a sad tab page.
2457 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2458 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322459
2460 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002461 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322462}
2463
[email protected]2e4633c2009-07-09 16:58:062464void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2465 NotificationService::current()->Notify(
2466 NotificationType::RENDER_VIEW_HOST_DELETED,
2467 Source<TabContents>(this),
2468 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482469 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062470}
2471
[email protected]420ae012009-04-24 05:16:322472void TabContents::DidNavigate(RenderViewHost* rvh,
2473 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372474 int extra_invalidate_flags = 0;
2475
2476 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]33f74972010-12-08 16:40:362477 PrerenderManager* pm = profile()->GetPrerenderManager();
2478 if (pm != NULL) {
2479 if (pm->MaybeUsePreloadedPage(this, params.url)) {
2480 // TODO(tburkard): If the preloaded page has not finished preloading
2481 // yet, we should not do this.
2482 DidStopLoading();
2483 return;
2484 }
2485 }
2486
[email protected]20ede072009-10-06 00:28:352487 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372488
[email protected]420ae012009-04-24 05:16:322489 render_manager_.DidNavigateMainFrame(rvh);
2490
[email protected]20ede072009-10-06 00:28:352491 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372492 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372493 }
2494
[email protected]420ae012009-04-24 05:16:322495 // Update the site of the SiteInstance if it doesn't have one yet.
2496 if (!GetSiteInstance()->has_site())
2497 GetSiteInstance()->SetSite(params.url);
2498
2499 // Need to update MIME type here because it's referred to in
2500 // UpdateNavigationCommands() called by RendererDidNavigate() to
2501 // determine whether or not to enable the encoding menu.
2502 // It's updated only for the main frame. For a subframe,
2503 // RenderView::UpdateURL does not set params.contents_mime_type.
2504 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2505 // TODO(jungshik): Add a test for the encoding menu to avoid
2506 // regressing it again.
2507 if (PageTransition::IsMainFrame(params.transition))
2508 contents_mime_type_ = params.contents_mime_type;
2509
2510 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372511 bool did_navigate = controller_.RendererDidNavigate(
2512 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392513
[email protected]a9c0bfe2010-09-17 08:35:222514 // Send notification about committed provisional loads. This notification is
2515 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2516 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2517 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072518 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2519 // that is not recorded in the navigation history. For the purpose of
2520 // tracking navigation events, we treat this event as a sub frame navigation
2521 // event.
2522 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2523 ProvisionalLoadDetails load_details(
2524 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412525 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222526 load_details.set_transition_type(params.transition);
2527 // Whether or not a page transition was triggered by going backward or
2528 // forward in the history is only stored in the navigation controller's
2529 // entry list.
2530 if (did_navigate &&
2531 (controller_.GetActiveEntry()->transition_type() &
2532 PageTransition::FORWARD_BACK)) {
2533 load_details.set_transition_type(
2534 params.transition | PageTransition::FORWARD_BACK);
2535 }
2536 NotificationService::current()->Notify(
2537 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2538 Source<NavigationController>(&controller_),
2539 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222540 }
2541
[email protected]3e90d4a2009-07-03 17:38:392542 // Update history. Note that this needs to happen after the entry is complete,
2543 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582544 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392545 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582546 // URLs, we use a data: URL as the real value. We actually want to save the
2547 // about: URL to the history db and keep the data: URL hidden. This is what
2548 // the TabContents' URL getter does.
2549 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2550 CreateHistoryAddPageArgs(GetURL(), details, params));
2551 if (!delegate() ||
2552 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2553 details.type)) {
2554 UpdateHistoryForNavigation(add_page_args);
2555 }
[email protected]3e90d4a2009-07-03 17:38:392556 }
2557
[email protected]76543b92009-08-31 17:27:452558 if (!did_navigate)
2559 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322560
2561 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2562 // for the appropriate notification (best) or you can add it to
2563 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2564 // necessary, please).
2565
2566 // Run post-commit tasks.
2567 if (details.is_main_frame)
2568 DidNavigateMainFramePostCommit(details, params);
2569 DidNavigateAnyFramePostCommit(rvh, details, params);
2570}
2571
2572void TabContents::UpdateState(RenderViewHost* rvh,
2573 int32 page_id,
2574 const std::string& state) {
2575 DCHECK(rvh == render_view_host());
2576
2577 // We must be prepared to handle state updates for any page, these occur
2578 // when the user is scrolling and entering form data, as well as when we're
2579 // leaving a page, in which case our state may have already been moved to
2580 // the next page. The navigation controller will look up the appropriate
2581 // NavigationEntry and update it when it is notified via the delegate.
2582
2583 int entry_index = controller_.GetEntryIndexWithPageID(
2584 GetSiteInstance(), page_id);
2585 if (entry_index < 0)
2586 return;
2587 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2588
2589 if (state == entry->content_state())
2590 return; // Nothing to update.
2591 entry->set_content_state(state);
2592 controller_.NotifyEntryChanged(entry, entry_index);
2593}
2594
2595void TabContents::UpdateTitle(RenderViewHost* rvh,
2596 int32 page_id, const std::wstring& title) {
2597 // If we have a title, that's a pretty good indication that we've started
2598 // getting useful data.
2599 SetNotWaitingForResponse();
2600
2601 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482602 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582603 page_id);
[email protected]420ae012009-04-24 05:16:322604 if (!entry || !UpdateTitleForEntry(entry, title))
2605 return;
2606
2607 // Broadcast notifications when the UI should be updated.
2608 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032609 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322610}
2611
[email protected]420ae012009-04-24 05:16:322612void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402613 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322614 set_encoding(encoding);
2615}
2616
2617void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2618 if (delegate())
2619 delegate()->UpdateTargetURL(this, url);
2620}
2621
2622void TabContents::UpdateThumbnail(const GURL& url,
2623 const SkBitmap& bitmap,
2624 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442625 if (profile()->IsOffTheRecord())
2626 return;
2627
[email protected]420ae012009-04-24 05:16:322628 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492629 if (history::TopSites::IsEnabled()) {
[email protected]e6baed562010-11-02 22:33:442630 history::TopSites* ts = profile()->GetTopSites();
2631 if (ts)
2632 ts->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282633 } else {
[email protected]e6baed562010-11-02 22:33:442634 HistoryService* hs =
2635 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2636 if (hs)
[email protected]449478302009-06-09 20:04:282637 hs->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322638 }
2639}
2640
[email protected]c4e98902010-06-01 10:20:142641void TabContents::UpdateInspectorSetting(const std::string& key,
2642 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052643 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082644}
2645
[email protected]45aafc92010-06-07 14:18:532646void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052647 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532648}
2649
[email protected]420ae012009-04-24 05:16:322650void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292651 // The UI may be in an event-tracking loop, such as between the
2652 // mouse-down and mouse-up in text selection or a button click.
2653 // Defer the close until after tracking is complete, so that we
2654 // don't free objects out from under the UI.
2655 // TODO(shess): This could probably be integrated with the
2656 // IsDoingDrag() test below. Punting for now because I need more
2657 // research to understand how this impacts platforms other than Mac.
2658 // TODO(shess): This could get more fine-grained. For instance,
2659 // closing a tab in another window while selecting text in the
2660 // current window's Omnibox should be just fine.
2661 if (view()->IsEventTracking()) {
2662 view()->CloseTabAfterEventTracking();
2663 return;
2664 }
2665
[email protected]24a4d1062009-07-10 23:10:422666 // If we close the tab while we're in the middle of a drag, we'll crash.
2667 // Instead, cancel the drag and close it as soon as the drag ends.
2668 if (view()->IsDoingDrag()) {
2669 view()->CancelDragAndCloseTab();
2670 return;
2671 }
2672
[email protected]420ae012009-04-24 05:16:322673 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2674 if (delegate() && rvh == render_view_host())
2675 delegate()->CloseContents(this);
2676}
2677
2678void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2679 if (delegate() && delegate()->IsPopup(this))
2680 delegate()->MoveContents(this, new_bounds);
2681}
2682
[email protected]7ab1e7d62009-10-14 23:32:012683void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322684 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492685
[email protected]de4761b2010-12-07 21:05:212686 if (delegate()) {
2687 bool is_print_preview_tab =
2688 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2689 if (content_restrictions_ || is_print_preview_tab) {
2690 content_restrictions_= is_print_preview_tab ?
2691 CONTENT_RESTRICTION_PRINT : 0;
2692 delegate()->ContentRestrictionsChanged(this);
2693 }
[email protected]9e823662010-10-13 23:36:002694 }
[email protected]3c9e1872010-11-18 16:17:492695
2696 // Notify observers about navigation.
2697 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2698 DidStartLoading());
[email protected]420ae012009-04-24 05:16:322699}
2700
[email protected]7ab1e7d62009-10-14 23:32:012701void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322702 scoped_ptr<LoadNotificationDetails> details;
2703
2704 NavigationEntry* entry = controller_.GetActiveEntry();
2705 // An entry may not exist for a stop when loading an initial blank page or
2706 // if an iframe injected by script into a blank page finishes loading.
2707 if (entry) {
[email protected]420ae012009-04-24 05:16:322708 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2709
2710 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542711 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322712 entry->transition_type(),
2713 elapsed,
2714 &controller_,
2715 controller_.GetCurrentEntryIndex()));
2716 }
2717
[email protected]420ae012009-04-24 05:16:322718 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492719
2720 // Notify observers about navigation.
2721 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2722 DidStopLoading());
[email protected]420ae012009-04-24 05:16:322723}
2724
[email protected]25497492010-09-11 15:15:082725void TabContents::DocumentOnLoadCompletedInMainFrame(
2726 RenderViewHost* render_view_host,
2727 int32 page_id) {
2728 NotificationService::current()->Notify(
2729 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2730 Source<TabContents>(this),
2731 Details<int>(&page_id));
2732}
2733
[email protected]420ae012009-04-24 05:16:322734void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2735 const GURL& source_url,
2736 const GURL& target_url) {
2737 NavigationEntry* entry;
2738 if (page_id == -1)
2739 entry = controller_.pending_entry();
2740 else
2741 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2742 if (!entry || entry->url() != source_url)
2743 return;
2744 entry->set_url(target_url);
2745}
2746
[email protected]420ae012009-04-24 05:16:322747void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2748 WindowOpenDisposition disposition) {
2749 if (render_manager_.dom_ui()) {
2750 // When we're a DOM UI, it will provide a page transition type for us (this
2751 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2752 // generated suggestions).
2753 //
2754 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162755 // want web sites to see a referrer of "chrome://blah" (and some
2756 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322757 // send to the site), so we send no referrer.
2758 OpenURL(url, GURL(), disposition,
2759 render_manager_.dom_ui()->link_transition_type());
2760 } else {
2761 OpenURL(url, referrer, disposition, PageTransition::LINK);
2762 }
2763}
2764
[email protected]1ee614862009-07-06 20:29:182765void TabContents::DomOperationResponse(const std::string& json_string,
2766 int automation_id) {
2767}
2768
[email protected]8b8e7c92010-08-19 18:05:562769void TabContents::ProcessDOMUIMessage(
2770 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322771 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442772 // This can happen if someone uses window.open() to open an extension URL
2773 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562774 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322775 return;
2776 }
[email protected]8b8e7c92010-08-19 18:05:562777 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322778}
2779
2780void TabContents::ProcessExternalHostMessage(const std::string& message,
2781 const std::string& origin,
2782 const std::string& target) {
2783 if (delegate())
2784 delegate()->ForwardMessageToExternalHost(message, origin, target);
2785}
2786
[email protected]420ae012009-04-24 05:16:322787void TabContents::RunJavaScriptMessage(
2788 const std::wstring& message,
2789 const std::wstring& default_prompt,
2790 const GURL& frame_url,
2791 const int flags,
2792 IPC::Message* reply_msg,
2793 bool* did_suppress_message) {
2794 // Suppress javascript messages when requested and when inside a constrained
2795 // popup window (because that activates them and breaks them out of the
2796 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552797 // Also suppress messages when showing an interstitial. The interstitial is
2798 // shown over the previous page, we don't want the hidden page dialogs to
2799 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502800 bool suppress_this_message =
2801 suppress_javascript_messages_ ||
2802 showing_interstitial_page() ||
2803 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322804 if (delegate())
2805 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312806 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322807
2808 *did_suppress_message = suppress_this_message;
2809
2810 if (!suppress_this_message) {
2811 base::TimeDelta time_since_last_message(
2812 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2813 bool show_suppress_checkbox = false;
2814 // Show a checkbox offering to suppress further messages if this message is
2815 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2816 if (time_since_last_message <
2817 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2818 show_suppress_checkbox = true;
2819
[email protected]d6ad7442010-09-05 19:06:522820 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2821 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322822 } else {
2823 // If we are suppressing messages, just reply as is if the user immediately
2824 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542825 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322826 }
2827}
2828
2829void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2830 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292831 if (delegate())
2832 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502833 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2834 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2835 std::wstring());
2836 return;
2837 }
[email protected]7ab1e7d62009-10-14 23:32:012838 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222839 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322840}
2841
2842void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2843 const std::string& json_arguments,
2844 IPC::Message* reply_msg) {
2845 if (delegate()) {
2846 HtmlDialogUIDelegate* dialog_delegate =
2847 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222848 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322849 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2850 }
2851}
2852
[email protected]c4aa86962010-11-24 23:08:042853void TabContents::PasswordFormsFound(
2854 const std::vector<webkit_glue::PasswordForm>& forms) {
2855 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2856 PasswordFormsFound(forms));
2857}
2858
2859void TabContents::PasswordFormsVisible(
2860 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2861 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2862 PasswordFormsVisible(visible_forms));
2863}
2864
[email protected]420ae012009-04-24 05:16:322865// Checks to see if we should generate a keyword based on the OSDD, and if
2866// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202867void TabContents::PageHasOSDD(
2868 RenderViewHost* render_view_host,
2869 int32 page_id,
2870 const GURL& url,
2871 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122872 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322873 DCHECK(url.is_valid());
2874 if (!IsActiveEntry(page_id))
2875 return;
[email protected]420ae012009-04-24 05:16:322876 if (!profile()->GetTemplateURLFetcher())
2877 return;
[email protected]420ae012009-04-24 05:16:322878 if (profile()->IsOffTheRecord())
2879 return;
2880
[email protected]2de7e002010-10-11 22:58:202881 TemplateURLFetcher::ProviderType provider_type;
2882 switch (msg_provider_type.type) {
2883 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2884 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2885 break;
2886
2887 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2888 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2889 break;
2890
2891 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2892 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2893 break;
2894
2895 default:
2896 NOTREACHED();
2897 return;
2898 }
2899
[email protected]420ae012009-04-24 05:16:322900 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2901 DCHECK(entry);
2902
2903 const NavigationEntry* base_entry = entry;
2904 if (IsFormSubmit(base_entry)) {
2905 // If the current page is a form submit, find the last page that was not
2906 // a form submit and use its url to generate the keyword from.
2907 int index = controller_.last_committed_entry_index() - 1;
2908 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2909 index--;
2910 if (index >= 0)
2911 base_entry = controller_.GetEntryAtIndex(index);
2912 else
2913 base_entry = NULL;
2914 }
2915
2916 // We want to use the user typed URL if available since that represents what
2917 // the user typed to get here, and fall back on the regular URL if not.
2918 if (!base_entry)
2919 return;
2920 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2921 base_entry->user_typed_url() : base_entry->url();
2922 if (!keyword_url.is_valid())
2923 return;
[email protected]2de7e002010-10-11 22:58:202924
[email protected]0b5b85c2010-10-11 23:00:122925 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2926 keyword_url,
2927 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532928
[email protected]0b5b85c2010-10-11 23:00:122929 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322930 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322931 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2932 keyword,
2933 url,
2934 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122935 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202936 provider_type);
[email protected]420ae012009-04-24 05:16:322937}
2938
[email protected]420ae012009-04-24 05:16:322939GURL TabContents::GetAlternateErrorPageURL() const {
2940 GURL url;
2941 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2942 if (profile()->IsOffTheRecord())
2943 return url;
2944
2945 PrefService* prefs = profile()->GetPrefs();
2946 DCHECK(prefs);
2947 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152948 url = google_util::AppendGoogleLocaleParam(
2949 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322950 url = google_util::AppendGoogleTLDParam(url);
2951 }
2952 return url;
2953}
2954
2955WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062956 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552957 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082958 WebPreferences web_prefs =
2959 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
2960
[email protected]9beff752010-09-22 19:35:432961 // Force accelerated compositing and 2d canvas off for chrome: and
2962 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432963 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2964 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082965 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432966 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082967 }
2968
[email protected]39553442010-09-09 00:01:552969#if defined(OS_MACOSX)
2970 // Disable accelerated compositing if IOSurface's are not supported,
2971 // as is the case in 10.5.
2972 if (!IOSurfaceSupport::Initialize())
2973 web_prefs.accelerated_compositing_enabled = false;
2974#endif
2975
[email protected]447021c2010-09-08 21:29:082976 return web_prefs;
[email protected]420ae012009-04-24 05:16:322977}
2978
[email protected]fa1cf0b82010-01-15 21:49:442979void TabContents::OnIgnoredUIEvent() {
2980 if (constrained_window_count()) {
2981 ConstrainedWindow* window = *constrained_window_begin();
2982 window->FocusConstrainedWindow();
2983 }
2984}
2985
[email protected]420ae012009-04-24 05:16:322986void TabContents::OnJSOutOfMemory() {
2987 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582988 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2989 NULL, true));
[email protected]420ae012009-04-24 05:16:322990}
2991
[email protected]420ae012009-04-24 05:16:322992void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2993 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342994 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322995 // delivered to a pending RenderViewHost. We must first run the onunload
2996 // handler of the old RenderViewHost before we can allow it to proceed.
2997 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2998 new_request_id);
2999}
3000
[email protected]420ae012009-04-24 05:16:323001void TabContents::RendererUnresponsive(RenderViewHost* rvh,
3002 bool is_during_unload) {
3003 if (is_during_unload) {
3004 // Hang occurred while firing the beforeunload/unload handler.
3005 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:113006 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323007
3008 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3009 return;
3010
3011 // If the tab hangs in the beforeunload/unload handler there's really
3012 // nothing we can do to recover. Pretend the unload listeners have
3013 // all fired and close the tab. If the hang is in the beforeunload handler
3014 // then the user will not have the option of cancelling the close.
3015 Close(rvh);
3016 return;
3017 }
3018
3019 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:003020 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:323021}
3022
3023void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:003024 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:323025}
3026
3027void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:563028 net::LoadState load_state,
3029 uint64 upload_position,
3030 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323031 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563032 upload_position_ = upload_position;
3033 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:293034 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:193035 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:293036 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:533037 load_state_host_ =
3038 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:323039 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
3040 SetNotWaitingForResponse();
3041 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:503042 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:323043}
3044
[email protected]1ee614862009-07-06 20:29:183045bool TabContents::IsExternalTabContainer() const {
3046 if (!delegate())
3047 return false;
3048
3049 return delegate()->IsExternalTabContainer();
3050}
3051
[email protected]1ee614862009-07-06 20:29:183052void TabContents::DidInsertCSS() {
3053 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:323054}
3055
[email protected]546ae4e02010-12-08 14:57:193056void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:353057 NotificationService::current()->Notify(
3058 NotificationType::FOCUS_CHANGED_IN_PAGE,
3059 Source<RenderViewHost>(render_view_host()),
[email protected]546ae4e02010-12-08 14:57:193060 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:353061}
3062
[email protected]b75b8292010-10-01 07:28:253063void TabContents::UpdateZoomLimits(int minimum_percent,
3064 int maximum_percent,
3065 bool remember) {
3066 minimum_zoom_percent_ = minimum_percent;
3067 maximum_zoom_percent_ = maximum_percent;
3068 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383069}
3070
[email protected]9e823662010-10-13 23:36:003071void TabContents::UpdateContentRestrictions(int restrictions) {
3072 content_restrictions_ = restrictions;
3073 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:323074}
3075
[email protected]420ae012009-04-24 05:16:323076void TabContents::BeforeUnloadFiredFromRenderManager(
3077 bool proceed,
3078 bool* proceed_to_fire_unload) {
3079 if (delegate())
3080 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3081}
3082
[email protected]3a3d47472010-07-15 21:03:543083void TabContents::DidStartLoadingFromRenderManager(
3084 RenderViewHost* render_view_host) {
3085 DidStartLoading();
3086}
3087
3088void TabContents::RenderViewGoneFromRenderManager(
3089 RenderViewHost* render_view_host) {
3090 RenderViewGone(render_view_host);
3091}
3092
[email protected]420ae012009-04-24 05:16:323093void TabContents::UpdateRenderViewSizeForRenderManager() {
3094 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263095 gfx::Size size = view_->GetContainerSize();
3096 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3097 // here during container initialization and normal window size will be set
3098 // later. In case of tab duplication this resizing to 0x0 prevents setting
3099 // normal size later so just ignore it.
3100 if (!size.IsEmpty())
3101 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323102}
3103
[email protected]3a3d47472010-07-15 21:03:543104void TabContents::NotifySwappedFromRenderManager() {
3105 NotifySwapped();
3106}
3107
3108NavigationController& TabContents::GetControllerForRenderManager() {
3109 return controller();
3110}
3111
[email protected]420ae012009-04-24 05:16:323112DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223113 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323114}
3115
3116NavigationEntry*
3117TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3118 return controller_.GetLastCommittedEntry();
3119}
3120
3121bool TabContents::CreateRenderViewForRenderManager(
3122 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323123 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523124
[email protected]674b3822010-08-04 04:02:513125 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323126 return false;
3127
3128 // Now that the RenderView has been created, we need to tell it its size.
3129 rwh_view->SetSize(view_->GetContainerSize());
3130
3131 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3132 render_view_host);
3133 return true;
3134}
3135
3136void TabContents::Observe(NotificationType type,
3137 const NotificationSource& source,
3138 const NotificationDetails& details) {
3139 switch (type.value) {
3140 case NotificationType::BOOKMARK_MODEL_LOADED:
3141 // BookmarkModel finished loading, fall through to update starred state.
3142 case NotificationType::URLS_STARRED: {
3143 // Somewhere, a URL has been starred.
3144 // Ignore notifications for profiles other than our current one.
3145 Profile* source_profile = Source<Profile>(source).ptr();
3146 if (!source_profile || !source_profile->IsSameProfile(profile()))
3147 return;
3148
3149 UpdateStarredStateForCurrentURL();
3150 break;
3151 }
3152 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513153 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323154 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3155 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3156 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533157 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3158 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323159 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173160 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3161 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323162 } else {
3163 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3164 }
3165 break;
3166 }
3167 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3168 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3169 break;
3170
3171 case NotificationType::NAV_ENTRY_COMMITTED: {
3172 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3173
3174 NavigationController::LoadCommittedDetails& committed_details =
3175 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3176 ExpireInfoBars(committed_details);
3177 break;
3178 }
3179
[email protected]d3ba77272009-09-03 00:06:093180#if defined(OS_LINUX)
3181 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543182 renderer_preferences_util::UpdateFromSystemSettings(
3183 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093184 render_view_host()->SyncRendererPrefs();
3185 break;
3186 }
3187#endif
3188
[email protected]6c32ce72010-03-08 05:18:063189 case NotificationType::USER_STYLE_SHEET_UPDATED:
3190 UpdateWebPreferences();
3191 break;
3192
[email protected]79580c62010-02-02 02:36:253193 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:453194 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:253195 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493196 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293197 if (entry)
[email protected]da0c8e92010-02-09 23:25:493198 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293199 if (settings_details.ptr()->update_all() ||
3200 settings_details.ptr()->pattern().Matches(entry_url)) {
3201 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233202 profile()->GetHostContentSettingsMap()->
3203 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253204 }
3205 break;
3206 }
3207
[email protected]e5adff72010-06-14 18:13:063208 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573209 break;
[email protected]a888b29e62010-04-01 13:38:573210
3211 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063212 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573213 break;
[email protected]a888b29e62010-04-01 13:38:573214
[email protected]88152052010-10-01 04:05:183215 case NotificationType::GOOGLE_URL_UPDATED:
3216 UpdateAlternateErrorPageURL();
3217 break;
3218
[email protected]420ae012009-04-24 05:16:323219 default:
3220 NOTREACHED();
3221 }
3222}
[email protected]aacd7cc2009-09-02 14:51:103223
[email protected]9adb9692010-10-29 23:14:023224void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083225 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433226
[email protected]a888b29e62010-04-01 13:38:573227 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083228 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3229 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573230 extension,
[email protected]807871f2010-09-16 01:04:483231 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3232 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573233 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3234 Extension::EXTENSION_ICON_SMALLISH),
3235 ImageLoadingTracker::CACHE);
3236 } else {
[email protected]98aa0b52010-05-06 17:03:083237 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573238 }
3239}
3240
[email protected]9adb9692010-10-29 23:14:023241const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:573242 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3243 if (!extensions_service)
3244 return NULL;
3245
[email protected]9adb9692010-10-29 23:14:023246 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573247 return extension ?
3248 extension : extensions_service->GetExtensionByWebExtent(url);
3249}
3250
[email protected]a888b29e62010-04-01 13:38:573251void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3252 int index) {
3253 if (image) {
[email protected]98aa0b52010-05-06 17:03:083254 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573255 NotifyNavigationStateChanged(INVALIDATE_TAB);
3256 }
3257}
3258
[email protected]beb440c2009-11-06 04:08:543259gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3260 return view_->GetTopLevelNativeWindow();
3261}
3262
3263void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3264 bool success,
3265 const std::wstring& prompt) {
3266 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3267 if (is_showing_before_unload_dialog_ && !success) {
3268 // If a beforeunload dialog is canceled, we need to stop the throbber from
3269 // spinning, since we forced it to start spinning in Navigate.
3270 DidStopLoading();
3271
3272 tab_close_start_time_ = base::TimeTicks();
3273 }
3274 is_showing_before_unload_dialog_ = false;
3275 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3276}
3277
3278void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3279 set_suppress_javascript_messages(suppress_message_boxes);
3280}
3281
[email protected]3a3d47472010-07-15 21:03:543282TabContents* TabContents::AsTabContents() {
3283 return this;
3284}
3285
3286ExtensionHost* TabContents::AsExtensionHost() {
3287 return NULL;
3288}
3289
[email protected]41fc0322009-09-04 22:23:403290void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103291 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3292}
[email protected]f45d2a72010-03-08 23:28:353293
3294void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3295 app_icon_ = app_icon;
3296 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3297}
[email protected]33f74972010-12-08 16:40:363298
3299void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
3300 render_manager_.SwapInRenderViewHost(rvh);
3301}
3302
3303void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
3304 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
3305 rwh_view->SetSize(view()->GetContainerSize());
3306}