blob: fd60bb552c71849d329559558c54a6df5273d00c [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]e5d2f7132010-04-09 18:13:5349#include "chrome/browser/find_bar_state.h"
[email protected]f7578f52010-08-30 22:22:4950#include "chrome/browser/google/google_util.h"
[email protected]8897c382009-05-06 17:53:2651#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0752#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3253#include "chrome/browser/load_from_memory_cache_details.h"
54#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4455#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0556#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1057#include "chrome/browser/omnibox_search_hint.h"
[email protected]14a000d2010-04-29 21:44:2458#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5759#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0260#include "chrome/browser/prefs/pref_service.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]ce560f82009-06-03 09:39:4463#include "chrome/browser/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]54ec6472010-04-09 19:39:5886#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2787#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4988#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5789#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4890#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1491#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0992#include "chrome/common/extensions/url_pattern.h"
93#include "chrome/common/navigation_types.h"
94#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5695#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2996#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3297#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0298#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:1899#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:54100#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:37101#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:26102#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32103#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06104#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37105#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32106#include "net/base/mime_util.h"
107#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29108#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32109#include "net/base/registry_controlled_domain.h"
[email protected]b75b8292010-10-01 07:28:25110#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]1ee614862009-07-06 20:29:18111#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03112#include "webkit/glue/password_form.h"
[email protected]45446a52010-11-04 17:41:00113#include "webkit/glue/plugins/plugin_list.h"
[email protected]3e45ba92009-02-20 21:09:00114
[email protected]420ae012009-04-24 05:16:32115// Cross-Site Navigations
116//
117// If a TabContents is told to navigate to a different web site (as determined
118// by SiteInstance), it will replace its current RenderViewHost with a new
119// RenderViewHost dedicated to the new SiteInstance. This works as follows:
120//
121// - Navigate determines whether the destination is cross-site, and if so,
122// it creates a pending_render_view_host_ and moves into the PENDING
123// RendererState.
124// - The pending RVH is "suspended," so that no navigation messages are sent to
125// its renderer until the onbeforeunload JavaScript handler has a chance to
126// run in the current RVH.
127// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
128// that it has a pending cross-site request. ResourceDispatcherHost will
129// check for this when the response arrives.
130// - The current RVH runs its onbeforeunload handler. If it returns false, we
131// cancel all the pending logic and go back to NORMAL. Otherwise we allow
132// the pending RVH to send the navigation request to its renderer.
133// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
134// checks CrossSiteRequestManager to see that the RVH responsible has a
135// pending cross-site request, and then installs a CrossSiteEventHandler.
136// - When RDH receives a response, the BufferedEventHandler determines whether
137// it is a download. If so, it sends a message to the new renderer causing
138// it to cancel the request, and the download proceeds in the download
139// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34140// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32141// doesn't affect any functionality.
142// - After RDH receives a response and determines that it is safe and not a
143// download, it pauses the response to first run the old page's onunload
144// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34145// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32146// to the current RVH.
147// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
148// the ResourceDispatcherHost, who unpauses the response. Data is then sent
149// to the pending RVH.
150// - The pending renderer sends a FrameNavigate message that invokes the
151// DidNavigate method. This replaces the current RVH with the
152// pending RVH and goes back to the NORMAL RendererState.
153
154namespace {
155
156// Amount of time we wait between when a key event is received and the renderer
157// is queried for its state and pushed to the NavigationEntry.
158const int kQueryStateDelay = 5000;
159
[email protected]6ebdc9b2010-09-27 16:55:57160const int kSyncWaitDelay = 40;
161
[email protected]420ae012009-04-24 05:16:32162// If another javascript message box is displayed within
163// kJavascriptMessageExpectedDelay of a previous javascript message box being
164// dismissed, display an option to suppress future message boxes from this
165// contents.
166const int kJavascriptMessageExpectedDelay = 1000;
167
[email protected]420ae012009-04-24 05:16:32168// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51169const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32170 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17171 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32172 prefs::kWebKitJavaEnabled,
173 prefs::kWebKitJavascriptEnabled,
174 prefs::kWebKitLoadsImagesAutomatically,
175 prefs::kWebKitPluginsEnabled,
176 prefs::kWebKitUsesUniversalDetector,
177 prefs::kWebKitSerifFontFamily,
178 prefs::kWebKitSansSerifFontFamily,
179 prefs::kWebKitFixedFontFamily,
180 prefs::kWebKitDefaultFontSize,
181 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13182 prefs::kWebKitMinimumFontSize,
183 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36184 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32185 prefs::kDefaultCharset
186 // kWebKitStandardFontIsSerif needs to be added
187 // if we let users pick which font to use, serif or sans-serif when
188 // no font is specified or a CSS generic family (serif or sans-serif)
189 // is not specified.
190};
191
192const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
193
[email protected]420ae012009-04-24 05:16:32194// Returns true if the entry's transition type is FORM_SUBMIT.
195bool IsFormSubmit(const NavigationEntry* entry) {
196 return (PageTransition::StripQualifier(entry->transition_type()) ==
197 PageTransition::FORM_SUBMIT);
198}
199
200#if defined(OS_WIN)
201
202BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
203 // Note: erase is required to properly paint some widgets borders. This can
204 // be seen with textfields.
205 InvalidateRect(hwnd, NULL, TRUE);
206 return TRUE;
207}
208#endif
209
[email protected]5e369672009-11-03 23:48:30210ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16211 Profile* profile, const NavigationEntry& entry,
212 NavigationController::ReloadType reload_type) {
213 switch (reload_type) {
214 case NavigationController::RELOAD:
215 return ViewMsg_Navigate_Params::RELOAD;
216 case NavigationController::RELOAD_IGNORING_CACHE:
217 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
218 case NavigationController::NO_RELOAD:
219 break; // Fall through to rest of function.
220 }
[email protected]5e369672009-11-03 23:48:30221
222 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
223 profile->DidLastSessionExitCleanly())
224 return ViewMsg_Navigate_Params::RESTORE;
225
226 return ViewMsg_Navigate_Params::NORMAL;
227}
228
[email protected]876bc832010-09-07 16:29:54229void MakeNavigateParams(const NavigationEntry& entry,
230 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16231 NavigationController::ReloadType reload_type,
232 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34233 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54234 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00235 params->current_history_list_offset = controller.last_committed_entry_index();
236 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34237 params->url = entry.url();
238 params->referrer = entry.referrer();
239 params->transition = entry.transition_type();
240 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00241 params->navigation_type =
242 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34243 params->request_time = base::Time::Now();
244}
245
[email protected]851b1eb2010-08-09 13:32:29246class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
247 public:
248 DisabledPluginInfoBar(TabContents* tab_contents,
249 const string16& name,
250 const GURL& update_url)
251 : ConfirmInfoBarDelegate(tab_contents),
252 tab_contents_(tab_contents),
253 name_(name),
254 update_url_(update_url) {
255 tab_contents->AddInfoBar(this);
256 }
257
258 virtual int GetButtons() const {
259 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
260 }
261
[email protected]e23d3a32010-08-13 19:39:58262 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29263 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58264 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29265 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58266 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29267 return ConfirmInfoBarDelegate::GetButtonLabel(button);
268 }
269
[email protected]e23d3a32010-08-13 19:39:58270 virtual string16 GetMessageText() const {
271 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29272 }
273
[email protected]e23d3a32010-08-13 19:39:58274 virtual string16 GetLinkText() {
275 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29276 }
277
278 virtual SkBitmap* GetIcon() const {
279 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
280 IDR_INFOBAR_PLUGIN_INSTALL);
281 }
282
283 virtual bool Accept() {
284 tab_contents_->OpenURL(update_url_, GURL(),
[email protected]57b66d02010-09-30 11:24:51285 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29286 return false;
287 }
288
289 virtual bool Cancel() {
290 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
[email protected]57b66d02010-09-30 11:24:51291 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29292 return false;
293 }
294
295 virtual bool LinkClicked(WindowOpenDisposition disposition) {
296 // TODO(bauerb): Navigate to a help page explaining why we disabled
297 // the plugin, once we have one.
298 return false;
299 }
300
301 private:
302 TabContents* tab_contents_;
303 string16 name_;
304 GURL update_url_;
305};
306
[email protected]420ae012009-04-24 05:16:32307} // namespace
308
309// -----------------------------------------------------------------------------
310
[email protected]fdd61c62009-04-22 19:22:57311// static
312int TabContents::find_request_id_counter_ = -1;
313
[email protected]420ae012009-04-24 05:16:32314
[email protected]420ae012009-04-24 05:16:32315TabContents::TabContents(Profile* profile,
316 SiteInstance* site_instance,
317 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07318 const TabContents* base_tab_contents,
319 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42320 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07321 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
322 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13323 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22324 TabContentsView::Create(this))),
325 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57326 property_bag_(),
327 registrar_(),
[email protected]12802702010-07-09 19:43:09328 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
329 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57330 save_package_(),
[email protected]6db0def92010-03-02 19:55:45331 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21332 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57333 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06334 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22335 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34336 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29337 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34338 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34339 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57340 current_load_start_(),
341 load_state_(net::LOAD_STATE_IDLE),
342 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56343 upload_size_(0),
344 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57345 received_page_title_(false),
346 is_starred_(false),
347 contents_mime_type_(),
348 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40349 blocked_contents_(NULL),
350 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49351 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47352 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57353 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57354 find_ui_active_(false),
355 find_op_aborted_(false),
356 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12357 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12358 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08359 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57360 capturing_contents_(false),
361 is_being_destroyed_(false),
362 notify_disconnection_(false),
363 history_requests_(),
364#if defined(OS_WIN)
365 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
366#endif
367 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44368 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01369 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54370 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54371 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16372 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38373 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25374 minimum_zoom_percent_(
375 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
376 maximum_zoom_percent_(
377 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00378 temporary_zoom_settings_(false),
379 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54380 renderer_preferences_util::UpdateFromSystemSettings(
381 &renderer_preferences_, profile);
382
[email protected]9fb83e82010-07-02 18:24:55383 content_settings_delegate_.reset(
384 new TabSpecificContentSettings(this, profile));
385
[email protected]12636df2009-09-28 22:32:21386 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32387
[email protected]34ac70502009-09-25 17:07:23388 // We have the initial size of the view be based on the size of the passed in
389 // tab contents (normally a tab from the same window).
390 view_->CreateView(base_tab_contents ?
391 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32392
393 // Register for notifications about all interested prefs change.
394 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28395 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32396 if (prefs) {
397 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28398 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32399 }
400
401 // Register for notifications about URL starredness changing on any profile.
402 registrar_.Add(this, NotificationType::URLS_STARRED,
403 NotificationService::AllSources());
404 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
405 NotificationService::AllSources());
406 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
407 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09408#if defined(OS_LINUX)
409 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
410 NotificationService::AllSources());
411#endif
[email protected]420ae012009-04-24 05:16:32412
[email protected]6c32ce72010-03-08 05:18:06413 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
414 NotificationService::AllSources());
415
[email protected]79580c62010-02-02 02:36:25416 // Register for notifications about content setting changes.
417 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
418 NotificationService::AllSources());
419
[email protected]a888b29e62010-04-01 13:38:57420 // Listen for extension changes so we can update extension_for_current_page_.
421 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
422 NotificationService::AllSources());
423 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
424 NotificationService::AllSources());
425 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
426 NotificationService::AllSources());
427
[email protected]88152052010-10-01 04:05:18428 // Listen for Google URL changes
429 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
430 NotificationService::AllSources());
431
[email protected]c8865482009-07-23 20:40:10432 // Set-up the showing of the omnibox search infobar if applicable.
433 if (OmniboxSearchHint::IsEnabled(profile))
434 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35435}
initial.commit09911bf2008-07-26 23:55:29436
437TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32438 is_being_destroyed_ = true;
439
[email protected]bfe4c1582009-10-02 18:11:09440 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32441 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28442 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32443
[email protected]420ae012009-04-24 05:16:32444 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00445 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32446
[email protected]420ae012009-04-24 05:16:32447 // First cleanly close all child windows.
448 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
449 // some of these to close. CloseWindows is async, so it might get called
450 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49451 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32452
[email protected]c65e2f152010-10-14 15:30:40453 // Close all blocked contents.
454 if (blocked_contents_)
455 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13456
[email protected]420ae012009-04-24 05:16:32457 // Notify any observer that have a reference on this tab contents.
458 NotificationService::current()->Notify(
459 NotificationType::TAB_CONTENTS_DESTROYED,
460 Source<TabContents>(this),
461 NotificationService::NoDetails());
462
[email protected]1e5e74f2009-05-27 20:55:12463 // Notify any lasting InfobarDelegates that have not yet been removed that
464 // whatever infobar they were handling in this TabContents has closed,
465 // because the TabContents is going away entirely.
466 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
467 // notification may trigger infobars calls that access their delegate. (and
468 // some implementations of InfoBarDelegate do delete themselves on
469 // InfoBarClosed()).
470 for (int i = 0; i < infobar_delegate_count(); ++i) {
471 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
472 delegate->InfoBarClosed();
473 }
474 infobar_delegates_.clear();
475
[email protected]420ae012009-04-24 05:16:32476 // TODO(brettw) this should be moved to the view.
477#if defined(OS_WIN)
478 // If we still have a window handle, destroy it. GetNativeView can return
479 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42480 if (GetNativeView()) {
481 RenderViewHost* host = render_view_host();
482 if (host && host->view()) {
483 host->view()->WillWmDestroy();
484 }
[email protected]420ae012009-04-24 05:16:32485 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42486 }
[email protected]420ae012009-04-24 05:16:32487#endif
[email protected]7ab1e7d62009-10-14 23:32:01488
489 // OnCloseStarted isn't called in unit tests.
490 if (!tab_close_start_time_.is_null()) {
491 UMA_HISTOGRAM_TIMES("Tab.Close",
492 base::TimeTicks::Now() - tab_close_start_time_);
493 }
initial.commit09911bf2008-07-26 23:55:29494}
495
[email protected]d5f942ba2008-09-26 19:30:34496// static
497void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32498 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
499
500 WebPreferences pref_defaults;
501 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
502 pref_defaults.javascript_enabled);
503 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
504 pref_defaults.web_security_enabled);
505 prefs->RegisterBooleanPref(
506 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
507 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
508 pref_defaults.loads_images_automatically);
509 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
510 pref_defaults.plugins_enabled);
511 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
512 pref_defaults.dom_paste_enabled);
513 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
514 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14515 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32516 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
517 pref_defaults.text_areas_are_resizable);
518 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
519 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36520 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
521 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32522
523 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
524 IDS_ACCEPT_LANGUAGES);
525 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
526 IDS_DEFAULT_ENCODING);
527 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
528 IDS_STANDARD_FONT_IS_SERIF);
529 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
530 IDS_FIXED_FONT_FAMILY);
531 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
532 IDS_SERIF_FONT_FAMILY);
533 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
534 IDS_SANS_SERIF_FONT_FAMILY);
535 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
536 IDS_CURSIVE_FONT_FAMILY);
537 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
538 IDS_FANTASY_FONT_FAMILY);
539 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
540 IDS_DEFAULT_FONT_SIZE);
541 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
542 IDS_DEFAULT_FIXED_FONT_SIZE);
543 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
544 IDS_MINIMUM_FONT_SIZE);
545 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
546 IDS_MINIMUM_LOGICAL_FONT_SIZE);
547 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
548 IDS_USES_UNIVERSAL_DETECTOR);
549 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
550 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29551}
552
[email protected]13367f72009-07-08 16:39:02553// Returns true if contains content rendered by an extension.
554bool TabContents::HostsExtension() const {
555 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34556}
557
[email protected]cf28ec52010-04-09 22:56:34558AutoFillManager* TabContents::GetAutoFillManager() {
559 if (autofill_manager_.get() == NULL)
560 autofill_manager_.reset(new AutoFillManager(this));
561 return autofill_manager_.get();
562}
563
[email protected]6e95706d2009-04-23 22:55:01564PluginInstaller* TabContents::GetPluginInstaller() {
565 if (plugin_installer_.get() == NULL)
566 plugin_installer_.reset(new PluginInstaller(this));
567 return plugin_installer_.get();
568}
569
[email protected]1f18184a2010-07-21 19:34:49570TabContentsSSLHelper* TabContents::GetSSLHelper() {
571 if (ssl_helper_.get() == NULL)
572 ssl_helper_.reset(new TabContentsSSLHelper(this));
573 return ssl_helper_.get();
574}
575
[email protected]8cb5d5b2010-02-09 11:36:16576RenderProcessHost* TabContents::GetRenderProcessHost() const {
577 return render_manager_.current_host()->process();
578}
579
[email protected]9adb9692010-10-29 23:14:02580void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46581 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08582 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10583
[email protected]98aa0b52010-05-06 17:03:08584 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57585
[email protected]fca656c2010-02-10 20:30:10586 NotificationService::current()->Notify(
587 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
588 Source<TabContents>(this),
589 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49590}
591
[email protected]98aa0b52010-05-06 17:03:08592void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
593 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40594 return;
595
596 ExtensionsService* extension_service = profile()->GetExtensionsService();
[email protected]fa6a9102010-11-22 15:38:50597 if (!extension_service || !extension_service->is_ready())
598 return;
599
600 const Extension* extension =
601 extension_service->GetExtensionById(extension_app_id, false);
602 if (extension)
603 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40604}
605
[email protected]98aa0b52010-05-06 17:03:08606SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08607 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51608 return NULL;
609
[email protected]98aa0b52010-05-06 17:03:08610 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51611}
612
[email protected]d5f942ba2008-09-26 19:30:34613const GURL& TabContents::GetURL() const {
614 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57615 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54616 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34617}
618
[email protected]96d185d2009-04-24 03:28:54619const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55620 // Transient entries take precedence. They are used for interstitial pages
621 // that are shown on top of existing pages.
622 NavigationEntry* entry = controller_.GetTransientEntry();
623 if (entry)
624 return entry->GetTitleForDisplay(&controller_);
625
[email protected]96d185d2009-04-24 03:28:54626 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
627 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
628 if (our_dom_ui) {
629 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55630 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54631 if (!(entry && entry->IsViewSourceMode())) {
632 // Give the DOM UI the chance to override our title.
633 const string16& title = our_dom_ui->overridden_title();
634 if (!title.empty())
635 return title;
636 }
637 }
638
639 // We use the title for the last committed entry rather than a pending
640 // navigation entry. For example, when the user types in a URL, we want to
641 // keep the old page's title until the new load has committed and we get a new
642 // title.
[email protected]96d185d2009-04-24 03:28:54643 entry = controller_.GetLastCommittedEntry();
644 if (entry)
645 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54646 return EmptyString16();
647}
648
[email protected]bbbc1ef2010-02-12 18:03:41649// static
650string16 TabContents::GetDefaultTitle() {
651 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
652}
653
[email protected]d5f942ba2008-09-26 19:30:34654int32 TabContents::GetMaxPageID() {
655 if (GetSiteInstance())
656 return GetSiteInstance()->max_page_id();
657 else
658 return max_page_id_;
659}
660
661void TabContents::UpdateMaxPageID(int32 page_id) {
662 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34663 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34664 // testing.
665 if (GetSiteInstance())
666 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16667 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34668}
669
[email protected]96d185d2009-04-24 03:28:54670SiteInstance* TabContents::GetSiteInstance() const {
671 return render_manager_.current_host()->site_instance();
672}
673
[email protected]96d185d2009-04-24 03:28:54674bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15675 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54676 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15677 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01678 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54679 return true;
[email protected]8ab24cc2009-11-13 20:56:15680 }
[email protected]83e3895b2009-06-11 00:07:16681
[email protected]96d185d2009-04-24 03:28:54682 DOMUI* dom_ui = GetDOMUIForCurrentState();
683 if (dom_ui)
684 return !dom_ui->should_hide_url();
685 return true;
686}
687
[email protected]d5f942ba2008-09-26 19:30:34688SkBitmap TabContents::GetFavIcon() const {
689 // Like GetTitle(), we also want to use the favicon for the last committed
690 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57691 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47692 if (entry)
693 return entry->favicon().bitmap();
694
[email protected]ce3fa3c2009-04-20 19:55:57695 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34696 if (entry)
697 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34698 return SkBitmap();
699}
700
[email protected]0b303cc2009-09-28 22:35:15701bool TabContents::FavIconIsValid() const {
702 NavigationEntry* entry = controller_.GetTransientEntry();
703 if (entry)
704 return entry->favicon().is_valid();
705
706 entry = controller_.GetLastCommittedEntry();
707 if (entry)
708 return entry->favicon().is_valid();
709
710 return false;
711}
712
[email protected]96d185d2009-04-24 03:28:54713bool TabContents::ShouldDisplayFavIcon() {
714 // Always display a throbber during pending loads.
715 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
716 return true;
717
718 DOMUI* dom_ui = GetDOMUIForCurrentState();
719 if (dom_ui)
720 return !dom_ui->hide_favicon();
721 return true;
722}
723
[email protected]96d185d2009-04-24 03:28:54724std::wstring TabContents::GetStatusText() const {
725 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
726 return std::wstring();
727
728 switch (load_state_) {
729 case net::LOAD_STATE_WAITING_FOR_CACHE:
730 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04731 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
732 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54733 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
734 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
735 case net::LOAD_STATE_RESOLVING_HOST:
736 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
737 case net::LOAD_STATE_CONNECTING:
738 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06739 case net::LOAD_STATE_SSL_HANDSHAKE:
740 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54741 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56742 if (upload_size_)
743 return l10n_util::GetStringF(
744 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
745 static_cast<int>((100 * upload_position_) / upload_size_));
746 else
747 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54748 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
749 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
750 load_state_host_);
751 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
752 case net::LOAD_STATE_IDLE:
753 case net::LOAD_STATE_READING_RESPONSE:
754 break;
755 }
756
757 return std::wstring();
758}
759
[email protected]3c9e1872010-11-18 16:17:49760void TabContents::AddNavigationObserver(WebNavigationObserver* observer) {
761 web_navigation_observers_.AddObserver(observer);
762}
763
764void TabContents::RemoveNavigationObserver(WebNavigationObserver* observer) {
765 web_navigation_observers_.RemoveObserver(observer);
766}
767
[email protected]d5f942ba2008-09-26 19:30:34768void TabContents::SetIsCrashed(bool state) {
769 if (state == is_crashed_)
770 return;
771
772 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50773 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34774}
775
[email protected]744ef172009-10-16 21:53:46776void TabContents::PageActionStateChanged() {
777 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00778}
[email protected]ce5c4502009-05-06 16:46:11779
[email protected]d5f942ba2008-09-26 19:30:34780void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
781 if (delegate_)
782 delegate_->NavigationStateChanged(this, changed_flags);
783}
784
[email protected]96d185d2009-04-24 03:28:54785void TabContents::DidBecomeSelected() {
786 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16787 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
788 if (rwhv) {
789 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43790#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16791 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43792#endif
793 }
[email protected]96d185d2009-04-24 03:28:54794
[email protected]8cb5d5b2010-02-09 11:36:16795 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11796 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54797}
798
799void TabContents::WasHidden() {
800 if (!capturing_contents()) {
801 // |render_view_host()| can be NULL if the user middle clicks a link to open
802 // a tab in then background, then closes the tab before selecting it. This
803 // is because closing the tab calls TabContents::Destroy(), which removes
804 // the |render_view_host()|; then when we actually destroy the window,
805 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16806 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
807 if (rwhv)
808 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54809 }
810
811 NotificationService::current()->Notify(
812 NotificationType::TAB_CONTENTS_HIDDEN,
813 Source<TabContents>(this),
814 NotificationService::NoDetails());
815}
816
[email protected]d5f942ba2008-09-26 19:30:34817void TabContents::Activate() {
818 if (delegate_)
819 delegate_->ActivateContents(this);
820}
821
[email protected]ea42e7782010-08-23 23:58:12822void TabContents::Deactivate() {
823 if (delegate_)
824 delegate_->DeactivateContents(this);
825}
826
[email protected]96d185d2009-04-24 03:28:54827void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16828 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
829 if (rwhv)
830 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54831}
832
833void TabContents::HideContents() {
834 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
835 // our superclass HideContents(), because some callers want to be very picky
836 // about the order in which these get called. In addition to making the code
837 // here practically impossible to understand, this also means we end up
838 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34839 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54840 WasHidden();
841}
842
[email protected]c0588052008-10-27 23:01:50843void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34844 WindowOpenDisposition disposition,
845 PageTransition::Type transition) {
846 if (delegate_)
[email protected]c0588052008-10-27 23:01:50847 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34848}
849
[email protected]1ccb3568d2010-02-19 10:51:16850bool TabContents::NavigateToPendingEntry(
851 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54852 return NavigateToEntry(*controller_.pending_entry(), reload_type);
853}
[email protected]96d185d2009-04-24 03:28:54854
[email protected]876bc832010-09-07 16:29:54855bool TabContents::NavigateToEntry(
856 const NavigationEntry& entry,
857 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54858 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
859 if (!dest_render_view_host)
860 return false; // Unable to create the desired render view host.
861
[email protected]770dd8b2010-05-24 18:11:39862 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
863 dest_render_view_host->EnablePreferredSizeChangedMode(
864 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
865 }
[email protected]9fb325e2010-05-06 18:23:24866
[email protected]05fdd492010-11-15 17:52:07867 // For security, we should never send non-DOM-UI URLs to a DOM UI renderer.
868 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58869 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40870 bool is_allowed_in_dom_ui_renderer =
[email protected]05fdd492010-11-15 17:52:07871 DOMUIFactory::IsURLAcceptableForDOMUI(profile(), entry.url());
[email protected]54ec6472010-04-09 19:39:58872 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40873 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58874
[email protected]96d185d2009-04-24 03:28:54875 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12876 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32877 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00878 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
879 dest_render_view_host,
880 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32881 }
[email protected]96d185d2009-04-24 03:28:54882
883 // Used for page load time metrics.
884 current_load_start_ = base::TimeTicks::Now();
885
886 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34887 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54888 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34889 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54890
891 if (entry.page_id() == -1) {
892 // HACK!! This code suppresses javascript: URLs from being added to
893 // session history, which is what we want to do for javascript: URLs that
894 // do not generate content. What we really need is a message from the
895 // renderer telling us that a new page was not created. The same message
896 // could be used for mailto: URLs and the like.
897 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
898 return false;
899 }
900
[email protected]3c9e1872010-11-18 16:17:49901 // Notify observers about navigation.
902 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
903 NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54904
[email protected]1ccb3568d2010-02-19 10:51:16905 if (reload_type != NavigationController::NO_RELOAD &&
906 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48907 FaviconService* favicon_service =
908 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
909 if (favicon_service)
910 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54911 }
912
[email protected]d5f942ba2008-09-26 19:30:34913 return true;
914}
915
[email protected]96d185d2009-04-24 03:28:54916void TabContents::Stop() {
917 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09918 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54919}
920
[email protected]96d185d2009-04-24 03:28:54921void TabContents::DisassociateFromPopupCount() {
922 render_view_host()->DisassociateFromPopupCount();
923}
924
925TabContents* TabContents::Clone() {
926 // We create a new SiteInstance so that the new tab won't share processes
927 // with the old one. This can be changed in the future if we need it to share
928 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32929 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54930 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07931 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54932 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08933 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08934 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54935 return tc;
936}
937
[email protected]4d677202009-07-19 07:37:12938void TabContents::ShowPageInfo(const GURL& url,
939 const NavigationEntry::SSLStatus& ssl,
940 bool show_history) {
941 if (!delegate_)
942 return;
943
[email protected]bb678332009-07-21 00:15:50944 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12945}
946
initial.commit09911bf2008-07-26 23:55:29947ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28948 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29949 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28950 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29951 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44952
953 if (child_windows_.size() == 1) {
954 window->ShowConstrainedWindow();
955 BlockTabContent(true);
956 }
957
initial.commit09911bf2008-07-26 23:55:29958 return window;
959}
960
[email protected]fa1cf0b82010-01-15 21:49:44961void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55962 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
963 if (rwhv)
964 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44965 render_view_host()->set_ignore_input_events(blocked);
966 if (delegate_)
967 delegate_->SetTabContentBlocked(this, blocked);
968}
969
initial.commit09911bf2008-07-26 23:55:29970void TabContents::AddNewContents(TabContents* new_contents,
971 WindowOpenDisposition disposition,
972 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29973 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40974 if (all_contents_blocked_) {
975 if (!blocked_contents_)
976 blocked_contents_ = new BlockedContentContainer(this);
977 blocked_contents_->AddTabContents(
978 new_contents, disposition, initial_pos, user_gesture);
979 return;
980 }
981
initial.commit09911bf2008-07-26 23:55:29982 if (!delegate_)
983 return;
984
[email protected]35f7d212009-04-29 21:19:27985 if ((disposition == NEW_POPUP) && !user_gesture &&
986 !CommandLine::ForCurrentProcess()->HasSwitch(
987 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22988 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31989 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29990 delegate_->GetConstrainingContents(this)->AddPopup(
991 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31992 } else {
[email protected]0aa55312008-10-17 21:53:08993 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29994 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
995 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49996 NotificationService::current()->Notify(
997 NotificationType::TAB_ADDED,
998 Source<TabContentsDelegate>(delegate_),
999 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291000 }
initial.commit09911bf2008-07-26 23:55:291001
[email protected]8cc8d492010-02-02 10:40:491002 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401003 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291004}
1005
[email protected]bcd9dc42010-01-23 16:38:181006bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201007 bool is_js_code, const std::string& code_string,
1008 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511009 RenderViewHost* host = render_view_host();
1010 if (!host)
1011 return false;
1012
1013 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171014 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511015 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351016}
1017
[email protected]96d185d2009-04-24 03:28:541018void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491019 if (is_being_destroyed_)
1020 return;
[email protected]9fb83e82010-07-02 18:24:551021 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491022 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401023 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541024}
1025
[email protected]5c9e97a2009-09-09 23:48:301026gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541027 return view_->GetContentNativeView();
1028}
1029
1030gfx::NativeView TabContents::GetNativeView() const {
1031 return view_->GetNativeView();
1032}
1033
1034void TabContents::GetContainerBounds(gfx::Rect *out) const {
1035 view_->GetContainerBounds(out);
1036}
1037
1038void TabContents::Focus() {
1039 view_->Focus();
1040}
1041
[email protected]90daadb42009-06-08 21:27:281042void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541043 if (showing_interstitial_page()) {
1044 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1045 return;
1046 }
[email protected]96d185d2009-04-24 03:28:541047 render_view_host()->SetInitialFocus(reverse);
1048}
1049
1050bool TabContents::FocusLocationBarByDefault() {
1051 DOMUI* dom_ui = GetDOMUIForCurrentState();
1052 if (dom_ui)
1053 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431054 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251055 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431056 return true;
[email protected]96d185d2009-04-24 03:28:541057 return false;
1058}
1059
[email protected]a26dc362010-04-23 01:48:581060void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381061 if (delegate())
[email protected]a26dc362010-04-23 01:48:581062 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381063}
1064
[email protected]616ed5a2008-11-21 22:27:241065void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321066 if (delegate_ && !delegate_->infobars_enabled()) {
1067 delegate->InfoBarClosed();
1068 return;
1069 }
1070
[email protected]616ed5a2008-11-21 22:27:241071 // Look through the existing InfoBarDelegates we have for a match. If we've
1072 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051073 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451074 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1075 // Tell the new infobar to close so that it can clean itself up.
1076 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241077 return;
[email protected]6d27a7b2009-12-18 23:25:451078 }
[email protected]616ed5a2008-11-21 22:27:241079 }
1080
1081 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561082 NotificationService::current()->Notify(
1083 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1084 Source<TabContents>(this),
1085 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241086
1087 // Add ourselves as an observer for navigations the first time a delegate is
1088 // added. We use this notification to expire InfoBars that need to expire on
1089 // page transitions.
1090 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561091 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571092 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241093 }
1094}
1095
1096void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321097 if (delegate_ && !delegate_->infobars_enabled()) {
1098 return;
1099 }
1100
[email protected]616ed5a2008-11-21 22:27:241101 std::vector<InfoBarDelegate*>::iterator it =
1102 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1103 if (it != infobar_delegates_.end()) {
1104 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561105 NotificationService::current()->Notify(
1106 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1107 Source<TabContents>(this),
1108 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241109
[email protected]cdadf6f2010-08-20 16:36:081110 // Just to be safe, make sure the delegate was not removed by an observer.
1111 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1112 if (it != infobar_delegates_.end()) {
1113 infobar_delegates_.erase(it);
1114 // Remove ourselves as an observer if we are tracking no more InfoBars.
1115 if (infobar_delegates_.empty()) {
1116 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1117 Source<NavigationController>(&controller_));
1118 }
1119 } else {
1120 // If you hit this NOTREACHED, please comment in bug
1121 // http://crbug.com/50428 how you got there.
1122 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031123 }
[email protected]616ed5a2008-11-21 22:27:241124 }
1125}
[email protected]3edd9522009-03-04 22:19:411126
[email protected]f81821c2009-08-07 01:29:471127void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1128 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321129 if (delegate_ && !delegate_->infobars_enabled()) {
1130 new_delegate->InfoBarClosed();
1131 return;
1132 }
1133
[email protected]f81821c2009-08-07 01:29:471134 std::vector<InfoBarDelegate*>::iterator it =
1135 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1136 DCHECK(it != infobar_delegates_.end());
1137
1138 // Notify the container about the change of plans.
1139 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1140 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1141 old_delegate, new_delegate));
1142 NotificationService::current()->Notify(
1143 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1144 Source<TabContents>(this),
1145 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1146
[email protected]cdadf6f2010-08-20 16:36:081147 // Just to be safe, make sure the delegate was not removed by an observer.
1148 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1149 if (it != infobar_delegates_.end()) {
1150 // Remove the old one.
1151 infobar_delegates_.erase(it);
1152 } else {
1153 // If you hit this NOTREACHED, please comment in bug
1154 // http://crbug.com/50428 how you got there.
1155 NOTREACHED();
1156 }
[email protected]f81821c2009-08-07 01:29:471157
1158 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081159 DCHECK(find(infobar_delegates_.begin(),
1160 infobar_delegates_.end(), new_delegate) ==
1161 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471162 infobar_delegates_.push_back(new_delegate);
1163}
1164
[email protected]20ede072009-10-06 00:28:351165bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271166 if (showing_interstitial_page())
1167 return false;
1168
[email protected]c8f74942010-09-03 10:04:141169 // Do not show bookmarks bar if bookmarks aren't enabled.
1170 if (!browser_defaults::bookmarks_enabled)
1171 return false;
1172
[email protected]96d185d2009-04-24 03:28:541173 // See GetDOMUIForCurrentState() comment for more info. This case is very
1174 // similar, but for non-first loads, we want to use the committed entry. This
1175 // is so the bookmarks bar disappears at the same time the page does.
1176 if (controller_.GetLastCommittedEntry()) {
1177 // Not the first load, always use the committed DOM UI.
[email protected]d6219912010-11-17 19:47:371178 return (render_manager_.dom_ui() == NULL) ?
1179 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541180 }
1181
1182 // When it's the first load, we know either the pending one or the committed
1183 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1184 // of them will be valid, so we can just check both.
1185 if (render_manager_.pending_dom_ui())
1186 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
[email protected]d6219912010-11-17 19:47:371187 return (render_manager_.dom_ui() == NULL) ?
1188 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541189}
1190
[email protected]3edd9522009-03-04 22:19:411191void TabContents::ToolbarSizeChanged(bool is_animating) {
1192 TabContentsDelegate* d = delegate();
1193 if (d)
1194 d->ToolbarSizeChanged(this, is_animating);
1195}
[email protected]616ed5a2008-11-21 22:27:241196
[email protected]fc6fb7fb2009-11-07 02:35:041197bool TabContents::CanDownload(int request_id) {
1198 TabContentsDelegate* d = delegate();
1199 if (d)
1200 return d->CanDownload(request_id);
1201 return true;
1202}
1203
[email protected]d5f942ba2008-09-26 19:30:341204void TabContents::OnStartDownload(DownloadItem* download) {
1205 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341206
1207 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311208 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341209
[email protected]5b928b62010-08-03 11:46:511210 if (tab_contents && tab_contents->delegate())
1211 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411212}
[email protected]3edd9522009-03-04 22:19:411213
[email protected]d5f942ba2008-09-26 19:30:341214void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371215 ConstrainedWindowList::iterator i(
1216 std::find(child_windows_.begin(), child_windows_.end(), window));
1217 bool removed_topmost_window = i == child_windows_.begin();
1218 if (i != child_windows_.end())
1219 child_windows_.erase(i);
1220 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441221 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371222 } else {
1223 if (removed_topmost_window)
1224 child_windows_[0]->ShowConstrainedWindow();
1225 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441226 }
[email protected]66ba4932009-06-04 19:22:131227}
[email protected]d5f942ba2008-09-26 19:30:341228
[email protected]c65e2f152010-10-14 15:30:401229void TabContents::WillCloseBlockedContentContainer(
1230 BlockedContentContainer* container) {
1231 DCHECK(blocked_contents_ == container);
1232 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491233 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341234}
1235
[email protected]d5f942ba2008-09-26 19:30:341236void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351237#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061238 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351239#endif
[email protected]d5f942ba2008-09-26 19:30:341240}
1241
[email protected]c1dc9f132009-11-20 23:13:211242void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121243 bool forward_direction,
1244 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211245 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011246 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211247 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531248 string16 last_search_prepopulate_text =
1249 FindBarState::GetLastPrepopulateText(profile());
1250
[email protected]87fae512009-12-11 02:20:211251 // Try the last thing we searched for on this tab, then the last thing
1252 // searched for on any tab.
1253 if (!previous_find_text_.empty())
1254 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531255 else if (!last_search_prepopulate_text.empty())
1256 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211257 else
[email protected]e491f1c2009-05-22 20:28:121258 return;
[email protected]e491f1c2009-05-22 20:28:121259 }
[email protected]6e95706d2009-04-23 22:55:011260
[email protected]101c90e2009-10-26 21:14:441261 // Keep track of the previous search.
1262 previous_find_text_ = find_text_;
1263
[email protected]6e95706d2009-04-23 22:55:011264 // This is a FindNext operation if we are searching for the same text again,
1265 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1266 // exception to this is if the Find was aborted (then we don't want FindNext
1267 // because the highlighting has been cleared and we need it to reappear). We
1268 // therefore treat FindNext after an aborted Find operation as a full fledged
1269 // Find.
[email protected]c1dc9f132009-11-20 23:13:211270 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121271 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011272 !find_op_aborted_;
1273 if (!find_next)
1274 current_find_request_id_ = find_request_id_counter_++;
1275
[email protected]c1dc9f132009-11-20 23:13:211276 if (!search_string.empty())
1277 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121278 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011279
1280 find_op_aborted_ = false;
1281
1282 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531283 FindBarState* find_bar_state = profile()->GetFindBarState();
1284 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011285 render_view_host()->StartFinding(current_find_request_id_,
1286 find_text_,
1287 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121288 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011289 find_next);
1290}
1291
[email protected]5bc8fe92010-03-11 18:19:001292void TabContents::StopFinding(
1293 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011294 if (selection_action == FindBarController::kClearSelection) {
1295 // kClearSelection means the find string has been cleared by the user, but
1296 // the UI has not been dismissed. In that case we want to clear the
1297 // previously remembered search (http://crbug.com/42639).
1298 previous_find_text_ = string16();
1299 } else {
[email protected]2d2dffc2009-06-09 21:41:001300 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011301 if (!find_text_.empty())
1302 previous_find_text_ = find_text_;
1303 }
[email protected]101c90e2009-10-26 21:14:441304 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011305 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121306 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001307 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011308}
1309
[email protected]420ae012009-04-24 05:16:321310void TabContents::OnSavePage() {
1311 // If we can not save the page, try to download it.
1312 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1313 DownloadManager* dlm = profile()->GetDownloadManager();
1314 const GURL& current_page_url = GetURL();
1315 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221316 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321317 return;
1318 }
1319
1320 Stop();
1321
1322 // Create the save package and possibly prompt the user for the name to save
1323 // the page as. The user prompt is an asynchronous operation that runs on
1324 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221325 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321326 save_package_->GetSaveInfo();
1327}
1328
1329// Used in automated testing to bypass prompting the user for file names.
1330// Instead, the names and paths are hard coded rather than running them through
1331// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111332bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321333 SavePackage::SavePackageType save_type) {
1334 // Stop the page from navigating.
1335 Stop();
1336
[email protected]828cabe2009-09-26 22:47:111337 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591338 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321339}
1340
[email protected]89d6e6e2009-12-03 23:06:511341void TabContents::EmailPageLocation() {
1342 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1343 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1344 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1345 title + "&body=%0A%0A" + page_url;
1346 platform_util::OpenExternal(GURL(mailto));
1347}
1348
[email protected]420ae012009-04-24 05:16:321349void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161350 if (CommandLine::ForCurrentProcess()->HasSwitch(
1351 switches::kEnablePrintPreview)) {
1352 if (showing_interstitial_page())
1353 return;
1354 render_view_host()->PrintPreview();
1355 } else {
1356 PrintNow();
1357 }
[email protected]420ae012009-04-24 05:16:321358}
1359
1360bool TabContents::PrintNow() {
1361 // We can't print interstitial page for now.
1362 if (showing_interstitial_page())
1363 return false;
1364
1365 return render_view_host()->PrintPages();
1366}
1367
[email protected]82270452009-06-19 15:58:011368void TabContents::PrintingDone(int document_cookie, bool success) {
1369 render_view_host()->PrintingDone(document_cookie, success);
1370}
1371
[email protected]420ae012009-04-24 05:16:321372bool TabContents::IsActiveEntry(int32 page_id) {
1373 NavigationEntry* active_entry = controller_.GetActiveEntry();
1374 return (active_entry != NULL &&
1375 active_entry->site_instance() == GetSiteInstance() &&
1376 active_entry->page_id() == page_id);
1377}
1378
[email protected]b2fe07d12010-02-09 14:38:081379void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161380 set_encoding(encoding);
1381 render_view_host()->SetPageEncoding(encoding);
1382}
1383
[email protected]b2fe07d12010-02-09 14:38:081384void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161385 reset_encoding();
1386 render_view_host()->ResetPageEncodingToDefault();
1387}
1388
1389void TabContents::WindowMoveOrResizeStarted() {
1390 render_view_host()->WindowMoveOrResizeStarted();
1391}
1392
[email protected]c65e2f152010-10-14 15:30:401393void TabContents::SetAllContentsBlocked(bool value) {
1394 if (all_contents_blocked_ == value)
1395 return;
1396
1397 all_contents_blocked_ = value;
1398 if (!all_contents_blocked_ && blocked_contents_) {
1399 std::vector<TabContents*> blocked;
1400 blocked_contents_->GetBlockedContents(&blocked);
1401 for (size_t i = 0; i < blocked.size(); ++i)
1402 blocked_contents_->LaunchForContents(blocked[i]);
1403 }
1404}
1405
[email protected]3f8eb7f2009-10-02 23:58:051406void TabContents::LogNewTabTime(const std::string& event_name) {
1407 // Not all new tab pages get timed. In those cases, we don't have a
1408 // new_tab_start_time_.
1409 if (new_tab_start_time_.is_null())
1410 return;
1411
1412 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441413 MetricEventDurationDetails details(event_name,
1414 static_cast<int>(duration.InMilliseconds()));
1415
[email protected]7ab1e7d62009-10-14 23:32:011416 if (event_name == "Tab.NewTabScriptStart") {
1417 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1418 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1419 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1420 } else if (event_name == "Tab.NewTabOnload") {
1421 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051422 // The new tab page has finished loading; reset it.
1423 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441424 } else {
1425 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051426 }
[email protected]84abba62009-10-07 17:01:441427 NotificationService::current()->Notify(
1428 NotificationType::METRIC_EVENT_DURATION,
1429 Source<TabContents>(this),
1430 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051431}
1432
[email protected]7ab1e7d62009-10-14 23:32:011433void TabContents::OnCloseStarted() {
1434 if (tab_close_start_time_.is_null())
1435 tab_close_start_time_ = base::TimeTicks::Now();
1436}
1437
[email protected]46624bf2010-06-09 16:04:191438bool TabContents::ShouldAcceptDragAndDrop() const {
1439#if defined(OS_CHROMEOS)
1440 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1441 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201442 if (delegate() && delegate()->IsPopup(this))
1443 return false;
1444 return true;
[email protected]46624bf2010-06-09 16:04:191445#else
1446 return true;
1447#endif
1448}
1449
[email protected]ec0b6c42010-08-26 03:16:581450void TabContents::UpdateHistoryForNavigation(
1451 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1452 if (profile()->IsOffTheRecord())
1453 return;
1454
1455 // Add to history service.
1456 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1457 if (hs)
1458 hs->AddPage(*add_page_args);
1459}
1460
1461void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1462 if (profile()->IsOffTheRecord())
1463 return;
1464
1465 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1466 if (hs)
1467 hs->SetPageTitle(entry.virtual_url(), entry.title());
1468}
1469
[email protected]d0b8d092010-10-25 04:05:171470double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251471 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1472 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171473 return 0;
[email protected]b75b8292010-10-01 07:28:251474
1475 double zoom_level;
1476 if (temporary_zoom_settings_) {
1477 zoom_level = zoom_map->GetTemporaryZoomLevel(
1478 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1479 } else {
1480 zoom_level = zoom_map->GetZoomLevel(GetURL());
1481 }
[email protected]d0b8d092010-10-25 04:05:171482 return zoom_level;
1483}
[email protected]b75b8292010-10-01 07:28:251484
[email protected]d0b8d092010-10-25 04:05:171485int TabContents::GetZoomPercent(bool* enable_increment,
1486 bool* enable_decrement) {
1487 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251488 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171489 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251490 *enable_decrement = percent > minimum_zoom_percent_;
1491 *enable_increment = percent < maximum_zoom_percent_;
1492 return percent;
1493}
1494
[email protected]96d185d2009-04-24 03:28:541495// Notifies the RenderWidgetHost instance about the fact that the page is
1496// loading, or done loading and calls the base implementation.
1497void TabContents::SetIsLoading(bool is_loading,
1498 LoadNotificationDetails* details) {
1499 if (is_loading == is_loading_)
1500 return;
1501
1502 if (!is_loading) {
1503 load_state_ = net::LOAD_STATE_IDLE;
1504 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561505 upload_size_ = 0;
1506 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541507 }
1508
1509 render_manager_.SetIsLoading(is_loading);
1510
1511 is_loading_ = is_loading;
1512 waiting_for_response_ = is_loading;
1513
[email protected]6ebdc9b2010-09-27 16:55:571514 if (delegate_)
1515 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351516 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541517
1518 NotificationType type = is_loading ? NotificationType::LOAD_START :
1519 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111520 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541521 if (details)
1522 det = Details<LoadNotificationDetails>(details);
1523 NotificationService::current()->Notify(type,
1524 Source<NavigationController>(&controller_),
1525 det);
1526}
1527
[email protected]b6c874582009-05-08 19:38:311528void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291529 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061530 // A page can't spawn popups (or do anything else, either) until its load
1531 // commits, so when we reach here, the popup was spawned by the
1532 // NavigationController's last committed entry, not the active entry. For
1533 // example, if a page opens a popup in an onunload() handler, then the active
1534 // entry is the page to be loaded as we navigate away from the unloading
1535 // page. For this reason, we can't use GetURL() to get the opener URL,
1536 // because it returns the active entry.
1537 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1538 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1539
1540 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491541 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091542 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491543 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1544 } else {
[email protected]c65e2f152010-10-14 15:30:401545 if (!blocked_contents_)
1546 blocked_contents_ = new BlockedContentContainer(this);
1547 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1548 true);
[email protected]55126132010-08-19 14:53:281549 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1550 std::string());
[email protected]8cc8d492010-02-02 10:40:491551 }
[email protected]b9681312008-11-07 00:08:261552}
[email protected]616ed5a2008-11-21 22:27:241553
[email protected]616ed5a2008-11-21 22:27:241554void TabContents::ExpireInfoBars(
1555 const NavigationController::LoadCommittedDetails& details) {
1556 // Only hide InfoBars when the user has done something that makes the main
1557 // frame load. We don't want various automatic or subframe navigations making
1558 // it disappear.
1559 if (!details.is_user_initiated_main_frame_load())
1560 return;
1561
[email protected]f86a07022008-11-25 01:06:051562 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241563 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081564 if (!delegate) {
1565 // If you hit this NOTREACHED, please comment in bug
1566 // http://crbug.com/50428 how you got there.
1567 NOTREACHED();
1568 continue;
1569 }
1570
[email protected]f86a07022008-11-25 01:06:051571 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241572 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241573 }
1574}
[email protected]fdd61c62009-04-22 19:22:571575
[email protected]96d185d2009-04-24 03:28:541576DOMUI* TabContents::GetDOMUIForCurrentState() {
1577 // When there is a pending navigation entry, we want to use the pending DOMUI
1578 // that goes along with it to control the basic flags. For example, we want to
1579 // show the pending URL in the URL bar, so we want the display_url flag to
1580 // be from the pending entry.
1581 //
1582 // The confusion comes because there are multiple possibilities for the
1583 // initial load in a tab as a side effect of the way the RenderViewHostManager
1584 // works.
1585 //
1586 // - For the very first tab the load looks "normal". The new tab DOM UI is
1587 // the pending one, and we want it to apply here.
1588 //
1589 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1590 // get switched to the one previously associated with the new tab pages.
1591 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1592 // have a committed DOM UI in this case.
1593 //
1594 // This condition handles all of these cases:
1595 //
1596 // - First load in first tab: no committed nav entry + pending nav entry +
1597 // pending dom ui:
1598 // -> Use pending DOM UI if any.
1599 //
1600 // - First load in second tab: no committed nav entry + pending nav entry +
1601 // no pending DOM UI:
1602 // -> Use the committed DOM UI if any.
1603 //
1604 // - Second navigation in any tab: committed nav entry + pending nav entry:
1605 // -> Use pending DOM UI if any.
1606 //
1607 // - Normal state with no load: committed nav entry + no pending nav entry:
1608 // -> Use committed DOM UI.
1609 if (controller_.pending_entry() &&
1610 (controller_.GetLastCommittedEntry() ||
1611 render_manager_.pending_dom_ui()))
1612 return render_manager_.pending_dom_ui();
1613 return render_manager_.dom_ui();
1614}
[email protected]420ae012009-04-24 05:16:321615
1616void TabContents::DidNavigateMainFramePostCommit(
1617 const NavigationController::LoadCommittedDetails& details,
1618 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441619 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1620 // If this is a window.open navigation, use the same DOMUI as the renderer
1621 // that opened the window, as long as both renderers have the same
1622 // privileges.
[email protected]583d45c12010-08-31 02:48:121623 if (opener_dom_ui_type_ ==
1624 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441625 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1626 // dom_ui might be NULL if the URL refers to a non-existent extension.
1627 if (dom_ui) {
1628 render_manager_.SetDOMUIPostCommit(dom_ui);
1629 dom_ui->RenderViewCreated(render_view_host());
1630 }
1631 }
1632 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1633 }
1634
[email protected]420ae012009-04-24 05:16:321635 if (details.is_user_initiated_main_frame_load()) {
1636 // Clear the status bubble. This is a workaround for a bug where WebKit
1637 // doesn't let us know that the cursor left an element during a
1638 // transition (this is also why the mouse cursor remains as a hand after
1639 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1640 // clear the bubble when a user navigates to a named anchor in the same
1641 // page.
1642 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321643 }
1644
1645 // The keyword generator uses the navigation entries, so must be called after
1646 // the commit.
1647 GenerateKeywordIfNecessary(params);
1648
1649 // Allow the new page to set the title again.
1650 received_page_title_ = false;
1651
1652 // Get the favicon, either from history or request it from the net.
1653 fav_icon_helper_.FetchFavIcon(details.entry->url());
1654
[email protected]0de80162010-02-03 04:52:351655 // Clear all page actions, blocked content notifications and browser actions
1656 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141657 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081658 ExtensionsService* service = profile()->GetExtensionsService();
1659 if (service) {
1660 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571661 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081662 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521663 if (browser_action) {
1664 browser_action->ClearAllValuesForTab(controller().session_id().id());
1665 NotificationService::current()->Notify(
1666 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571667 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521668 NotificationService::NoDetails());
1669 }
[email protected]92c6f9b92009-10-24 04:35:081670
[email protected]5d246db22009-10-27 06:17:571671 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521672 service->extensions()->at(i)->page_action();
1673 if (page_action) {
1674 page_action->ClearAllValuesForTab(controller().session_id().id());
1675 PageActionStateChanged();
1676 }
[email protected]92c6f9b92009-10-24 04:35:081677 }
[email protected]aece2c7f2009-08-27 20:43:171678 }
[email protected]0de80162010-02-03 04:52:351679
1680 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401681 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341682 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401683 blocked_contents_->Destroy();
1684 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351685 }
1686
1687 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411688 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551689 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471690
1691 // Once the main frame is navigated, we're no longer considered to have
1692 // displayed insecure content.
1693 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171694 }
[email protected]ce5c4502009-05-06 16:46:111695
[email protected]8cc8d492010-02-02 10:40:491696 // Close constrained windows if necessary.
1697 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1698 details.previous_url, details.entry->url()))
1699 CloseConstrainedWindows();
1700
[email protected]420ae012009-04-24 05:16:321701 // Update the starred state.
1702 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531703
[email protected]3c9e1872010-11-18 16:17:491704 // Notify observers about navigation.
1705 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1706 DidNavigateMainFramePostCommit(details, params));
1707
[email protected]c07c9752010-03-12 05:57:531708 // Clear the cache of forms in AutoFill.
1709 if (autofill_manager_.get())
1710 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321711}
1712
1713void TabContents::DidNavigateAnyFramePostCommit(
1714 RenderViewHost* render_view_host,
1715 const NavigationController::LoadCommittedDetails& details,
1716 const ViewHostMsg_FrameNavigate_Params& params) {
1717 // If we navigate, start showing messages again. This does nothing to prevent
1718 // a malicious script from spamming messages, since the script could just
1719 // reload the page to stop blocking.
1720 suppress_javascript_messages_ = false;
1721
[email protected]3c9e1872010-11-18 16:17:491722 // Notify observers about navigation.
1723 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1724 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551725
1726 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581727 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321728}
1729
[email protected]8cc8d492010-02-02 10:40:491730void TabContents::CloseConstrainedWindows() {
1731 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321732 // We use indices instead of iterators in case CloseWindow does something
1733 // that may invalidate an iterator.
1734 int size = static_cast<int>(child_windows_.size());
1735 for (int i = size - 1; i >= 0; --i) {
1736 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441737 if (window) {
[email protected]420ae012009-04-24 05:16:321738 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441739 BlockTabContent(false);
1740 }
[email protected]420ae012009-04-24 05:16:321741 }
1742}
1743
1744void TabContents::UpdateStarredStateForCurrentURL() {
1745 BookmarkModel* model = profile()->GetBookmarkModel();
1746 const bool old_state = is_starred_;
1747 is_starred_ = (model && model->IsBookmarked(GetURL()));
1748
1749 if (is_starred_ != old_state && delegate())
1750 delegate()->URLStarredChanged(this, is_starred_);
1751}
1752
1753void TabContents::UpdateAlternateErrorPageURL() {
1754 GURL url = GetAlternateErrorPageURL();
1755 render_view_host()->SetAlternateErrorPageURL(url);
1756}
1757
1758void TabContents::UpdateWebPreferences() {
1759 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1760}
1761
[email protected]d0b8d092010-10-25 04:05:171762void TabContents::UpdateZoomLevel() {
1763 render_view_host()->SetZoomLevel(GetZoomLevel());
1764}
1765
[email protected]420ae012009-04-24 05:16:321766void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1767 RenderViewHost* rvh) {
1768 // If we are creating a RVH for a restored controller, then we might
1769 // have more page IDs than the SiteInstance's current max page ID. We must
1770 // make sure that the max page ID is larger than any restored page ID.
1771 // Note that it is ok for conflicting page IDs to exist in another tab
1772 // (i.e., NavigationController), but if any page ID is larger than the max,
1773 // the back/forward list will get confused.
1774 int max_restored_page_id = controller_.max_restored_page_id();
1775 if (max_restored_page_id > 0) {
1776 int curr_max_page_id = site_instance->max_page_id();
1777 if (max_restored_page_id > curr_max_page_id) {
1778 // Need to update the site instance immediately.
1779 site_instance->UpdateMaxPageID(max_restored_page_id);
1780
1781 // Also tell the renderer to update its internal representation. We
1782 // need to reserve enough IDs to make all restored page IDs less than
1783 // the max.
1784 if (curr_max_page_id < 0)
1785 curr_max_page_id = 0;
1786 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1787 }
1788 }
1789}
1790
[email protected]ec0b6c42010-08-26 03:16:581791scoped_refptr<history::HistoryAddPageArgs>
1792TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541793 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471794 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321795 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581796 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1797 new history::HistoryAddPageArgs(
1798 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1799 params.redirects, params.transition, history::SOURCE_BROWSED,
1800 details.did_replace_entry));
1801 if (PageTransition::IsMainFrame(params.transition) &&
1802 virtual_url != params.url) {
1803 // Hack on the "virtual" URL so that it will appear in history. For some
1804 // types of URLs, we will display a magic URL that is different from where
1805 // the page is actually navigated. We want the user to see in history what
1806 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1807 // only applies to the main frame, as the virtual URL doesn't apply to
1808 // sub-frames.
1809 add_page_args->url = virtual_url;
1810 if (!add_page_args->redirects.empty())
1811 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321812 }
[email protected]ec0b6c42010-08-26 03:16:581813 return add_page_args;
[email protected]420ae012009-04-24 05:16:321814}
1815
1816bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1817 const std::wstring& title) {
1818 // For file URLs without a title, use the pathname instead. In the case of a
1819 // synthesized title, we don't want the update to count toward the "one set
1820 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251821 string16 final_title;
[email protected]420ae012009-04-24 05:16:321822 bool explicit_set;
1823 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251824 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321825 explicit_set = false; // Don't count synthetic titles toward the set limit.
1826 } else {
[email protected]e53668962010-06-23 15:35:251827 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321828 explicit_set = true;
1829 }
1830
[email protected]e53668962010-06-23 15:35:251831 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321832 return false; // Nothing changed, don't bother.
1833
[email protected]e53668962010-06-23 15:35:251834 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321835
[email protected]ec0b6c42010-08-26 03:16:581836 if (!received_page_title_) {
1837 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321838 received_page_title_ = explicit_set;
1839 }
1840
1841 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251842 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321843
[email protected]cbc0e1b2010-04-12 18:33:041844 NotificationService::current()->Notify(
1845 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1846 Source<TabContents>(this),
1847 NotificationService::NoDetails());
1848
[email protected]420ae012009-04-24 05:16:321849 return true;
1850}
1851
1852void TabContents::NotifySwapped() {
1853 // After sending out a swap notification, we need to send a disconnect
1854 // notification so that clients that pick up a pointer to |this| can NULL the
1855 // pointer. See Bug 1230284.
1856 notify_disconnection_ = true;
1857 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341858 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221859 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321860 NotificationService::NoDetails());
1861}
1862
1863void TabContents::NotifyConnected() {
1864 notify_disconnection_ = true;
1865 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341866 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221867 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321868 NotificationService::NoDetails());
1869}
1870
1871void TabContents::NotifyDisconnected() {
1872 if (!notify_disconnection_)
1873 return;
1874
1875 notify_disconnection_ = false;
1876 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341877 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221878 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321879 NotificationService::NoDetails());
1880}
1881
1882void TabContents::GenerateKeywordIfNecessary(
1883 const ViewHostMsg_FrameNavigate_Params& params) {
1884 if (!params.searchable_form_url.is_valid())
1885 return;
1886
1887 if (profile()->IsOffTheRecord())
1888 return;
1889
1890 int last_index = controller_.last_committed_entry_index();
1891 // When there was no previous page, the last index will be 0. This is
1892 // normally due to a form submit that opened in a new tab.
1893 // TODO(brettw) bug 916126: we should support keywords when form submits
1894 // happen in new tabs.
1895 if (last_index <= 0)
1896 return;
1897 const NavigationEntry* previous_entry =
1898 controller_.GetEntryAtIndex(last_index - 1);
1899 if (IsFormSubmit(previous_entry)) {
1900 // Only generate a keyword if the previous page wasn't itself a form
1901 // submit.
1902 return;
1903 }
1904
1905 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1906 previous_entry->user_typed_url() : previous_entry->url();
1907 std::wstring keyword =
1908 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1909 if (keyword.empty())
1910 return;
1911
1912 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1913 if (!url_model)
1914 return;
1915
1916 if (!url_model->loaded()) {
1917 url_model->Load();
1918 return;
1919 }
1920
1921 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191922 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321923 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1924 return;
1925
1926 if (current_url) {
1927 if (current_url->originating_url().is_valid()) {
1928 // The existing keyword was generated from an OpenSearch description
1929 // document, don't regenerate.
1930 return;
1931 }
1932 url_model->Remove(current_url);
1933 }
1934 TemplateURL* new_url = new TemplateURL();
1935 new_url->set_keyword(keyword);
1936 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191937 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321938 new_url->add_input_encoding(params.searchable_form_encoding);
1939 DCHECK(controller_.GetLastCommittedEntry());
1940 const GURL& favicon_url =
1941 controller_.GetLastCommittedEntry()->favicon().url();
1942 if (favicon_url.is_valid()) {
1943 new_url->SetFavIconURL(favicon_url);
1944 } else {
1945 // The favicon url isn't valid. This means there really isn't a favicon,
1946 // or the favicon url wasn't obtained before the load started. This assumes
1947 // the later.
1948 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1949 // its url.
1950 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1951 }
1952 new_url->set_safe_for_autoreplace(true);
1953 url_model->Add(new_url);
1954}
1955
[email protected]bf5c2ff392009-07-08 16:24:331956void TabContents::OnUserGesture() {
1957 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011958 DownloadRequestLimiter* limiter =
1959 g_browser_process->download_request_limiter();
1960 if (limiter)
1961 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261962 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331963}
1964
1965void TabContents::OnFindReply(int request_id,
1966 int number_of_matches,
1967 const gfx::Rect& selection_rect,
1968 int active_match_ordinal,
1969 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421970 // Ignore responses for requests that have been aborted.
1971 if (find_op_aborted_)
1972 return;
1973
[email protected]bf5c2ff392009-07-08 16:24:331974 // Ignore responses for requests other than the one we have most recently
1975 // issued. That way we won't act on stale results when the user has
1976 // already typed in another query.
1977 if (request_id != current_find_request_id_)
1978 return;
1979
1980 if (number_of_matches == -1)
1981 number_of_matches = last_search_result_.number_of_matches();
1982 if (active_match_ordinal == -1)
1983 active_match_ordinal = last_search_result_.active_match_ordinal();
1984
1985 gfx::Rect selection = selection_rect;
1986 if (selection.IsEmpty())
1987 selection = last_search_result_.selection_rect();
1988
1989 // Notify the UI, automation and any other observers that a find result was
1990 // found.
1991 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1992 selection, active_match_ordinal,
1993 final_update);
1994 NotificationService::current()->Notify(
1995 NotificationType::FIND_RESULT_AVAILABLE,
1996 Source<TabContents>(this),
1997 Details<FindNotificationDetails>(&last_search_result_));
1998}
1999
2000void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542001 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2002 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2003 if (!entry)
2004 return;
2005 // Note that we don't call NavigationController::GotToOffset() as we don't
2006 // want to create a pending navigation entry (it might end up lingering
2007 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522008 entry->set_transition_type(entry->transition_type() |
2009 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542010 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2011 }
[email protected]bf5c2ff392009-07-08 16:24:332012}
2013
[email protected]bf5c2ff392009-07-08 16:24:332014void TabContents::OnMissingPluginStatus(int status) {
2015#if defined(OS_WIN)
2016// TODO(PORT): pull in when plug-ins work
2017 GetPluginInstaller()->OnMissingPluginStatus(status);
2018#endif
2019}
2020
2021void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332022 DCHECK(!plugin_path.value().empty());
2023
2024 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]45446a52010-11-04 17:41:002025 WebPluginInfo plugin_info;
2026 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
2027 plugin_path, &plugin_info) &&
2028 !plugin_info.name.empty()) {
2029 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372030#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002031 // Many plugins on the Mac have .plugin in the actual name, which looks
2032 // terrible, so look for that and strip it off if present.
2033 const std::wstring plugin_extension(L".plugin");
2034 if (EndsWith(plugin_name, plugin_extension, true))
2035 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372036#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332037 }
[email protected]2ae8a922010-06-28 20:27:532038 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2039 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332040 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582041 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2042 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532043 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332044}
2045
2046void TabContents::OnCrashedWorker() {
2047 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582048 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422049 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332050}
2051
[email protected]38789d82010-11-17 06:03:442052void TabContents::OnDidGetApplicationInfo(int32 page_id,
2053 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512054 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332055
[email protected]ed5431872009-11-17 08:39:512056 if (delegate())
2057 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332058}
2059
[email protected]bb461532010-11-26 21:50:232060void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
2061 if (delegate())
2062 delegate()->OnInstallApplication(this, info);
2063}
2064
[email protected]851b1eb2010-08-09 13:32:292065void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2066 const GURL& update_url) {
2067 new DisabledPluginInfoBar(this, name, update_url);
2068}
2069
[email protected]a2cf65eb2010-01-18 08:20:382070void TabContents::OnPageContents(const GURL& url,
2071 int renderer_process_id,
2072 int32 page_id,
[email protected]e5106202010-06-11 21:12:362073 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102074 const std::string& language,
2075 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382076 // Don't index any https pages. People generally don't want their bank
2077 // accounts, etc. indexed on their computer, especially since some of these
2078 // things are not marked cachable.
2079 // TODO(brettw) we may want to consider more elaborate heuristics such as
2080 // the cachability of the page. We may also want to consider subframes (this
2081 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272082 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2083 // content indexing for chromeos in some future releases.
2084#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382085 if (!url.SchemeIsSecure()) {
2086 Profile* p = profile();
2087 if (p && !p->IsOffTheRecord()) {
2088 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2089 if (hs)
2090 hs->SetPageContents(url, contents);
2091 }
2092 }
[email protected]ccd40a52010-05-11 16:15:272093#endif
[email protected]a8a81292010-01-21 00:32:452094
[email protected]1c57b7b2010-07-12 17:38:102095 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452096
2097 std::string lang = language;
2098 NotificationService::current()->Notify(
2099 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152100 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452101 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382102}
2103
[email protected]7e0831b2010-02-01 08:45:152104void TabContents::OnPageTranslated(int32 page_id,
2105 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162106 const std::string& translated_lang,
2107 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552108 language_state_.set_current_language(translated_lang);
2109 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162110 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152111 NotificationService::current()->Notify(
2112 NotificationType::PAGE_TRANSLATED,
2113 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162114 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152115}
2116
[email protected]ce833282010-11-04 15:48:392117void TabContents::OnSetSuggestions(
2118 int32 page_id,
2119 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262120 if (delegate())
[email protected]ce833282010-11-04 15:48:392121 delegate()->OnSetSuggestions(page_id, suggestions);
2122}
2123
2124void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2125 if (delegate())
2126 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262127}
2128
[email protected]bf5c2ff392009-07-08 16:24:332129void TabContents::DidStartProvisionalLoadForFrame(
2130 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182131 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332132 bool is_main_frame,
[email protected]ea51f1f2010-12-01 10:07:272133 bool is_error_page,
[email protected]bf5c2ff392009-07-08 16:24:332134 const GURL& url) {
2135 ProvisionalLoadDetails details(is_main_frame,
2136 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412137 url, std::string(), false,
2138 is_error_page, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332139 NotificationService::current()->Notify(
2140 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2141 Source<NavigationController>(&controller_),
2142 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142143 if (is_main_frame) {
[email protected]ea51f1f2010-12-01 10:07:272144 // If we're displaying a network error page do not reset the content
2145 // settings delegate's cookies so the user has a chance to modify cookie
2146 // settings.
2147 if (!is_error_page)
2148 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142149 content_settings_delegate_->ClearGeolocationContentSettings();
2150 }
[email protected]bf5c2ff392009-07-08 16:24:332151}
2152
2153void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202154 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332155 NotificationService::current()->Notify(
2156 NotificationType::RESOURCE_RESPONSE_STARTED,
2157 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202158 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332159}
2160
[email protected]3dbb80b2010-02-09 22:41:202161void TabContents::DidRedirectResource(
2162 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332163 NotificationService::current()->Notify(
2164 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2165 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202166 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332167}
2168
2169void TabContents::DidLoadResourceFromMemoryCache(
2170 const GURL& url,
2171 const std::string& frame_origin,
2172 const std::string& main_frame_origin,
2173 const std::string& security_info) {
2174 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442175 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332176 SSLManager::DeserializeSecurityInfo(security_info,
2177 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042178 &security_bits,
2179 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332180 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162181 GetRenderProcessHost()->id(), cert_id,
2182 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332183
2184 NotificationService::current()->Notify(
2185 NotificationType::LOAD_FROM_MEMORY_CACHE,
2186 Source<NavigationController>(&controller_),
2187 Details<LoadFromMemoryCacheDetails>(&details));
2188}
2189
[email protected]e3d60e5d2009-09-25 21:08:292190void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472191 displayed_insecure_content_ = true;
2192 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292193}
2194
2195void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592196 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292197}
2198
[email protected]bf5c2ff392009-07-08 16:24:332199void TabContents::DidFailProvisionalLoadWithError(
2200 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182201 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332202 bool is_main_frame,
2203 int error_code,
2204 const GURL& url,
2205 bool showing_repost_interstitial) {
2206 if (net::ERR_ABORTED == error_code) {
2207 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2208 // This means that the interstitial won't be torn down properly, which is
2209 // bad. But if we have an interstitial, go back to another tab type, and
2210 // then load the same interstitial again, we could end up getting the first
2211 // interstitial's "failed" message (as a result of the cancel) when we're on
2212 // the second one.
2213 //
2214 // We can't tell this apart, so we think we're tearing down the current page
2215 // which will cause a crash later one. There is also some code in
2216 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2217 // out because of this problem.
2218 //
2219 // http://code.google.com/p/chromium/issues/detail?id=2855
2220 // Because this will not tear down the interstitial properly, if "back" is
2221 // back to another tab type, the interstitial will still be somewhat alive
2222 // in the previous tab type. If you navigate somewhere that activates the
2223 // tab with the interstitial again, you'll see a flash before the new load
2224 // commits of the interstitial page.
2225 if (showing_interstitial_page()) {
2226 LOG(WARNING) << "Discarding message during interstitial.";
2227 return;
2228 }
2229
2230 // This will discard our pending entry if we cancelled the load (e.g., if we
2231 // decided to download the file instead of load it). Only discard the
2232 // pending entry if the URLs match, otherwise the user initiated a navigate
2233 // before the page loaded so that the discard would discard the wrong entry.
2234 NavigationEntry* pending_entry = controller_.pending_entry();
2235 if (pending_entry && pending_entry->url() == url) {
2236 controller_.DiscardNonCommittedEntries();
2237 // Update the URL display.
2238 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2239 }
2240
2241 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2242 }
2243
2244 // Send out a notification that we failed a provisional load with an error.
2245 ProvisionalLoadDetails details(is_main_frame,
2246 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412247 url, std::string(), false, false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332248 details.set_error_code(error_code);
2249
2250 NotificationService::current()->Notify(
2251 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2252 Source<NavigationController>(&controller_),
2253 Details<ProvisionalLoadDetails>(&details));
2254}
2255
[email protected]4b8e2b02010-11-30 09:15:182256void TabContents::DocumentLoadedInFrame(int64 frame_id) {
[email protected]bf5c2ff392009-07-08 16:24:332257 controller_.DocumentLoadedInFrame();
[email protected]622474d2010-11-04 09:21:082258 NotificationService::current()->Notify(
2259 NotificationType::FRAME_DOM_CONTENT_LOADED,
2260 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182261 Details<int64>(&frame_id));
[email protected]bf5c2ff392009-07-08 16:24:332262}
2263
[email protected]4b8e2b02010-11-30 09:15:182264void TabContents::DidFinishLoad(int64 frame_id) {
[email protected]fdd94a02010-11-05 08:07:172265 NotificationService::current()->Notify(
2266 NotificationType::FRAME_DID_FINISH_LOAD,
2267 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182268 Details<int64>(&frame_id));
[email protected]fdd94a02010-11-05 08:07:172269}
2270
[email protected]dcd5b332010-08-11 08:55:182271void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562272 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242273 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562274}
2275
[email protected]8d3347f2009-07-09 22:00:212276RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322277 return view_.get();
2278}
2279
[email protected]8d3347f2009-07-09 22:00:212280RenderViewHostDelegate::RendererManagement*
2281TabContents::GetRendererManagementDelegate() {
2282 return &render_manager_;
2283}
2284
[email protected]bf5c2ff392009-07-08 16:24:332285RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212286 TabContents::GetBrowserIntegrationDelegate() {
2287 return this;
[email protected]bf5c2ff392009-07-08 16:24:332288}
2289
[email protected]8d3347f2009-07-09 22:00:212290RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2291 return this;
[email protected]bf5c2ff392009-07-08 16:24:332292}
2293
[email protected]46ba9082010-06-22 10:00:582294RenderViewHostDelegate::ContentSettings*
2295TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552296 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582297}
2298
[email protected]8d3347f2009-07-09 22:00:212299RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322300 return save_package_.get(); // May be NULL, but we can return NULL.
2301}
2302
[email protected]8d3347f2009-07-09 22:00:212303RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092304 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212305}
2306
2307RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2308 return &fav_icon_helper_;
2309}
2310
[email protected]e8dbd674b2010-03-11 18:34:402311RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452312 if (autocomplete_history_manager_.get() == NULL)
2313 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2314 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332315}
2316
[email protected]21674df2009-10-28 19:51:212317RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342318 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212319}
2320
[email protected]1f18184a2010-07-21 19:34:492321RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2322 return GetSSLHelper();
2323}
2324
[email protected]b5977a0c2010-08-24 19:46:262325RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2326 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492327 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262328 return file_select_helper_.get();
2329}
2330
[email protected]fd571bb2010-03-19 01:23:542331AutomationResourceRoutingDelegate*
2332TabContents::GetAutomationResourceRoutingDelegate() {
2333 return delegate();
2334}
2335
[email protected]ced90ae12010-02-20 02:06:162336RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2337 return bookmark_drag_;
2338}
2339
2340void TabContents::SetBookmarkDragDelegate(
2341 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2342 bookmark_drag_ = bookmark_drag;
2343}
2344
[email protected]9fb83e82010-07-02 18:24:552345TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2346 return content_settings_delegate_.get();
2347}
2348
[email protected]93623c5d2009-12-10 21:40:322349RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462350 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512351}
2352
[email protected]57c6a652009-05-04 07:58:342353TabContents* TabContents::GetAsTabContents() {
2354 return this;
2355}
2356
[email protected]7b291f92009-08-14 05:43:532357ViewType::Type TabContents::GetRenderViewType() const {
2358 return ViewType::TAB_CONTENTS;
2359}
2360
2361int TabContents::GetBrowserWindowID() const {
2362 return controller().window_id().id();
2363}
2364
[email protected]420ae012009-04-24 05:16:322365void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062366 NotificationService::current()->Notify(
2367 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2368 Source<TabContents>(this),
2369 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322370 NavigationEntry* entry = controller_.GetActiveEntry();
2371 if (!entry)
2372 return;
2373
2374 // When we're creating views, we're still doing initial setup, so we always
2375 // use the pending DOM UI rather than any possibly existing committed one.
2376 if (render_manager_.pending_dom_ui()) {
2377 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2378 }
2379
2380 if (entry->IsViewSourceMode()) {
2381 // Put the renderer in view source mode.
2382 render_view_host->Send(
2383 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2384 }
[email protected]0666aef2009-05-13 19:48:082385
2386 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322387}
2388
2389void TabContents::RenderViewReady(RenderViewHost* rvh) {
2390 if (rvh != render_view_host()) {
2391 // Don't notify the world, since this came from a renderer in the
2392 // background.
2393 return;
2394 }
2395
2396 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302397 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322398 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302399
2400 // Restore the focus to the tab (otherwise the focus will be on the top
2401 // window).
[email protected]484ae5912010-09-29 19:16:142402 if (was_crashed && !FocusLocationBarByDefault() &&
2403 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302404 Focus();
[email protected]484ae5912010-09-29 19:16:142405 }
[email protected]420ae012009-04-24 05:16:322406}
2407
2408void TabContents::RenderViewGone(RenderViewHost* rvh) {
2409 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092410 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322411 return;
2412 if (rvh != render_view_host()) {
2413 // The pending page's RenderViewHost is gone.
2414 return;
2415 }
2416
2417 SetIsLoading(false, NULL);
2418 NotifyDisconnected();
2419 SetIsCrashed(true);
2420
[email protected]ff9efc62010-02-18 22:10:542421 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212422 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542423 RemoveInfoBar(GetInfoBarDelegateAt(i));
2424
[email protected]8e537302009-06-10 21:19:582425 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552426 // Only do this if we're not in browser shutdown, so that TabContents
2427 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2428 // visible do not flash a sad tab page.
2429 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2430 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322431
2432 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002433 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322434}
2435
[email protected]2e4633c2009-07-09 16:58:062436void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2437 NotificationService::current()->Notify(
2438 NotificationType::RENDER_VIEW_HOST_DELETED,
2439 Source<TabContents>(this),
2440 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482441 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062442}
2443
[email protected]420ae012009-04-24 05:16:322444void TabContents::DidNavigate(RenderViewHost* rvh,
2445 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372446 int extra_invalidate_flags = 0;
2447
2448 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352449 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372450
[email protected]420ae012009-04-24 05:16:322451 render_manager_.DidNavigateMainFrame(rvh);
2452
[email protected]20ede072009-10-06 00:28:352453 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372454 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372455 }
2456
[email protected]420ae012009-04-24 05:16:322457 // Update the site of the SiteInstance if it doesn't have one yet.
2458 if (!GetSiteInstance()->has_site())
2459 GetSiteInstance()->SetSite(params.url);
2460
2461 // Need to update MIME type here because it's referred to in
2462 // UpdateNavigationCommands() called by RendererDidNavigate() to
2463 // determine whether or not to enable the encoding menu.
2464 // It's updated only for the main frame. For a subframe,
2465 // RenderView::UpdateURL does not set params.contents_mime_type.
2466 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2467 // TODO(jungshik): Add a test for the encoding menu to avoid
2468 // regressing it again.
2469 if (PageTransition::IsMainFrame(params.transition))
2470 contents_mime_type_ = params.contents_mime_type;
2471
2472 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372473 bool did_navigate = controller_.RendererDidNavigate(
2474 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392475
[email protected]a9c0bfe2010-09-17 08:35:222476 // Send notification about committed provisional loads. This notification is
2477 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2478 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2479 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072480 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2481 // that is not recorded in the navigation history. For the purpose of
2482 // tracking navigation events, we treat this event as a sub frame navigation
2483 // event.
2484 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2485 ProvisionalLoadDetails load_details(
2486 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412487 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222488 load_details.set_transition_type(params.transition);
2489 // Whether or not a page transition was triggered by going backward or
2490 // forward in the history is only stored in the navigation controller's
2491 // entry list.
2492 if (did_navigate &&
2493 (controller_.GetActiveEntry()->transition_type() &
2494 PageTransition::FORWARD_BACK)) {
2495 load_details.set_transition_type(
2496 params.transition | PageTransition::FORWARD_BACK);
2497 }
2498 NotificationService::current()->Notify(
2499 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2500 Source<NavigationController>(&controller_),
2501 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222502 }
2503
[email protected]3e90d4a2009-07-03 17:38:392504 // Update history. Note that this needs to happen after the entry is complete,
2505 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582506 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392507 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582508 // URLs, we use a data: URL as the real value. We actually want to save the
2509 // about: URL to the history db and keep the data: URL hidden. This is what
2510 // the TabContents' URL getter does.
2511 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2512 CreateHistoryAddPageArgs(GetURL(), details, params));
2513 if (!delegate() ||
2514 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2515 details.type)) {
2516 UpdateHistoryForNavigation(add_page_args);
2517 }
[email protected]3e90d4a2009-07-03 17:38:392518 }
2519
[email protected]76543b92009-08-31 17:27:452520 if (!did_navigate)
2521 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322522
2523 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2524 // for the appropriate notification (best) or you can add it to
2525 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2526 // necessary, please).
2527
2528 // Run post-commit tasks.
2529 if (details.is_main_frame)
2530 DidNavigateMainFramePostCommit(details, params);
2531 DidNavigateAnyFramePostCommit(rvh, details, params);
2532}
2533
2534void TabContents::UpdateState(RenderViewHost* rvh,
2535 int32 page_id,
2536 const std::string& state) {
2537 DCHECK(rvh == render_view_host());
2538
2539 // We must be prepared to handle state updates for any page, these occur
2540 // when the user is scrolling and entering form data, as well as when we're
2541 // leaving a page, in which case our state may have already been moved to
2542 // the next page. The navigation controller will look up the appropriate
2543 // NavigationEntry and update it when it is notified via the delegate.
2544
2545 int entry_index = controller_.GetEntryIndexWithPageID(
2546 GetSiteInstance(), page_id);
2547 if (entry_index < 0)
2548 return;
2549 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2550
2551 if (state == entry->content_state())
2552 return; // Nothing to update.
2553 entry->set_content_state(state);
2554 controller_.NotifyEntryChanged(entry, entry_index);
2555}
2556
2557void TabContents::UpdateTitle(RenderViewHost* rvh,
2558 int32 page_id, const std::wstring& title) {
2559 // If we have a title, that's a pretty good indication that we've started
2560 // getting useful data.
2561 SetNotWaitingForResponse();
2562
2563 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482564 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582565 page_id);
[email protected]420ae012009-04-24 05:16:322566 if (!entry || !UpdateTitleForEntry(entry, title))
2567 return;
2568
2569 // Broadcast notifications when the UI should be updated.
2570 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032571 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322572}
2573
[email protected]420ae012009-04-24 05:16:322574void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402575 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322576 set_encoding(encoding);
2577}
2578
2579void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2580 if (delegate())
2581 delegate()->UpdateTargetURL(this, url);
2582}
2583
2584void TabContents::UpdateThumbnail(const GURL& url,
2585 const SkBitmap& bitmap,
2586 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442587 if (profile()->IsOffTheRecord())
2588 return;
2589
[email protected]420ae012009-04-24 05:16:322590 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492591 if (history::TopSites::IsEnabled()) {
[email protected]e6baed562010-11-02 22:33:442592 history::TopSites* ts = profile()->GetTopSites();
2593 if (ts)
2594 ts->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282595 } else {
[email protected]e6baed562010-11-02 22:33:442596 HistoryService* hs =
2597 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2598 if (hs)
[email protected]449478302009-06-09 20:04:282599 hs->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322600 }
2601}
2602
[email protected]c4e98902010-06-01 10:20:142603void TabContents::UpdateInspectorSetting(const std::string& key,
2604 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052605 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082606}
2607
[email protected]45aafc92010-06-07 14:18:532608void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052609 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532610}
2611
[email protected]420ae012009-04-24 05:16:322612void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292613 // The UI may be in an event-tracking loop, such as between the
2614 // mouse-down and mouse-up in text selection or a button click.
2615 // Defer the close until after tracking is complete, so that we
2616 // don't free objects out from under the UI.
2617 // TODO(shess): This could probably be integrated with the
2618 // IsDoingDrag() test below. Punting for now because I need more
2619 // research to understand how this impacts platforms other than Mac.
2620 // TODO(shess): This could get more fine-grained. For instance,
2621 // closing a tab in another window while selecting text in the
2622 // current window's Omnibox should be just fine.
2623 if (view()->IsEventTracking()) {
2624 view()->CloseTabAfterEventTracking();
2625 return;
2626 }
2627
[email protected]24a4d1062009-07-10 23:10:422628 // If we close the tab while we're in the middle of a drag, we'll crash.
2629 // Instead, cancel the drag and close it as soon as the drag ends.
2630 if (view()->IsDoingDrag()) {
2631 view()->CancelDragAndCloseTab();
2632 return;
2633 }
2634
[email protected]420ae012009-04-24 05:16:322635 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2636 if (delegate() && rvh == render_view_host())
2637 delegate()->CloseContents(this);
2638}
2639
2640void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2641 if (delegate() && delegate()->IsPopup(this))
2642 delegate()->MoveContents(this, new_bounds);
2643}
2644
[email protected]7ab1e7d62009-10-14 23:32:012645void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322646 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492647
[email protected]9e823662010-10-13 23:36:002648 if (content_restrictions_) {
2649 content_restrictions_= 0;
2650 delegate()->ContentRestrictionsChanged(this);
2651 }
[email protected]3c9e1872010-11-18 16:17:492652
2653 // Notify observers about navigation.
2654 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2655 DidStartLoading());
[email protected]420ae012009-04-24 05:16:322656}
2657
[email protected]7ab1e7d62009-10-14 23:32:012658void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322659 scoped_ptr<LoadNotificationDetails> details;
2660
2661 NavigationEntry* entry = controller_.GetActiveEntry();
2662 // An entry may not exist for a stop when loading an initial blank page or
2663 // if an iframe injected by script into a blank page finishes loading.
2664 if (entry) {
[email protected]420ae012009-04-24 05:16:322665 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2666
2667 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542668 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322669 entry->transition_type(),
2670 elapsed,
2671 &controller_,
2672 controller_.GetCurrentEntryIndex()));
2673 }
2674
[email protected]420ae012009-04-24 05:16:322675 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492676
2677 // Notify observers about navigation.
2678 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2679 DidStopLoading());
[email protected]420ae012009-04-24 05:16:322680}
2681
[email protected]25497492010-09-11 15:15:082682void TabContents::DocumentOnLoadCompletedInMainFrame(
2683 RenderViewHost* render_view_host,
2684 int32 page_id) {
2685 NotificationService::current()->Notify(
2686 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2687 Source<TabContents>(this),
2688 Details<int>(&page_id));
2689}
2690
[email protected]420ae012009-04-24 05:16:322691void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2692 const GURL& source_url,
2693 const GURL& target_url) {
2694 NavigationEntry* entry;
2695 if (page_id == -1)
2696 entry = controller_.pending_entry();
2697 else
2698 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2699 if (!entry || entry->url() != source_url)
2700 return;
2701 entry->set_url(target_url);
2702}
2703
[email protected]420ae012009-04-24 05:16:322704void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2705 WindowOpenDisposition disposition) {
2706 if (render_manager_.dom_ui()) {
2707 // When we're a DOM UI, it will provide a page transition type for us (this
2708 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2709 // generated suggestions).
2710 //
2711 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162712 // want web sites to see a referrer of "chrome://blah" (and some
2713 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322714 // send to the site), so we send no referrer.
2715 OpenURL(url, GURL(), disposition,
2716 render_manager_.dom_ui()->link_transition_type());
2717 } else {
2718 OpenURL(url, referrer, disposition, PageTransition::LINK);
2719 }
2720}
2721
[email protected]1ee614862009-07-06 20:29:182722void TabContents::DomOperationResponse(const std::string& json_string,
2723 int automation_id) {
2724}
2725
[email protected]8b8e7c92010-08-19 18:05:562726void TabContents::ProcessDOMUIMessage(
2727 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322728 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442729 // This can happen if someone uses window.open() to open an extension URL
2730 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562731 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322732 return;
2733 }
[email protected]8b8e7c92010-08-19 18:05:562734 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322735}
2736
2737void TabContents::ProcessExternalHostMessage(const std::string& message,
2738 const std::string& origin,
2739 const std::string& target) {
2740 if (delegate())
2741 delegate()->ForwardMessageToExternalHost(message, origin, target);
2742}
2743
[email protected]420ae012009-04-24 05:16:322744void TabContents::RunJavaScriptMessage(
2745 const std::wstring& message,
2746 const std::wstring& default_prompt,
2747 const GURL& frame_url,
2748 const int flags,
2749 IPC::Message* reply_msg,
2750 bool* did_suppress_message) {
2751 // Suppress javascript messages when requested and when inside a constrained
2752 // popup window (because that activates them and breaks them out of the
2753 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552754 // Also suppress messages when showing an interstitial. The interstitial is
2755 // shown over the previous page, we don't want the hidden page dialogs to
2756 // interfere with the interstitial.
2757 bool suppress_this_message = suppress_javascript_messages_ ||
2758 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322759 if (delegate())
2760 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312761 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322762
2763 *did_suppress_message = suppress_this_message;
2764
2765 if (!suppress_this_message) {
2766 base::TimeDelta time_since_last_message(
2767 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2768 bool show_suppress_checkbox = false;
2769 // Show a checkbox offering to suppress further messages if this message is
2770 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2771 if (time_since_last_message <
2772 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2773 show_suppress_checkbox = true;
2774
[email protected]d6ad7442010-09-05 19:06:522775 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2776 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322777 } else {
2778 // If we are suppressing messages, just reply as is if the user immediately
2779 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542780 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322781 }
2782}
2783
2784void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2785 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012786 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222787 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322788}
2789
2790void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2791 const std::string& json_arguments,
2792 IPC::Message* reply_msg) {
2793 if (delegate()) {
2794 HtmlDialogUIDelegate* dialog_delegate =
2795 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222796 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322797 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2798 }
2799}
2800
[email protected]c4aa86962010-11-24 23:08:042801void TabContents::PasswordFormsFound(
2802 const std::vector<webkit_glue::PasswordForm>& forms) {
2803 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2804 PasswordFormsFound(forms));
2805}
2806
2807void TabContents::PasswordFormsVisible(
2808 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2809 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2810 PasswordFormsVisible(visible_forms));
2811}
2812
[email protected]420ae012009-04-24 05:16:322813// Checks to see if we should generate a keyword based on the OSDD, and if
2814// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202815void TabContents::PageHasOSDD(
2816 RenderViewHost* render_view_host,
2817 int32 page_id,
2818 const GURL& url,
2819 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122820 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322821 DCHECK(url.is_valid());
2822 if (!IsActiveEntry(page_id))
2823 return;
[email protected]420ae012009-04-24 05:16:322824 if (!profile()->GetTemplateURLFetcher())
2825 return;
[email protected]420ae012009-04-24 05:16:322826 if (profile()->IsOffTheRecord())
2827 return;
2828
[email protected]2de7e002010-10-11 22:58:202829 TemplateURLFetcher::ProviderType provider_type;
2830 switch (msg_provider_type.type) {
2831 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2832 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2833 break;
2834
2835 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2836 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2837 break;
2838
2839 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2840 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2841 break;
2842
2843 default:
2844 NOTREACHED();
2845 return;
2846 }
2847
[email protected]420ae012009-04-24 05:16:322848 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2849 DCHECK(entry);
2850
2851 const NavigationEntry* base_entry = entry;
2852 if (IsFormSubmit(base_entry)) {
2853 // If the current page is a form submit, find the last page that was not
2854 // a form submit and use its url to generate the keyword from.
2855 int index = controller_.last_committed_entry_index() - 1;
2856 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2857 index--;
2858 if (index >= 0)
2859 base_entry = controller_.GetEntryAtIndex(index);
2860 else
2861 base_entry = NULL;
2862 }
2863
2864 // We want to use the user typed URL if available since that represents what
2865 // the user typed to get here, and fall back on the regular URL if not.
2866 if (!base_entry)
2867 return;
2868 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2869 base_entry->user_typed_url() : base_entry->url();
2870 if (!keyword_url.is_valid())
2871 return;
[email protected]2de7e002010-10-11 22:58:202872
[email protected]0b5b85c2010-10-11 23:00:122873 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2874 keyword_url,
2875 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532876
[email protected]0b5b85c2010-10-11 23:00:122877 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322878 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322879 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2880 keyword,
2881 url,
2882 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122883 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202884 provider_type);
[email protected]420ae012009-04-24 05:16:322885}
2886
[email protected]420ae012009-04-24 05:16:322887GURL TabContents::GetAlternateErrorPageURL() const {
2888 GURL url;
2889 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2890 if (profile()->IsOffTheRecord())
2891 return url;
2892
2893 PrefService* prefs = profile()->GetPrefs();
2894 DCHECK(prefs);
2895 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152896 url = google_util::AppendGoogleLocaleParam(
2897 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322898 url = google_util::AppendGoogleTLDParam(url);
2899 }
2900 return url;
2901}
2902
2903WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062904 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552905 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082906 WebPreferences web_prefs =
2907 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
2908
[email protected]9beff752010-09-22 19:35:432909 // Force accelerated compositing and 2d canvas off for chrome: and
2910 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432911 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2912 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082913 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432914 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082915 }
2916
[email protected]39553442010-09-09 00:01:552917#if defined(OS_MACOSX)
2918 // Disable accelerated compositing if IOSurface's are not supported,
2919 // as is the case in 10.5.
2920 if (!IOSurfaceSupport::Initialize())
2921 web_prefs.accelerated_compositing_enabled = false;
2922#endif
2923
[email protected]447021c2010-09-08 21:29:082924 return web_prefs;
[email protected]420ae012009-04-24 05:16:322925}
2926
[email protected]fa1cf0b82010-01-15 21:49:442927void TabContents::OnIgnoredUIEvent() {
2928 if (constrained_window_count()) {
2929 ConstrainedWindow* window = *constrained_window_begin();
2930 window->FocusConstrainedWindow();
2931 }
2932}
2933
[email protected]420ae012009-04-24 05:16:322934void TabContents::OnJSOutOfMemory() {
2935 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582936 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2937 NULL, true));
[email protected]420ae012009-04-24 05:16:322938}
2939
[email protected]420ae012009-04-24 05:16:322940void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2941 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342942 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322943 // delivered to a pending RenderViewHost. We must first run the onunload
2944 // handler of the old RenderViewHost before we can allow it to proceed.
2945 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2946 new_request_id);
2947}
2948
[email protected]420ae012009-04-24 05:16:322949void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2950 bool is_during_unload) {
2951 if (is_during_unload) {
2952 // Hang occurred while firing the beforeunload/unload handler.
2953 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112954 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322955
2956 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2957 return;
2958
2959 // If the tab hangs in the beforeunload/unload handler there's really
2960 // nothing we can do to recover. Pretend the unload listeners have
2961 // all fired and close the tab. If the hang is in the beforeunload handler
2962 // then the user will not have the option of cancelling the close.
2963 Close(rvh);
2964 return;
2965 }
2966
2967 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002968 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322969}
2970
2971void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002972 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322973}
2974
2975void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562976 net::LoadState load_state,
2977 uint64 upload_position,
2978 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322979 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562980 upload_position_ = upload_position;
2981 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292982 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192983 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292984 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532985 load_state_host_ =
2986 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322987 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2988 SetNotWaitingForResponse();
2989 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502990 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322991}
2992
[email protected]1ee614862009-07-06 20:29:182993bool TabContents::IsExternalTabContainer() const {
2994 if (!delegate())
2995 return false;
2996
2997 return delegate()->IsExternalTabContainer();
2998}
2999
[email protected]1ee614862009-07-06 20:29:183000void TabContents::DidInsertCSS() {
3001 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:323002}
3003
[email protected]130efb02009-09-18 18:54:353004void TabContents::FocusedNodeChanged() {
3005 NotificationService::current()->Notify(
3006 NotificationType::FOCUS_CHANGED_IN_PAGE,
3007 Source<RenderViewHost>(render_view_host()),
3008 NotificationService::NoDetails());
3009}
3010
[email protected]b75b8292010-10-01 07:28:253011void TabContents::UpdateZoomLimits(int minimum_percent,
3012 int maximum_percent,
3013 bool remember) {
3014 minimum_zoom_percent_ = minimum_percent;
3015 maximum_zoom_percent_ = maximum_percent;
3016 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383017}
3018
[email protected]9e823662010-10-13 23:36:003019void TabContents::UpdateContentRestrictions(int restrictions) {
3020 content_restrictions_ = restrictions;
3021 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:323022}
3023
[email protected]420ae012009-04-24 05:16:323024void TabContents::BeforeUnloadFiredFromRenderManager(
3025 bool proceed,
3026 bool* proceed_to_fire_unload) {
3027 if (delegate())
3028 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3029}
3030
[email protected]3a3d47472010-07-15 21:03:543031void TabContents::DidStartLoadingFromRenderManager(
3032 RenderViewHost* render_view_host) {
3033 DidStartLoading();
3034}
3035
3036void TabContents::RenderViewGoneFromRenderManager(
3037 RenderViewHost* render_view_host) {
3038 RenderViewGone(render_view_host);
3039}
3040
[email protected]420ae012009-04-24 05:16:323041void TabContents::UpdateRenderViewSizeForRenderManager() {
3042 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263043 gfx::Size size = view_->GetContainerSize();
3044 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3045 // here during container initialization and normal window size will be set
3046 // later. In case of tab duplication this resizing to 0x0 prevents setting
3047 // normal size later so just ignore it.
3048 if (!size.IsEmpty())
3049 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323050}
3051
[email protected]3a3d47472010-07-15 21:03:543052void TabContents::NotifySwappedFromRenderManager() {
3053 NotifySwapped();
3054}
3055
3056NavigationController& TabContents::GetControllerForRenderManager() {
3057 return controller();
3058}
3059
[email protected]420ae012009-04-24 05:16:323060DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223061 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323062}
3063
3064NavigationEntry*
3065TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3066 return controller_.GetLastCommittedEntry();
3067}
3068
3069bool TabContents::CreateRenderViewForRenderManager(
3070 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323071 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523072
[email protected]674b3822010-08-04 04:02:513073 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323074 return false;
3075
3076 // Now that the RenderView has been created, we need to tell it its size.
3077 rwh_view->SetSize(view_->GetContainerSize());
3078
3079 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3080 render_view_host);
3081 return true;
3082}
3083
3084void TabContents::Observe(NotificationType type,
3085 const NotificationSource& source,
3086 const NotificationDetails& details) {
3087 switch (type.value) {
3088 case NotificationType::BOOKMARK_MODEL_LOADED:
3089 // BookmarkModel finished loading, fall through to update starred state.
3090 case NotificationType::URLS_STARRED: {
3091 // Somewhere, a URL has been starred.
3092 // Ignore notifications for profiles other than our current one.
3093 Profile* source_profile = Source<Profile>(source).ptr();
3094 if (!source_profile || !source_profile->IsSameProfile(profile()))
3095 return;
3096
3097 UpdateStarredStateForCurrentURL();
3098 break;
3099 }
3100 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513101 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323102 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3103 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3104 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533105 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3106 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323107 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173108 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3109 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323110 } else {
3111 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3112 }
3113 break;
3114 }
3115 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3116 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3117 break;
3118
3119 case NotificationType::NAV_ENTRY_COMMITTED: {
3120 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3121
3122 NavigationController::LoadCommittedDetails& committed_details =
3123 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3124 ExpireInfoBars(committed_details);
3125 break;
3126 }
3127
[email protected]d3ba77272009-09-03 00:06:093128#if defined(OS_LINUX)
3129 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543130 renderer_preferences_util::UpdateFromSystemSettings(
3131 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093132 render_view_host()->SyncRendererPrefs();
3133 break;
3134 }
3135#endif
3136
[email protected]6c32ce72010-03-08 05:18:063137 case NotificationType::USER_STYLE_SHEET_UPDATED:
3138 UpdateWebPreferences();
3139 break;
3140
[email protected]79580c62010-02-02 02:36:253141 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:453142 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:253143 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493144 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293145 if (entry)
[email protected]da0c8e92010-02-09 23:25:493146 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293147 if (settings_details.ptr()->update_all() ||
3148 settings_details.ptr()->pattern().Matches(entry_url)) {
3149 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233150 profile()->GetHostContentSettingsMap()->
3151 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253152 }
3153 break;
3154 }
3155
[email protected]e5adff72010-06-14 18:13:063156 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573157 break;
[email protected]a888b29e62010-04-01 13:38:573158
3159 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063160 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573161 break;
[email protected]a888b29e62010-04-01 13:38:573162
[email protected]88152052010-10-01 04:05:183163 case NotificationType::GOOGLE_URL_UPDATED:
3164 UpdateAlternateErrorPageURL();
3165 break;
3166
[email protected]420ae012009-04-24 05:16:323167 default:
3168 NOTREACHED();
3169 }
3170}
[email protected]aacd7cc2009-09-02 14:51:103171
[email protected]9adb9692010-10-29 23:14:023172void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083173 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433174
[email protected]a888b29e62010-04-01 13:38:573175 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083176 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3177 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573178 extension,
[email protected]807871f2010-09-16 01:04:483179 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3180 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573181 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3182 Extension::EXTENSION_ICON_SMALLISH),
3183 ImageLoadingTracker::CACHE);
3184 } else {
[email protected]98aa0b52010-05-06 17:03:083185 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573186 }
3187}
3188
[email protected]9adb9692010-10-29 23:14:023189const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:573190 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3191 if (!extensions_service)
3192 return NULL;
3193
[email protected]9adb9692010-10-29 23:14:023194 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573195 return extension ?
3196 extension : extensions_service->GetExtensionByWebExtent(url);
3197}
3198
[email protected]a888b29e62010-04-01 13:38:573199void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3200 int index) {
3201 if (image) {
[email protected]98aa0b52010-05-06 17:03:083202 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573203 NotifyNavigationStateChanged(INVALIDATE_TAB);
3204 }
3205}
3206
[email protected]beb440c2009-11-06 04:08:543207gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3208 return view_->GetTopLevelNativeWindow();
3209}
3210
3211void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3212 bool success,
3213 const std::wstring& prompt) {
3214 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3215 if (is_showing_before_unload_dialog_ && !success) {
3216 // If a beforeunload dialog is canceled, we need to stop the throbber from
3217 // spinning, since we forced it to start spinning in Navigate.
3218 DidStopLoading();
3219
3220 tab_close_start_time_ = base::TimeTicks();
3221 }
3222 is_showing_before_unload_dialog_ = false;
3223 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3224}
3225
3226void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3227 set_suppress_javascript_messages(suppress_message_boxes);
3228}
3229
[email protected]3a3d47472010-07-15 21:03:543230TabContents* TabContents::AsTabContents() {
3231 return this;
3232}
3233
3234ExtensionHost* TabContents::AsExtensionHost() {
3235 return NULL;
3236}
3237
[email protected]41fc0322009-09-04 22:23:403238void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103239 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3240}
[email protected]f45d2a72010-03-08 23:28:353241
3242void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3243 app_icon_ = app_icon;
3244 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3245}