blob: 26b77ce1255e1faf5e9013cf9f5ab3a0b5b4f355 [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]96d185d2009-04-24 03:28:5432#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1433#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3234#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5435#include "chrome/browser/dom_ui/dom_ui.h"
36#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0237#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3238#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0139#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4940#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0841#include "chrome/browser/extensions/extensions_service.h"
[email protected]ec0b6c42010-08-26 03:16:5842#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4243#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2544#include "chrome/browser/host_zoom_map.h"
[email protected]0189bc722009-08-28 21:56:4845#include "chrome/browser/favicon_service.h"
[email protected]ba70d082010-09-10 16:54:4946#include "chrome/browser/file_select_helper.h"
[email protected]e5d2f7132010-04-09 18:13:5347#include "chrome/browser/find_bar_state.h"
[email protected]f7578f52010-08-30 22:22:4948#include "chrome/browser/google/google_util.h"
[email protected]79580c62010-02-02 02:36:2549#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2650#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0751#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]12f74a92010-02-05 22:32:1452#include "chrome/browser/message_box_handler.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]fdd61c62009-04-22 19:22:5758#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2459#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5760#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0261#include "chrome/browser/prefs/pref_service.h"
[email protected]dbeebd52010-11-16 20:34:1662#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0963#include "chrome/browser/printing/print_view_manager.h"
[email protected]ce560f82009-06-03 09:39:4464#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0765#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1666#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5467#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3768#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0769#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5470#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3271#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1172#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1673#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1274#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1675#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1776#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1777#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5478#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1679#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4380#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1681#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4982#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5783#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0284#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1685#include "chrome/browser/translate/page_translated_details.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 password_manager_(),
334 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06335 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22336 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34337 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29338 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34339 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34340 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57341 current_load_start_(),
342 load_state_(net::LOAD_STATE_IDLE),
343 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56344 upload_size_(0),
345 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57346 received_page_title_(false),
347 is_starred_(false),
348 contents_mime_type_(),
349 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40350 blocked_contents_(NULL),
351 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49352 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47353 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57354 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57355 find_ui_active_(false),
356 find_op_aborted_(false),
357 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12358 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12359 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08360 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57361 capturing_contents_(false),
362 is_being_destroyed_(false),
363 notify_disconnection_(false),
364 history_requests_(),
365#if defined(OS_WIN)
366 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
367#endif
368 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44369 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01370 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54371 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54372 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16373 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38374 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25375 minimum_zoom_percent_(
376 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
377 maximum_zoom_percent_(
378 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00379 temporary_zoom_settings_(false),
380 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54381 renderer_preferences_util::UpdateFromSystemSettings(
382 &renderer_preferences_, profile);
383
[email protected]9fb83e82010-07-02 18:24:55384 content_settings_delegate_.reset(
385 new TabSpecificContentSettings(this, profile));
386
[email protected]16779842009-07-08 23:45:29387#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02388 // Make sure the thumbnailer is started before starting the render manager.
389 // The thumbnailer will want to listen for RVH creations, one of which will
390 // happen in RVHManager::Init.
391 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
392 if (generator)
393 generator->StartThumbnailing();
394#endif
395
[email protected]12636df2009-09-28 22:32:21396 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32397
[email protected]34ac70502009-09-25 17:07:23398 // We have the initial size of the view be based on the size of the passed in
399 // tab contents (normally a tab from the same window).
400 view_->CreateView(base_tab_contents ?
401 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32402
403 // Register for notifications about all interested prefs change.
404 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28405 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32406 if (prefs) {
407 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28408 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32409 }
410
411 // Register for notifications about URL starredness changing on any profile.
412 registrar_.Add(this, NotificationType::URLS_STARRED,
413 NotificationService::AllSources());
414 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
415 NotificationService::AllSources());
416 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
417 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09418#if defined(OS_LINUX)
419 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
420 NotificationService::AllSources());
421#endif
[email protected]420ae012009-04-24 05:16:32422
[email protected]6c32ce72010-03-08 05:18:06423 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
424 NotificationService::AllSources());
425
[email protected]79580c62010-02-02 02:36:25426 // Register for notifications about content setting changes.
427 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
428 NotificationService::AllSources());
429
[email protected]a888b29e62010-04-01 13:38:57430 // Listen for extension changes so we can update extension_for_current_page_.
431 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
432 NotificationService::AllSources());
433 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
434 NotificationService::AllSources());
435 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
436 NotificationService::AllSources());
437
[email protected]88152052010-10-01 04:05:18438 // Listen for Google URL changes
439 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
440 NotificationService::AllSources());
441
[email protected]c8865482009-07-23 20:40:10442 // Set-up the showing of the omnibox search infobar if applicable.
443 if (OmniboxSearchHint::IsEnabled(profile))
444 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35445}
initial.commit09911bf2008-07-26 23:55:29446
447TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32448 is_being_destroyed_ = true;
449
[email protected]bfe4c1582009-10-02 18:11:09450 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32451 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28452 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32453
[email protected]420ae012009-04-24 05:16:32454 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00455 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32456
[email protected]420ae012009-04-24 05:16:32457 // First cleanly close all child windows.
458 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
459 // some of these to close. CloseWindows is async, so it might get called
460 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49461 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32462
[email protected]c65e2f152010-10-14 15:30:40463 // Close all blocked contents.
464 if (blocked_contents_)
465 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13466
[email protected]420ae012009-04-24 05:16:32467 // Notify any observer that have a reference on this tab contents.
468 NotificationService::current()->Notify(
469 NotificationType::TAB_CONTENTS_DESTROYED,
470 Source<TabContents>(this),
471 NotificationService::NoDetails());
472
[email protected]1e5e74f2009-05-27 20:55:12473 // Notify any lasting InfobarDelegates that have not yet been removed that
474 // whatever infobar they were handling in this TabContents has closed,
475 // because the TabContents is going away entirely.
476 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
477 // notification may trigger infobars calls that access their delegate. (and
478 // some implementations of InfoBarDelegate do delete themselves on
479 // InfoBarClosed()).
480 for (int i = 0; i < infobar_delegate_count(); ++i) {
481 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
482 delegate->InfoBarClosed();
483 }
484 infobar_delegates_.clear();
485
[email protected]420ae012009-04-24 05:16:32486 // TODO(brettw) this should be moved to the view.
487#if defined(OS_WIN)
488 // If we still have a window handle, destroy it. GetNativeView can return
489 // NULL if this contents was part of a window that closed.
490 if (GetNativeView())
491 ::DestroyWindow(GetNativeView());
492#endif
[email protected]7ab1e7d62009-10-14 23:32:01493
494 // OnCloseStarted isn't called in unit tests.
495 if (!tab_close_start_time_.is_null()) {
496 UMA_HISTOGRAM_TIMES("Tab.Close",
497 base::TimeTicks::Now() - tab_close_start_time_);
498 }
initial.commit09911bf2008-07-26 23:55:29499}
500
[email protected]d5f942ba2008-09-26 19:30:34501// static
502void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32503 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
504
505 WebPreferences pref_defaults;
506 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
507 pref_defaults.javascript_enabled);
508 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
509 pref_defaults.web_security_enabled);
510 prefs->RegisterBooleanPref(
511 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
512 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
513 pref_defaults.loads_images_automatically);
514 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
515 pref_defaults.plugins_enabled);
516 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
517 pref_defaults.dom_paste_enabled);
518 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
519 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14520 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32521 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
522 pref_defaults.text_areas_are_resizable);
523 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
524 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36525 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
526 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32527
528 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
529 IDS_ACCEPT_LANGUAGES);
530 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
531 IDS_DEFAULT_ENCODING);
532 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
533 IDS_STANDARD_FONT_IS_SERIF);
534 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
535 IDS_FIXED_FONT_FAMILY);
536 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
537 IDS_SERIF_FONT_FAMILY);
538 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
539 IDS_SANS_SERIF_FONT_FAMILY);
540 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
541 IDS_CURSIVE_FONT_FAMILY);
542 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
543 IDS_FANTASY_FONT_FAMILY);
544 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
545 IDS_DEFAULT_FONT_SIZE);
546 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
547 IDS_DEFAULT_FIXED_FONT_SIZE);
548 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
549 IDS_MINIMUM_FONT_SIZE);
550 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
551 IDS_MINIMUM_LOGICAL_FONT_SIZE);
552 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
553 IDS_USES_UNIVERSAL_DETECTOR);
554 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
555 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29556}
557
[email protected]13367f72009-07-08 16:39:02558// Returns true if contains content rendered by an extension.
559bool TabContents::HostsExtension() const {
560 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34561}
562
[email protected]cf28ec52010-04-09 22:56:34563AutoFillManager* TabContents::GetAutoFillManager() {
564 if (autofill_manager_.get() == NULL)
565 autofill_manager_.reset(new AutoFillManager(this));
566 return autofill_manager_.get();
567}
568
[email protected]6e95706d2009-04-23 22:55:01569PasswordManager* TabContents::GetPasswordManager() {
570 if (password_manager_.get() == NULL)
571 password_manager_.reset(new PasswordManager(this));
572 return password_manager_.get();
573}
574
575PluginInstaller* TabContents::GetPluginInstaller() {
576 if (plugin_installer_.get() == NULL)
577 plugin_installer_.reset(new PluginInstaller(this));
578 return plugin_installer_.get();
579}
580
[email protected]1f18184a2010-07-21 19:34:49581TabContentsSSLHelper* TabContents::GetSSLHelper() {
582 if (ssl_helper_.get() == NULL)
583 ssl_helper_.reset(new TabContentsSSLHelper(this));
584 return ssl_helper_.get();
585}
586
[email protected]8cb5d5b2010-02-09 11:36:16587RenderProcessHost* TabContents::GetRenderProcessHost() const {
588 return render_manager_.current_host()->process();
589}
590
[email protected]9adb9692010-10-29 23:14:02591void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46592 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08593 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10594
[email protected]98aa0b52010-05-06 17:03:08595 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57596
[email protected]fca656c2010-02-10 20:30:10597 NotificationService::current()->Notify(
598 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
599 Source<TabContents>(this),
600 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49601}
602
[email protected]98aa0b52010-05-06 17:03:08603void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
604 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40605 return;
606
607 ExtensionsService* extension_service = profile()->GetExtensionsService();
608 if (extension_service && extension_service->is_ready()) {
[email protected]9adb9692010-10-29 23:14:02609 const Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08610 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40611 if (extension)
[email protected]98aa0b52010-05-06 17:03:08612 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40613 }
614}
615
[email protected]98aa0b52010-05-06 17:03:08616SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08617 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51618 return NULL;
619
[email protected]98aa0b52010-05-06 17:03:08620 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51621}
622
[email protected]d5f942ba2008-09-26 19:30:34623const GURL& TabContents::GetURL() const {
624 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57625 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54626 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34627}
628
[email protected]96d185d2009-04-24 03:28:54629const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55630 // Transient entries take precedence. They are used for interstitial pages
631 // that are shown on top of existing pages.
632 NavigationEntry* entry = controller_.GetTransientEntry();
633 if (entry)
634 return entry->GetTitleForDisplay(&controller_);
635
[email protected]96d185d2009-04-24 03:28:54636 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
637 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
638 if (our_dom_ui) {
639 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55640 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54641 if (!(entry && entry->IsViewSourceMode())) {
642 // Give the DOM UI the chance to override our title.
643 const string16& title = our_dom_ui->overridden_title();
644 if (!title.empty())
645 return title;
646 }
647 }
648
649 // We use the title for the last committed entry rather than a pending
650 // navigation entry. For example, when the user types in a URL, we want to
651 // keep the old page's title until the new load has committed and we get a new
652 // title.
[email protected]96d185d2009-04-24 03:28:54653 entry = controller_.GetLastCommittedEntry();
654 if (entry)
655 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54656 return EmptyString16();
657}
658
[email protected]bbbc1ef2010-02-12 18:03:41659// static
660string16 TabContents::GetDefaultTitle() {
661 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
662}
663
[email protected]d5f942ba2008-09-26 19:30:34664int32 TabContents::GetMaxPageID() {
665 if (GetSiteInstance())
666 return GetSiteInstance()->max_page_id();
667 else
668 return max_page_id_;
669}
670
671void TabContents::UpdateMaxPageID(int32 page_id) {
672 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34673 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34674 // testing.
675 if (GetSiteInstance())
676 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16677 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34678}
679
[email protected]96d185d2009-04-24 03:28:54680SiteInstance* TabContents::GetSiteInstance() const {
681 return render_manager_.current_host()->site_instance();
682}
683
[email protected]96d185d2009-04-24 03:28:54684bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15685 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54686 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15687 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01688 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54689 return true;
[email protected]8ab24cc2009-11-13 20:56:15690 }
[email protected]83e3895b2009-06-11 00:07:16691
[email protected]96d185d2009-04-24 03:28:54692 DOMUI* dom_ui = GetDOMUIForCurrentState();
693 if (dom_ui)
694 return !dom_ui->should_hide_url();
695 return true;
696}
697
[email protected]d5f942ba2008-09-26 19:30:34698SkBitmap TabContents::GetFavIcon() const {
699 // Like GetTitle(), we also want to use the favicon for the last committed
700 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57701 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47702 if (entry)
703 return entry->favicon().bitmap();
704
[email protected]ce3fa3c2009-04-20 19:55:57705 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34706 if (entry)
707 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34708 return SkBitmap();
709}
710
[email protected]0b303cc2009-09-28 22:35:15711bool TabContents::FavIconIsValid() const {
712 NavigationEntry* entry = controller_.GetTransientEntry();
713 if (entry)
714 return entry->favicon().is_valid();
715
716 entry = controller_.GetLastCommittedEntry();
717 if (entry)
718 return entry->favicon().is_valid();
719
720 return false;
721}
722
[email protected]96d185d2009-04-24 03:28:54723bool TabContents::ShouldDisplayFavIcon() {
724 // Always display a throbber during pending loads.
725 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
726 return true;
727
728 DOMUI* dom_ui = GetDOMUIForCurrentState();
729 if (dom_ui)
730 return !dom_ui->hide_favicon();
731 return true;
732}
733
[email protected]96d185d2009-04-24 03:28:54734std::wstring TabContents::GetStatusText() const {
735 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
736 return std::wstring();
737
738 switch (load_state_) {
739 case net::LOAD_STATE_WAITING_FOR_CACHE:
740 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04741 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
742 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54743 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
744 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
745 case net::LOAD_STATE_RESOLVING_HOST:
746 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
747 case net::LOAD_STATE_CONNECTING:
748 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06749 case net::LOAD_STATE_SSL_HANDSHAKE:
750 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54751 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56752 if (upload_size_)
753 return l10n_util::GetStringF(
754 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
755 static_cast<int>((100 * upload_position_) / upload_size_));
756 else
757 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54758 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
759 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
760 load_state_host_);
761 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
762 case net::LOAD_STATE_IDLE:
763 case net::LOAD_STATE_READING_RESPONSE:
764 break;
765 }
766
767 return std::wstring();
768}
769
[email protected]d5f942ba2008-09-26 19:30:34770void TabContents::SetIsCrashed(bool state) {
771 if (state == is_crashed_)
772 return;
773
774 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50775 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34776}
777
[email protected]744ef172009-10-16 21:53:46778void TabContents::PageActionStateChanged() {
779 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00780}
[email protected]ce5c4502009-05-06 16:46:11781
[email protected]d5f942ba2008-09-26 19:30:34782void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
783 if (delegate_)
784 delegate_->NavigationStateChanged(this, changed_flags);
785}
786
[email protected]96d185d2009-04-24 03:28:54787void TabContents::DidBecomeSelected() {
788 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16789 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
790 if (rwhv) {
791 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43792#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16793 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43794#endif
795 }
[email protected]96d185d2009-04-24 03:28:54796
[email protected]8cb5d5b2010-02-09 11:36:16797 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54798}
799
800void TabContents::WasHidden() {
801 if (!capturing_contents()) {
802 // |render_view_host()| can be NULL if the user middle clicks a link to open
803 // a tab in then background, then closes the tab before selecting it. This
804 // is because closing the tab calls TabContents::Destroy(), which removes
805 // the |render_view_host()|; then when we actually destroy the window,
806 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16807 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
808 if (rwhv)
809 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54810 }
811
812 NotificationService::current()->Notify(
813 NotificationType::TAB_CONTENTS_HIDDEN,
814 Source<TabContents>(this),
815 NotificationService::NoDetails());
816}
817
[email protected]d5f942ba2008-09-26 19:30:34818void TabContents::Activate() {
819 if (delegate_)
820 delegate_->ActivateContents(this);
821}
822
[email protected]ea42e7782010-08-23 23:58:12823void TabContents::Deactivate() {
824 if (delegate_)
825 delegate_->DeactivateContents(this);
826}
827
[email protected]96d185d2009-04-24 03:28:54828void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16829 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
830 if (rwhv)
831 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54832}
833
834void TabContents::HideContents() {
835 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
836 // our superclass HideContents(), because some callers want to be very picky
837 // about the order in which these get called. In addition to making the code
838 // here practically impossible to understand, this also means we end up
839 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34840 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54841 WasHidden();
842}
843
[email protected]c0588052008-10-27 23:01:50844void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34845 WindowOpenDisposition disposition,
846 PageTransition::Type transition) {
847 if (delegate_)
[email protected]c0588052008-10-27 23:01:50848 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34849}
850
[email protected]1ccb3568d2010-02-19 10:51:16851bool TabContents::NavigateToPendingEntry(
852 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54853 return NavigateToEntry(*controller_.pending_entry(), reload_type);
854}
[email protected]96d185d2009-04-24 03:28:54855
[email protected]876bc832010-09-07 16:29:54856bool TabContents::NavigateToEntry(
857 const NavigationEntry& entry,
858 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54859 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
860 if (!dest_render_view_host)
861 return false; // Unable to create the desired render view host.
862
[email protected]770dd8b2010-05-24 18:11:39863 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
864 dest_render_view_host->EnablePreferredSizeChangedMode(
865 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
866 }
[email protected]9fb325e2010-05-06 18:23:24867
[email protected]05fdd492010-11-15 17:52:07868 // For security, we should never send non-DOM-UI URLs to a DOM UI renderer.
869 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58870 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40871 bool is_allowed_in_dom_ui_renderer =
[email protected]05fdd492010-11-15 17:52:07872 DOMUIFactory::IsURLAcceptableForDOMUI(profile(), entry.url());
[email protected]54ec6472010-04-09 19:39:58873 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40874 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58875
[email protected]96d185d2009-04-24 03:28:54876 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12877 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32878 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00879 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
880 dest_render_view_host,
881 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32882 }
[email protected]96d185d2009-04-24 03:28:54883
884 // Used for page load time metrics.
885 current_load_start_ = base::TimeTicks::Now();
886
887 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34888 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54889 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34890 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54891
892 if (entry.page_id() == -1) {
893 // HACK!! This code suppresses javascript: URLs from being added to
894 // session history, which is what we want to do for javascript: URLs that
895 // do not generate content. What we really need is a message from the
896 // renderer telling us that a new page was not created. The same message
897 // could be used for mailto: URLs and the like.
898 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
899 return false;
900 }
901
902 // Clear any provisional password saves - this stops password infobars
903 // showing up on pages the user navigates to while the right page is
904 // loading.
905 GetPasswordManager()->ClearProvisionalSave();
906
[email protected]1ccb3568d2010-02-19 10:51:16907 if (reload_type != NavigationController::NO_RELOAD &&
908 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48909 FaviconService* favicon_service =
910 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
911 if (favicon_service)
912 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54913 }
914
[email protected]d5f942ba2008-09-26 19:30:34915 return true;
916}
917
[email protected]96d185d2009-04-24 03:28:54918void TabContents::Stop() {
919 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09920 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54921}
922
[email protected]96d185d2009-04-24 03:28:54923void TabContents::DisassociateFromPopupCount() {
924 render_view_host()->DisassociateFromPopupCount();
925}
926
927TabContents* TabContents::Clone() {
928 // We create a new SiteInstance so that the new tab won't share processes
929 // with the old one. This can be changed in the future if we need it to share
930 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32931 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54932 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07933 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54934 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08935 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08936 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54937 return tc;
938}
939
[email protected]4d677202009-07-19 07:37:12940void TabContents::ShowPageInfo(const GURL& url,
941 const NavigationEntry::SSLStatus& ssl,
942 bool show_history) {
943 if (!delegate_)
944 return;
945
[email protected]bb678332009-07-21 00:15:50946 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12947}
948
initial.commit09911bf2008-07-26 23:55:29949ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28950 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29951 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28952 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29953 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44954
955 if (child_windows_.size() == 1) {
956 window->ShowConstrainedWindow();
957 BlockTabContent(true);
958 }
959
initial.commit09911bf2008-07-26 23:55:29960 return window;
961}
962
[email protected]fa1cf0b82010-01-15 21:49:44963void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55964 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
965 if (rwhv)
966 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44967 render_view_host()->set_ignore_input_events(blocked);
968 if (delegate_)
969 delegate_->SetTabContentBlocked(this, blocked);
970}
971
initial.commit09911bf2008-07-26 23:55:29972void TabContents::AddNewContents(TabContents* new_contents,
973 WindowOpenDisposition disposition,
974 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29975 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40976 if (all_contents_blocked_) {
977 if (!blocked_contents_)
978 blocked_contents_ = new BlockedContentContainer(this);
979 blocked_contents_->AddTabContents(
980 new_contents, disposition, initial_pos, user_gesture);
981 return;
982 }
983
initial.commit09911bf2008-07-26 23:55:29984 if (!delegate_)
985 return;
986
[email protected]35f7d212009-04-29 21:19:27987 if ((disposition == NEW_POPUP) && !user_gesture &&
988 !CommandLine::ForCurrentProcess()->HasSwitch(
989 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22990 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31991 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29992 delegate_->GetConstrainingContents(this)->AddPopup(
993 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31994 } else {
[email protected]0aa55312008-10-17 21:53:08995 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29996 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
997 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49998 NotificationService::current()->Notify(
999 NotificationType::TAB_ADDED,
1000 Source<TabContentsDelegate>(delegate_),
1001 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291002 }
initial.commit09911bf2008-07-26 23:55:291003
[email protected]8cc8d492010-02-02 10:40:491004 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401005 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291006}
1007
[email protected]bcd9dc42010-01-23 16:38:181008bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201009 bool is_js_code, const std::string& code_string,
1010 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511011 RenderViewHost* host = render_view_host();
1012 if (!host)
1013 return false;
1014
1015 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171016 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511017 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351018}
1019
[email protected]96d185d2009-04-24 03:28:541020void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491021 if (is_being_destroyed_)
1022 return;
[email protected]9fb83e82010-07-02 18:24:551023 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491024 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401025 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541026}
1027
[email protected]5c9e97a2009-09-09 23:48:301028gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541029 return view_->GetContentNativeView();
1030}
1031
1032gfx::NativeView TabContents::GetNativeView() const {
1033 return view_->GetNativeView();
1034}
1035
1036void TabContents::GetContainerBounds(gfx::Rect *out) const {
1037 view_->GetContainerBounds(out);
1038}
1039
1040void TabContents::Focus() {
1041 view_->Focus();
1042}
1043
[email protected]90daadb42009-06-08 21:27:281044void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541045 if (showing_interstitial_page()) {
1046 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1047 return;
1048 }
[email protected]96d185d2009-04-24 03:28:541049 render_view_host()->SetInitialFocus(reverse);
1050}
1051
1052bool TabContents::FocusLocationBarByDefault() {
1053 DOMUI* dom_ui = GetDOMUIForCurrentState();
1054 if (dom_ui)
1055 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431056 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251057 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431058 return true;
[email protected]96d185d2009-04-24 03:28:541059 return false;
1060}
1061
[email protected]a26dc362010-04-23 01:48:581062void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381063 if (delegate())
[email protected]a26dc362010-04-23 01:48:581064 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381065}
1066
[email protected]616ed5a2008-11-21 22:27:241067void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321068 if (delegate_ && !delegate_->infobars_enabled()) {
1069 delegate->InfoBarClosed();
1070 return;
1071 }
1072
[email protected]616ed5a2008-11-21 22:27:241073 // Look through the existing InfoBarDelegates we have for a match. If we've
1074 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051075 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451076 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1077 // Tell the new infobar to close so that it can clean itself up.
1078 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241079 return;
[email protected]6d27a7b2009-12-18 23:25:451080 }
[email protected]616ed5a2008-11-21 22:27:241081 }
1082
1083 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561084 NotificationService::current()->Notify(
1085 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1086 Source<TabContents>(this),
1087 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241088
1089 // Add ourselves as an observer for navigations the first time a delegate is
1090 // added. We use this notification to expire InfoBars that need to expire on
1091 // page transitions.
1092 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561093 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571094 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241095 }
1096}
1097
1098void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321099 if (delegate_ && !delegate_->infobars_enabled()) {
1100 return;
1101 }
1102
[email protected]616ed5a2008-11-21 22:27:241103 std::vector<InfoBarDelegate*>::iterator it =
1104 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1105 if (it != infobar_delegates_.end()) {
1106 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561107 NotificationService::current()->Notify(
1108 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1109 Source<TabContents>(this),
1110 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241111
[email protected]cdadf6f2010-08-20 16:36:081112 // Just to be safe, make sure the delegate was not removed by an observer.
1113 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1114 if (it != infobar_delegates_.end()) {
1115 infobar_delegates_.erase(it);
1116 // Remove ourselves as an observer if we are tracking no more InfoBars.
1117 if (infobar_delegates_.empty()) {
1118 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1119 Source<NavigationController>(&controller_));
1120 }
1121 } else {
1122 // If you hit this NOTREACHED, please comment in bug
1123 // http://crbug.com/50428 how you got there.
1124 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031125 }
[email protected]616ed5a2008-11-21 22:27:241126 }
1127}
[email protected]3edd9522009-03-04 22:19:411128
[email protected]f81821c2009-08-07 01:29:471129void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1130 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321131 if (delegate_ && !delegate_->infobars_enabled()) {
1132 new_delegate->InfoBarClosed();
1133 return;
1134 }
1135
[email protected]f81821c2009-08-07 01:29:471136 std::vector<InfoBarDelegate*>::iterator it =
1137 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1138 DCHECK(it != infobar_delegates_.end());
1139
1140 // Notify the container about the change of plans.
1141 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1142 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1143 old_delegate, new_delegate));
1144 NotificationService::current()->Notify(
1145 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1146 Source<TabContents>(this),
1147 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1148
[email protected]cdadf6f2010-08-20 16:36:081149 // Just to be safe, make sure the delegate was not removed by an observer.
1150 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1151 if (it != infobar_delegates_.end()) {
1152 // Remove the old one.
1153 infobar_delegates_.erase(it);
1154 } else {
1155 // If you hit this NOTREACHED, please comment in bug
1156 // http://crbug.com/50428 how you got there.
1157 NOTREACHED();
1158 }
[email protected]f81821c2009-08-07 01:29:471159
1160 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081161 DCHECK(find(infobar_delegates_.begin(),
1162 infobar_delegates_.end(), new_delegate) ==
1163 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471164 infobar_delegates_.push_back(new_delegate);
1165}
1166
[email protected]20ede072009-10-06 00:28:351167bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271168 if (showing_interstitial_page())
1169 return false;
1170
[email protected]c8f74942010-09-03 10:04:141171 // Do not show bookmarks bar if bookmarks aren't enabled.
1172 if (!browser_defaults::bookmarks_enabled)
1173 return false;
1174
[email protected]96d185d2009-04-24 03:28:541175 // See GetDOMUIForCurrentState() comment for more info. This case is very
1176 // similar, but for non-first loads, we want to use the committed entry. This
1177 // is so the bookmarks bar disappears at the same time the page does.
1178 if (controller_.GetLastCommittedEntry()) {
1179 // Not the first load, always use the committed DOM UI.
[email protected]d6219912010-11-17 19:47:371180 return (render_manager_.dom_ui() == NULL) ?
1181 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541182 }
1183
1184 // When it's the first load, we know either the pending one or the committed
1185 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1186 // of them will be valid, so we can just check both.
1187 if (render_manager_.pending_dom_ui())
1188 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
[email protected]d6219912010-11-17 19:47:371189 return (render_manager_.dom_ui() == NULL) ?
1190 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541191}
1192
[email protected]3edd9522009-03-04 22:19:411193void TabContents::ToolbarSizeChanged(bool is_animating) {
1194 TabContentsDelegate* d = delegate();
1195 if (d)
1196 d->ToolbarSizeChanged(this, is_animating);
1197}
[email protected]616ed5a2008-11-21 22:27:241198
[email protected]fc6fb7fb2009-11-07 02:35:041199bool TabContents::CanDownload(int request_id) {
1200 TabContentsDelegate* d = delegate();
1201 if (d)
1202 return d->CanDownload(request_id);
1203 return true;
1204}
1205
[email protected]d5f942ba2008-09-26 19:30:341206void TabContents::OnStartDownload(DownloadItem* download) {
1207 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341208
1209 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311210 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341211
[email protected]5b928b62010-08-03 11:46:511212 if (tab_contents && tab_contents->delegate())
1213 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411214}
[email protected]3edd9522009-03-04 22:19:411215
[email protected]d5f942ba2008-09-26 19:30:341216void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371217 ConstrainedWindowList::iterator i(
1218 std::find(child_windows_.begin(), child_windows_.end(), window));
1219 bool removed_topmost_window = i == child_windows_.begin();
1220 if (i != child_windows_.end())
1221 child_windows_.erase(i);
1222 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441223 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371224 } else {
1225 if (removed_topmost_window)
1226 child_windows_[0]->ShowConstrainedWindow();
1227 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441228 }
[email protected]66ba4932009-06-04 19:22:131229}
[email protected]d5f942ba2008-09-26 19:30:341230
[email protected]c65e2f152010-10-14 15:30:401231void TabContents::WillCloseBlockedContentContainer(
1232 BlockedContentContainer* container) {
1233 DCHECK(blocked_contents_ == container);
1234 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491235 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341236}
1237
[email protected]d5f942ba2008-09-26 19:30:341238void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351239#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061240 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351241#endif
[email protected]d5f942ba2008-09-26 19:30:341242}
1243
[email protected]c1dc9f132009-11-20 23:13:211244void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121245 bool forward_direction,
1246 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211247 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011248 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211249 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531250 string16 last_search_prepopulate_text =
1251 FindBarState::GetLastPrepopulateText(profile());
1252
[email protected]87fae512009-12-11 02:20:211253 // Try the last thing we searched for on this tab, then the last thing
1254 // searched for on any tab.
1255 if (!previous_find_text_.empty())
1256 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531257 else if (!last_search_prepopulate_text.empty())
1258 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211259 else
[email protected]e491f1c2009-05-22 20:28:121260 return;
[email protected]e491f1c2009-05-22 20:28:121261 }
[email protected]6e95706d2009-04-23 22:55:011262
[email protected]101c90e2009-10-26 21:14:441263 // Keep track of the previous search.
1264 previous_find_text_ = find_text_;
1265
[email protected]6e95706d2009-04-23 22:55:011266 // This is a FindNext operation if we are searching for the same text again,
1267 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1268 // exception to this is if the Find was aborted (then we don't want FindNext
1269 // because the highlighting has been cleared and we need it to reappear). We
1270 // therefore treat FindNext after an aborted Find operation as a full fledged
1271 // Find.
[email protected]c1dc9f132009-11-20 23:13:211272 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121273 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011274 !find_op_aborted_;
1275 if (!find_next)
1276 current_find_request_id_ = find_request_id_counter_++;
1277
[email protected]c1dc9f132009-11-20 23:13:211278 if (!search_string.empty())
1279 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121280 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011281
1282 find_op_aborted_ = false;
1283
1284 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531285 FindBarState* find_bar_state = profile()->GetFindBarState();
1286 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011287 render_view_host()->StartFinding(current_find_request_id_,
1288 find_text_,
1289 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121290 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011291 find_next);
1292}
1293
[email protected]5bc8fe92010-03-11 18:19:001294void TabContents::StopFinding(
1295 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011296 if (selection_action == FindBarController::kClearSelection) {
1297 // kClearSelection means the find string has been cleared by the user, but
1298 // the UI has not been dismissed. In that case we want to clear the
1299 // previously remembered search (http://crbug.com/42639).
1300 previous_find_text_ = string16();
1301 } else {
[email protected]2d2dffc2009-06-09 21:41:001302 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011303 if (!find_text_.empty())
1304 previous_find_text_ = find_text_;
1305 }
[email protected]101c90e2009-10-26 21:14:441306 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011307 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121308 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001309 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011310}
1311
[email protected]420ae012009-04-24 05:16:321312void TabContents::OnSavePage() {
1313 // If we can not save the page, try to download it.
1314 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1315 DownloadManager* dlm = profile()->GetDownloadManager();
1316 const GURL& current_page_url = GetURL();
1317 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221318 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321319 return;
1320 }
1321
1322 Stop();
1323
1324 // Create the save package and possibly prompt the user for the name to save
1325 // the page as. The user prompt is an asynchronous operation that runs on
1326 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221327 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321328 save_package_->GetSaveInfo();
1329}
1330
1331// Used in automated testing to bypass prompting the user for file names.
1332// Instead, the names and paths are hard coded rather than running them through
1333// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111334bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321335 SavePackage::SavePackageType save_type) {
1336 // Stop the page from navigating.
1337 Stop();
1338
[email protected]828cabe2009-09-26 22:47:111339 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591340 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321341}
1342
[email protected]89d6e6e2009-12-03 23:06:511343void TabContents::EmailPageLocation() {
1344 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1345 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1346 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1347 title + "&body=%0A%0A" + page_url;
1348 platform_util::OpenExternal(GURL(mailto));
1349}
1350
[email protected]420ae012009-04-24 05:16:321351void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161352 if (CommandLine::ForCurrentProcess()->HasSwitch(
1353 switches::kEnablePrintPreview)) {
1354 if (showing_interstitial_page())
1355 return;
1356 render_view_host()->PrintPreview();
1357 } else {
1358 PrintNow();
1359 }
[email protected]420ae012009-04-24 05:16:321360}
1361
1362bool TabContents::PrintNow() {
1363 // We can't print interstitial page for now.
1364 if (showing_interstitial_page())
1365 return false;
1366
1367 return render_view_host()->PrintPages();
1368}
1369
[email protected]82270452009-06-19 15:58:011370void TabContents::PrintingDone(int document_cookie, bool success) {
1371 render_view_host()->PrintingDone(document_cookie, success);
1372}
1373
[email protected]420ae012009-04-24 05:16:321374bool TabContents::IsActiveEntry(int32 page_id) {
1375 NavigationEntry* active_entry = controller_.GetActiveEntry();
1376 return (active_entry != NULL &&
1377 active_entry->site_instance() == GetSiteInstance() &&
1378 active_entry->page_id() == page_id);
1379}
1380
[email protected]b2fe07d12010-02-09 14:38:081381void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161382 set_encoding(encoding);
1383 render_view_host()->SetPageEncoding(encoding);
1384}
1385
[email protected]b2fe07d12010-02-09 14:38:081386void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161387 reset_encoding();
1388 render_view_host()->ResetPageEncodingToDefault();
1389}
1390
1391void TabContents::WindowMoveOrResizeStarted() {
1392 render_view_host()->WindowMoveOrResizeStarted();
1393}
1394
[email protected]c65e2f152010-10-14 15:30:401395void TabContents::SetAllContentsBlocked(bool value) {
1396 if (all_contents_blocked_ == value)
1397 return;
1398
1399 all_contents_blocked_ = value;
1400 if (!all_contents_blocked_ && blocked_contents_) {
1401 std::vector<TabContents*> blocked;
1402 blocked_contents_->GetBlockedContents(&blocked);
1403 for (size_t i = 0; i < blocked.size(); ++i)
1404 blocked_contents_->LaunchForContents(blocked[i]);
1405 }
1406}
1407
[email protected]3f8eb7f2009-10-02 23:58:051408void TabContents::LogNewTabTime(const std::string& event_name) {
1409 // Not all new tab pages get timed. In those cases, we don't have a
1410 // new_tab_start_time_.
1411 if (new_tab_start_time_.is_null())
1412 return;
1413
1414 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441415 MetricEventDurationDetails details(event_name,
1416 static_cast<int>(duration.InMilliseconds()));
1417
[email protected]7ab1e7d62009-10-14 23:32:011418 if (event_name == "Tab.NewTabScriptStart") {
1419 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1420 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1421 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1422 } else if (event_name == "Tab.NewTabOnload") {
1423 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051424 // The new tab page has finished loading; reset it.
1425 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441426 } else {
1427 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051428 }
[email protected]84abba62009-10-07 17:01:441429 NotificationService::current()->Notify(
1430 NotificationType::METRIC_EVENT_DURATION,
1431 Source<TabContents>(this),
1432 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051433}
1434
[email protected]7ab1e7d62009-10-14 23:32:011435void TabContents::OnCloseStarted() {
1436 if (tab_close_start_time_.is_null())
1437 tab_close_start_time_ = base::TimeTicks::Now();
1438}
1439
[email protected]46624bf2010-06-09 16:04:191440bool TabContents::ShouldAcceptDragAndDrop() const {
1441#if defined(OS_CHROMEOS)
1442 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1443 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201444 if (delegate() && delegate()->IsPopup(this))
1445 return false;
1446 return true;
[email protected]46624bf2010-06-09 16:04:191447#else
1448 return true;
1449#endif
1450}
1451
[email protected]ec0b6c42010-08-26 03:16:581452void TabContents::UpdateHistoryForNavigation(
1453 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1454 if (profile()->IsOffTheRecord())
1455 return;
1456
1457 // Add to history service.
1458 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1459 if (hs)
1460 hs->AddPage(*add_page_args);
1461}
1462
1463void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1464 if (profile()->IsOffTheRecord())
1465 return;
1466
1467 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1468 if (hs)
1469 hs->SetPageTitle(entry.virtual_url(), entry.title());
1470}
1471
[email protected]d0b8d092010-10-25 04:05:171472double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251473 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1474 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171475 return 0;
[email protected]b75b8292010-10-01 07:28:251476
1477 double zoom_level;
1478 if (temporary_zoom_settings_) {
1479 zoom_level = zoom_map->GetTemporaryZoomLevel(
1480 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1481 } else {
1482 zoom_level = zoom_map->GetZoomLevel(GetURL());
1483 }
[email protected]d0b8d092010-10-25 04:05:171484 return zoom_level;
1485}
[email protected]b75b8292010-10-01 07:28:251486
[email protected]d0b8d092010-10-25 04:05:171487int TabContents::GetZoomPercent(bool* enable_increment,
1488 bool* enable_decrement) {
1489 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251490 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171491 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251492 *enable_decrement = percent > minimum_zoom_percent_;
1493 *enable_increment = percent < maximum_zoom_percent_;
1494 return percent;
1495}
1496
[email protected]96d185d2009-04-24 03:28:541497// Notifies the RenderWidgetHost instance about the fact that the page is
1498// loading, or done loading and calls the base implementation.
1499void TabContents::SetIsLoading(bool is_loading,
1500 LoadNotificationDetails* details) {
1501 if (is_loading == is_loading_)
1502 return;
1503
1504 if (!is_loading) {
1505 load_state_ = net::LOAD_STATE_IDLE;
1506 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561507 upload_size_ = 0;
1508 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541509 }
1510
1511 render_manager_.SetIsLoading(is_loading);
1512
1513 is_loading_ = is_loading;
1514 waiting_for_response_ = is_loading;
1515
[email protected]6ebdc9b2010-09-27 16:55:571516 if (delegate_)
1517 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351518 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541519
1520 NotificationType type = is_loading ? NotificationType::LOAD_START :
1521 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111522 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541523 if (details)
1524 det = Details<LoadNotificationDetails>(details);
1525 NotificationService::current()->Notify(type,
1526 Source<NavigationController>(&controller_),
1527 det);
1528}
1529
[email protected]b6c874582009-05-08 19:38:311530void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291531 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061532 // A page can't spawn popups (or do anything else, either) until its load
1533 // commits, so when we reach here, the popup was spawned by the
1534 // NavigationController's last committed entry, not the active entry. For
1535 // example, if a page opens a popup in an onunload() handler, then the active
1536 // entry is the page to be loaded as we navigate away from the unloading
1537 // page. For this reason, we can't use GetURL() to get the opener URL,
1538 // because it returns the active entry.
1539 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1540 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1541
1542 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491543 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091544 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491545 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1546 } else {
[email protected]c65e2f152010-10-14 15:30:401547 if (!blocked_contents_)
1548 blocked_contents_ = new BlockedContentContainer(this);
1549 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1550 true);
[email protected]55126132010-08-19 14:53:281551 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1552 std::string());
[email protected]8cc8d492010-02-02 10:40:491553 }
[email protected]b9681312008-11-07 00:08:261554}
[email protected]616ed5a2008-11-21 22:27:241555
[email protected]616ed5a2008-11-21 22:27:241556void TabContents::ExpireInfoBars(
1557 const NavigationController::LoadCommittedDetails& details) {
1558 // Only hide InfoBars when the user has done something that makes the main
1559 // frame load. We don't want various automatic or subframe navigations making
1560 // it disappear.
1561 if (!details.is_user_initiated_main_frame_load())
1562 return;
1563
[email protected]f86a07022008-11-25 01:06:051564 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241565 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081566 if (!delegate) {
1567 // If you hit this NOTREACHED, please comment in bug
1568 // http://crbug.com/50428 how you got there.
1569 NOTREACHED();
1570 continue;
1571 }
1572
[email protected]f86a07022008-11-25 01:06:051573 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241574 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241575 }
1576}
[email protected]fdd61c62009-04-22 19:22:571577
[email protected]96d185d2009-04-24 03:28:541578DOMUI* TabContents::GetDOMUIForCurrentState() {
1579 // When there is a pending navigation entry, we want to use the pending DOMUI
1580 // that goes along with it to control the basic flags. For example, we want to
1581 // show the pending URL in the URL bar, so we want the display_url flag to
1582 // be from the pending entry.
1583 //
1584 // The confusion comes because there are multiple possibilities for the
1585 // initial load in a tab as a side effect of the way the RenderViewHostManager
1586 // works.
1587 //
1588 // - For the very first tab the load looks "normal". The new tab DOM UI is
1589 // the pending one, and we want it to apply here.
1590 //
1591 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1592 // get switched to the one previously associated with the new tab pages.
1593 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1594 // have a committed DOM UI in this case.
1595 //
1596 // This condition handles all of these cases:
1597 //
1598 // - First load in first tab: no committed nav entry + pending nav entry +
1599 // pending dom ui:
1600 // -> Use pending DOM UI if any.
1601 //
1602 // - First load in second tab: no committed nav entry + pending nav entry +
1603 // no pending DOM UI:
1604 // -> Use the committed DOM UI if any.
1605 //
1606 // - Second navigation in any tab: committed nav entry + pending nav entry:
1607 // -> Use pending DOM UI if any.
1608 //
1609 // - Normal state with no load: committed nav entry + no pending nav entry:
1610 // -> Use committed DOM UI.
1611 if (controller_.pending_entry() &&
1612 (controller_.GetLastCommittedEntry() ||
1613 render_manager_.pending_dom_ui()))
1614 return render_manager_.pending_dom_ui();
1615 return render_manager_.dom_ui();
1616}
[email protected]420ae012009-04-24 05:16:321617
1618void TabContents::DidNavigateMainFramePostCommit(
1619 const NavigationController::LoadCommittedDetails& details,
1620 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441621 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1622 // If this is a window.open navigation, use the same DOMUI as the renderer
1623 // that opened the window, as long as both renderers have the same
1624 // privileges.
[email protected]583d45c12010-08-31 02:48:121625 if (opener_dom_ui_type_ ==
1626 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441627 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1628 // dom_ui might be NULL if the URL refers to a non-existent extension.
1629 if (dom_ui) {
1630 render_manager_.SetDOMUIPostCommit(dom_ui);
1631 dom_ui->RenderViewCreated(render_view_host());
1632 }
1633 }
1634 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1635 }
1636
[email protected]420ae012009-04-24 05:16:321637 if (details.is_user_initiated_main_frame_load()) {
1638 // Clear the status bubble. This is a workaround for a bug where WebKit
1639 // doesn't let us know that the cursor left an element during a
1640 // transition (this is also why the mouse cursor remains as a hand after
1641 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1642 // clear the bubble when a user navigates to a named anchor in the same
1643 // page.
1644 UpdateTargetURL(details.entry->page_id(), GURL());
1645
1646 // UpdateHelpersForDidNavigate will handle the case where the password_form
1647 // origin is valid.
1648 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1649 // cleaned up and covered by tests.
1650 if (!params.password_form.origin.is_valid())
1651 GetPasswordManager()->DidNavigate();
1652 }
1653
1654 // The keyword generator uses the navigation entries, so must be called after
1655 // the commit.
1656 GenerateKeywordIfNecessary(params);
1657
1658 // Allow the new page to set the title again.
1659 received_page_title_ = false;
1660
1661 // Get the favicon, either from history or request it from the net.
1662 fav_icon_helper_.FetchFavIcon(details.entry->url());
1663
[email protected]0de80162010-02-03 04:52:351664 // Clear all page actions, blocked content notifications and browser actions
1665 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141666 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081667 ExtensionsService* service = profile()->GetExtensionsService();
1668 if (service) {
1669 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571670 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081671 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521672 if (browser_action) {
1673 browser_action->ClearAllValuesForTab(controller().session_id().id());
1674 NotificationService::current()->Notify(
1675 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571676 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521677 NotificationService::NoDetails());
1678 }
[email protected]92c6f9b92009-10-24 04:35:081679
[email protected]5d246db22009-10-27 06:17:571680 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521681 service->extensions()->at(i)->page_action();
1682 if (page_action) {
1683 page_action->ClearAllValuesForTab(controller().session_id().id());
1684 PageActionStateChanged();
1685 }
[email protected]92c6f9b92009-10-24 04:35:081686 }
[email protected]aece2c7f2009-08-27 20:43:171687 }
[email protected]0de80162010-02-03 04:52:351688
1689 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401690 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341691 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401692 blocked_contents_->Destroy();
1693 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351694 }
1695
1696 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411697 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551698 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471699
1700 // Once the main frame is navigated, we're no longer considered to have
1701 // displayed insecure content.
1702 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171703 }
[email protected]ce5c4502009-05-06 16:46:111704
[email protected]8cc8d492010-02-02 10:40:491705 // Close constrained windows if necessary.
1706 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1707 details.previous_url, details.entry->url()))
1708 CloseConstrainedWindows();
1709
[email protected]420ae012009-04-24 05:16:321710 // Update the starred state.
1711 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531712
1713 // Clear the cache of forms in AutoFill.
1714 if (autofill_manager_.get())
1715 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321716}
1717
1718void TabContents::DidNavigateAnyFramePostCommit(
1719 RenderViewHost* render_view_host,
1720 const NavigationController::LoadCommittedDetails& details,
1721 const ViewHostMsg_FrameNavigate_Params& params) {
1722 // If we navigate, start showing messages again. This does nothing to prevent
1723 // a malicious script from spamming messages, since the script could just
1724 // reload the page to stop blocking.
1725 suppress_javascript_messages_ = false;
1726
[email protected]420ae012009-04-24 05:16:321727 // Notify the password manager of the navigation or form submit.
1728 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1729 // cleaned up and covered by tests.
1730 if (params.password_form.origin.is_valid())
1731 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551732
1733 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581734 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321735}
1736
[email protected]8cc8d492010-02-02 10:40:491737void TabContents::CloseConstrainedWindows() {
1738 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321739 // We use indices instead of iterators in case CloseWindow does something
1740 // that may invalidate an iterator.
1741 int size = static_cast<int>(child_windows_.size());
1742 for (int i = size - 1; i >= 0; --i) {
1743 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441744 if (window) {
[email protected]420ae012009-04-24 05:16:321745 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441746 BlockTabContent(false);
1747 }
[email protected]420ae012009-04-24 05:16:321748 }
1749}
1750
1751void TabContents::UpdateStarredStateForCurrentURL() {
1752 BookmarkModel* model = profile()->GetBookmarkModel();
1753 const bool old_state = is_starred_;
1754 is_starred_ = (model && model->IsBookmarked(GetURL()));
1755
1756 if (is_starred_ != old_state && delegate())
1757 delegate()->URLStarredChanged(this, is_starred_);
1758}
1759
1760void TabContents::UpdateAlternateErrorPageURL() {
1761 GURL url = GetAlternateErrorPageURL();
1762 render_view_host()->SetAlternateErrorPageURL(url);
1763}
1764
1765void TabContents::UpdateWebPreferences() {
1766 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1767}
1768
[email protected]d0b8d092010-10-25 04:05:171769void TabContents::UpdateZoomLevel() {
1770 render_view_host()->SetZoomLevel(GetZoomLevel());
1771}
1772
[email protected]420ae012009-04-24 05:16:321773void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1774 RenderViewHost* rvh) {
1775 // If we are creating a RVH for a restored controller, then we might
1776 // have more page IDs than the SiteInstance's current max page ID. We must
1777 // make sure that the max page ID is larger than any restored page ID.
1778 // Note that it is ok for conflicting page IDs to exist in another tab
1779 // (i.e., NavigationController), but if any page ID is larger than the max,
1780 // the back/forward list will get confused.
1781 int max_restored_page_id = controller_.max_restored_page_id();
1782 if (max_restored_page_id > 0) {
1783 int curr_max_page_id = site_instance->max_page_id();
1784 if (max_restored_page_id > curr_max_page_id) {
1785 // Need to update the site instance immediately.
1786 site_instance->UpdateMaxPageID(max_restored_page_id);
1787
1788 // Also tell the renderer to update its internal representation. We
1789 // need to reserve enough IDs to make all restored page IDs less than
1790 // the max.
1791 if (curr_max_page_id < 0)
1792 curr_max_page_id = 0;
1793 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1794 }
1795 }
1796}
1797
[email protected]ec0b6c42010-08-26 03:16:581798scoped_refptr<history::HistoryAddPageArgs>
1799TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541800 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471801 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321802 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581803 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1804 new history::HistoryAddPageArgs(
1805 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1806 params.redirects, params.transition, history::SOURCE_BROWSED,
1807 details.did_replace_entry));
1808 if (PageTransition::IsMainFrame(params.transition) &&
1809 virtual_url != params.url) {
1810 // Hack on the "virtual" URL so that it will appear in history. For some
1811 // types of URLs, we will display a magic URL that is different from where
1812 // the page is actually navigated. We want the user to see in history what
1813 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1814 // only applies to the main frame, as the virtual URL doesn't apply to
1815 // sub-frames.
1816 add_page_args->url = virtual_url;
1817 if (!add_page_args->redirects.empty())
1818 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321819 }
[email protected]ec0b6c42010-08-26 03:16:581820 return add_page_args;
[email protected]420ae012009-04-24 05:16:321821}
1822
1823bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1824 const std::wstring& title) {
1825 // For file URLs without a title, use the pathname instead. In the case of a
1826 // synthesized title, we don't want the update to count toward the "one set
1827 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251828 string16 final_title;
[email protected]420ae012009-04-24 05:16:321829 bool explicit_set;
1830 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251831 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321832 explicit_set = false; // Don't count synthetic titles toward the set limit.
1833 } else {
[email protected]e53668962010-06-23 15:35:251834 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321835 explicit_set = true;
1836 }
1837
[email protected]e53668962010-06-23 15:35:251838 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321839 return false; // Nothing changed, don't bother.
1840
[email protected]e53668962010-06-23 15:35:251841 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321842
[email protected]ec0b6c42010-08-26 03:16:581843 if (!received_page_title_) {
1844 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321845 received_page_title_ = explicit_set;
1846 }
1847
1848 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251849 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321850
[email protected]cbc0e1b2010-04-12 18:33:041851 NotificationService::current()->Notify(
1852 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1853 Source<TabContents>(this),
1854 NotificationService::NoDetails());
1855
[email protected]420ae012009-04-24 05:16:321856 return true;
1857}
1858
1859void TabContents::NotifySwapped() {
1860 // After sending out a swap notification, we need to send a disconnect
1861 // notification so that clients that pick up a pointer to |this| can NULL the
1862 // pointer. See Bug 1230284.
1863 notify_disconnection_ = true;
1864 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341865 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221866 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321867 NotificationService::NoDetails());
1868}
1869
1870void TabContents::NotifyConnected() {
1871 notify_disconnection_ = true;
1872 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341873 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221874 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321875 NotificationService::NoDetails());
1876}
1877
1878void TabContents::NotifyDisconnected() {
1879 if (!notify_disconnection_)
1880 return;
1881
1882 notify_disconnection_ = false;
1883 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341884 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221885 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321886 NotificationService::NoDetails());
1887}
1888
1889void TabContents::GenerateKeywordIfNecessary(
1890 const ViewHostMsg_FrameNavigate_Params& params) {
1891 if (!params.searchable_form_url.is_valid())
1892 return;
1893
1894 if (profile()->IsOffTheRecord())
1895 return;
1896
1897 int last_index = controller_.last_committed_entry_index();
1898 // When there was no previous page, the last index will be 0. This is
1899 // normally due to a form submit that opened in a new tab.
1900 // TODO(brettw) bug 916126: we should support keywords when form submits
1901 // happen in new tabs.
1902 if (last_index <= 0)
1903 return;
1904 const NavigationEntry* previous_entry =
1905 controller_.GetEntryAtIndex(last_index - 1);
1906 if (IsFormSubmit(previous_entry)) {
1907 // Only generate a keyword if the previous page wasn't itself a form
1908 // submit.
1909 return;
1910 }
1911
1912 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1913 previous_entry->user_typed_url() : previous_entry->url();
1914 std::wstring keyword =
1915 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1916 if (keyword.empty())
1917 return;
1918
1919 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1920 if (!url_model)
1921 return;
1922
1923 if (!url_model->loaded()) {
1924 url_model->Load();
1925 return;
1926 }
1927
1928 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191929 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321930 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1931 return;
1932
1933 if (current_url) {
1934 if (current_url->originating_url().is_valid()) {
1935 // The existing keyword was generated from an OpenSearch description
1936 // document, don't regenerate.
1937 return;
1938 }
1939 url_model->Remove(current_url);
1940 }
1941 TemplateURL* new_url = new TemplateURL();
1942 new_url->set_keyword(keyword);
1943 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191944 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321945 new_url->add_input_encoding(params.searchable_form_encoding);
1946 DCHECK(controller_.GetLastCommittedEntry());
1947 const GURL& favicon_url =
1948 controller_.GetLastCommittedEntry()->favicon().url();
1949 if (favicon_url.is_valid()) {
1950 new_url->SetFavIconURL(favicon_url);
1951 } else {
1952 // The favicon url isn't valid. This means there really isn't a favicon,
1953 // or the favicon url wasn't obtained before the load started. This assumes
1954 // the later.
1955 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1956 // its url.
1957 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1958 }
1959 new_url->set_safe_for_autoreplace(true);
1960 url_model->Add(new_url);
1961}
1962
[email protected]bf5c2ff392009-07-08 16:24:331963void TabContents::OnUserGesture() {
1964 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011965 DownloadRequestLimiter* limiter =
1966 g_browser_process->download_request_limiter();
1967 if (limiter)
1968 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261969 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331970}
1971
1972void TabContents::OnFindReply(int request_id,
1973 int number_of_matches,
1974 const gfx::Rect& selection_rect,
1975 int active_match_ordinal,
1976 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421977 // Ignore responses for requests that have been aborted.
1978 if (find_op_aborted_)
1979 return;
1980
[email protected]bf5c2ff392009-07-08 16:24:331981 // Ignore responses for requests other than the one we have most recently
1982 // issued. That way we won't act on stale results when the user has
1983 // already typed in another query.
1984 if (request_id != current_find_request_id_)
1985 return;
1986
1987 if (number_of_matches == -1)
1988 number_of_matches = last_search_result_.number_of_matches();
1989 if (active_match_ordinal == -1)
1990 active_match_ordinal = last_search_result_.active_match_ordinal();
1991
1992 gfx::Rect selection = selection_rect;
1993 if (selection.IsEmpty())
1994 selection = last_search_result_.selection_rect();
1995
1996 // Notify the UI, automation and any other observers that a find result was
1997 // found.
1998 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1999 selection, active_match_ordinal,
2000 final_update);
2001 NotificationService::current()->Notify(
2002 NotificationType::FIND_RESULT_AVAILABLE,
2003 Source<TabContents>(this),
2004 Details<FindNotificationDetails>(&last_search_result_));
2005}
2006
2007void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542008 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2009 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2010 if (!entry)
2011 return;
2012 // Note that we don't call NavigationController::GotToOffset() as we don't
2013 // want to create a pending navigation entry (it might end up lingering
2014 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522015 entry->set_transition_type(entry->transition_type() |
2016 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542017 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2018 }
[email protected]bf5c2ff392009-07-08 16:24:332019}
2020
[email protected]bf5c2ff392009-07-08 16:24:332021void TabContents::OnMissingPluginStatus(int status) {
2022#if defined(OS_WIN)
2023// TODO(PORT): pull in when plug-ins work
2024 GetPluginInstaller()->OnMissingPluginStatus(status);
2025#endif
2026}
2027
2028void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332029 DCHECK(!plugin_path.value().empty());
2030
2031 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]45446a52010-11-04 17:41:002032 WebPluginInfo plugin_info;
2033 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
2034 plugin_path, &plugin_info) &&
2035 !plugin_info.name.empty()) {
2036 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372037#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002038 // Many plugins on the Mac have .plugin in the actual name, which looks
2039 // terrible, so look for that and strip it off if present.
2040 const std::wstring plugin_extension(L".plugin");
2041 if (EndsWith(plugin_name, plugin_extension, true))
2042 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372043#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332044 }
[email protected]2ae8a922010-06-28 20:27:532045 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2046 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332047 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582048 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2049 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532050 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332051}
2052
2053void TabContents::OnCrashedWorker() {
2054 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582055 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422056 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332057}
2058
[email protected]38789d82010-11-17 06:03:442059void TabContents::OnDidGetApplicationInfo(int32 page_id,
2060 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512061 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332062
[email protected]ed5431872009-11-17 08:39:512063 if (delegate())
2064 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332065}
2066
[email protected]851b1eb2010-08-09 13:32:292067void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2068 const GURL& update_url) {
2069 new DisabledPluginInfoBar(this, name, update_url);
2070}
2071
[email protected]a2cf65eb2010-01-18 08:20:382072void TabContents::OnPageContents(const GURL& url,
2073 int renderer_process_id,
2074 int32 page_id,
[email protected]e5106202010-06-11 21:12:362075 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102076 const std::string& language,
2077 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382078 // Don't index any https pages. People generally don't want their bank
2079 // accounts, etc. indexed on their computer, especially since some of these
2080 // things are not marked cachable.
2081 // TODO(brettw) we may want to consider more elaborate heuristics such as
2082 // the cachability of the page. We may also want to consider subframes (this
2083 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272084 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2085 // content indexing for chromeos in some future releases.
2086#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382087 if (!url.SchemeIsSecure()) {
2088 Profile* p = profile();
2089 if (p && !p->IsOffTheRecord()) {
2090 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2091 if (hs)
2092 hs->SetPageContents(url, contents);
2093 }
2094 }
[email protected]ccd40a52010-05-11 16:15:272095#endif
[email protected]a8a81292010-01-21 00:32:452096
[email protected]1c57b7b2010-07-12 17:38:102097 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452098
2099 std::string lang = language;
2100 NotificationService::current()->Notify(
2101 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152102 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452103 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382104}
2105
[email protected]7e0831b2010-02-01 08:45:152106void TabContents::OnPageTranslated(int32 page_id,
2107 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162108 const std::string& translated_lang,
2109 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552110 language_state_.set_current_language(translated_lang);
2111 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162112 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152113 NotificationService::current()->Notify(
2114 NotificationType::PAGE_TRANSLATED,
2115 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162116 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152117}
2118
[email protected]ce833282010-11-04 15:48:392119void TabContents::OnSetSuggestions(
2120 int32 page_id,
2121 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262122 if (delegate())
[email protected]ce833282010-11-04 15:48:392123 delegate()->OnSetSuggestions(page_id, suggestions);
2124}
2125
2126void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2127 if (delegate())
2128 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262129}
2130
[email protected]bf5c2ff392009-07-08 16:24:332131void TabContents::DidStartProvisionalLoadForFrame(
2132 RenderViewHost* render_view_host,
[email protected]dabb0d12010-10-05 12:50:072133 long long frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332134 bool is_main_frame,
2135 const GURL& url) {
2136 ProvisionalLoadDetails details(is_main_frame,
2137 controller_.IsURLInPageNavigation(url),
[email protected]dabb0d12010-10-05 12:50:072138 url, std::string(), false, 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]da4f8a12010-08-19 08:33:412144 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142145 content_settings_delegate_->ClearGeolocationContentSettings();
2146 }
[email protected]bf5c2ff392009-07-08 16:24:332147}
2148
2149void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202150 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332151 NotificationService::current()->Notify(
2152 NotificationType::RESOURCE_RESPONSE_STARTED,
2153 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202154 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332155}
2156
[email protected]3dbb80b2010-02-09 22:41:202157void TabContents::DidRedirectResource(
2158 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332159 NotificationService::current()->Notify(
2160 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2161 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202162 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332163}
2164
2165void TabContents::DidLoadResourceFromMemoryCache(
2166 const GURL& url,
2167 const std::string& frame_origin,
2168 const std::string& main_frame_origin,
2169 const std::string& security_info) {
2170 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442171 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332172 SSLManager::DeserializeSecurityInfo(security_info,
2173 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042174 &security_bits,
2175 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332176 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162177 GetRenderProcessHost()->id(), cert_id,
2178 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332179
2180 NotificationService::current()->Notify(
2181 NotificationType::LOAD_FROM_MEMORY_CACHE,
2182 Source<NavigationController>(&controller_),
2183 Details<LoadFromMemoryCacheDetails>(&details));
2184}
2185
[email protected]e3d60e5d2009-09-25 21:08:292186void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472187 displayed_insecure_content_ = true;
2188 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292189}
2190
2191void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592192 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292193}
2194
[email protected]bf5c2ff392009-07-08 16:24:332195void TabContents::DidFailProvisionalLoadWithError(
2196 RenderViewHost* render_view_host,
[email protected]dabb0d12010-10-05 12:50:072197 long long frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332198 bool is_main_frame,
2199 int error_code,
2200 const GURL& url,
2201 bool showing_repost_interstitial) {
2202 if (net::ERR_ABORTED == error_code) {
2203 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2204 // This means that the interstitial won't be torn down properly, which is
2205 // bad. But if we have an interstitial, go back to another tab type, and
2206 // then load the same interstitial again, we could end up getting the first
2207 // interstitial's "failed" message (as a result of the cancel) when we're on
2208 // the second one.
2209 //
2210 // We can't tell this apart, so we think we're tearing down the current page
2211 // which will cause a crash later one. There is also some code in
2212 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2213 // out because of this problem.
2214 //
2215 // http://code.google.com/p/chromium/issues/detail?id=2855
2216 // Because this will not tear down the interstitial properly, if "back" is
2217 // back to another tab type, the interstitial will still be somewhat alive
2218 // in the previous tab type. If you navigate somewhere that activates the
2219 // tab with the interstitial again, you'll see a flash before the new load
2220 // commits of the interstitial page.
2221 if (showing_interstitial_page()) {
2222 LOG(WARNING) << "Discarding message during interstitial.";
2223 return;
2224 }
2225
2226 // This will discard our pending entry if we cancelled the load (e.g., if we
2227 // decided to download the file instead of load it). Only discard the
2228 // pending entry if the URLs match, otherwise the user initiated a navigate
2229 // before the page loaded so that the discard would discard the wrong entry.
2230 NavigationEntry* pending_entry = controller_.pending_entry();
2231 if (pending_entry && pending_entry->url() == url) {
2232 controller_.DiscardNonCommittedEntries();
2233 // Update the URL display.
2234 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2235 }
2236
2237 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2238 }
2239
2240 // Send out a notification that we failed a provisional load with an error.
2241 ProvisionalLoadDetails details(is_main_frame,
2242 controller_.IsURLInPageNavigation(url),
[email protected]dabb0d12010-10-05 12:50:072243 url, std::string(), false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332244 details.set_error_code(error_code);
2245
2246 NotificationService::current()->Notify(
2247 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2248 Source<NavigationController>(&controller_),
2249 Details<ProvisionalLoadDetails>(&details));
2250}
2251
[email protected]622474d2010-11-04 09:21:082252void TabContents::DocumentLoadedInFrame(long long frame_id) {
[email protected]bf5c2ff392009-07-08 16:24:332253 controller_.DocumentLoadedInFrame();
[email protected]622474d2010-11-04 09:21:082254 NotificationService::current()->Notify(
2255 NotificationType::FRAME_DOM_CONTENT_LOADED,
2256 Source<NavigationController>(&controller_),
2257 Details<long long>(&frame_id));
[email protected]bf5c2ff392009-07-08 16:24:332258}
2259
[email protected]fdd94a02010-11-05 08:07:172260void TabContents::DidFinishLoad(long long frame_id) {
2261 NotificationService::current()->Notify(
2262 NotificationType::FRAME_DID_FINISH_LOAD,
2263 Source<NavigationController>(&controller_),
2264 Details<long long>(&frame_id));
2265}
2266
[email protected]dcd5b332010-08-11 08:55:182267void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562268 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242269 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562270}
2271
[email protected]8d3347f2009-07-09 22:00:212272RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322273 return view_.get();
2274}
2275
[email protected]8d3347f2009-07-09 22:00:212276RenderViewHostDelegate::RendererManagement*
2277TabContents::GetRendererManagementDelegate() {
2278 return &render_manager_;
2279}
2280
[email protected]bf5c2ff392009-07-08 16:24:332281RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212282 TabContents::GetBrowserIntegrationDelegate() {
2283 return this;
[email protected]bf5c2ff392009-07-08 16:24:332284}
2285
[email protected]8d3347f2009-07-09 22:00:212286RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2287 return this;
[email protected]bf5c2ff392009-07-08 16:24:332288}
2289
[email protected]46ba9082010-06-22 10:00:582290RenderViewHostDelegate::ContentSettings*
2291TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552292 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582293}
2294
[email protected]8d3347f2009-07-09 22:00:212295RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322296 return save_package_.get(); // May be NULL, but we can return NULL.
2297}
2298
[email protected]8d3347f2009-07-09 22:00:212299RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092300 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212301}
2302
2303RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2304 return &fav_icon_helper_;
2305}
2306
[email protected]e8dbd674b2010-03-11 18:34:402307RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452308 if (autocomplete_history_manager_.get() == NULL)
2309 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2310 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332311}
2312
[email protected]21674df2009-10-28 19:51:212313RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342314 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212315}
2316
[email protected]1f18184a2010-07-21 19:34:492317RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2318 return GetSSLHelper();
2319}
2320
[email protected]b5977a0c2010-08-24 19:46:262321RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2322 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492323 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262324 return file_select_helper_.get();
2325}
2326
[email protected]fd571bb2010-03-19 01:23:542327AutomationResourceRoutingDelegate*
2328TabContents::GetAutomationResourceRoutingDelegate() {
2329 return delegate();
2330}
2331
[email protected]ced90ae12010-02-20 02:06:162332RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2333 return bookmark_drag_;
2334}
2335
2336void TabContents::SetBookmarkDragDelegate(
2337 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2338 bookmark_drag_ = bookmark_drag;
2339}
2340
[email protected]9fb83e82010-07-02 18:24:552341TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2342 return content_settings_delegate_.get();
2343}
2344
[email protected]93623c5d2009-12-10 21:40:322345RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462346 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512347}
2348
[email protected]57c6a652009-05-04 07:58:342349TabContents* TabContents::GetAsTabContents() {
2350 return this;
2351}
2352
[email protected]7b291f92009-08-14 05:43:532353ViewType::Type TabContents::GetRenderViewType() const {
2354 return ViewType::TAB_CONTENTS;
2355}
2356
2357int TabContents::GetBrowserWindowID() const {
2358 return controller().window_id().id();
2359}
2360
[email protected]420ae012009-04-24 05:16:322361void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062362 NotificationService::current()->Notify(
2363 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2364 Source<TabContents>(this),
2365 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322366 NavigationEntry* entry = controller_.GetActiveEntry();
2367 if (!entry)
2368 return;
2369
2370 // When we're creating views, we're still doing initial setup, so we always
2371 // use the pending DOM UI rather than any possibly existing committed one.
2372 if (render_manager_.pending_dom_ui()) {
2373 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2374 }
2375
2376 if (entry->IsViewSourceMode()) {
2377 // Put the renderer in view source mode.
2378 render_view_host->Send(
2379 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2380 }
[email protected]0666aef2009-05-13 19:48:082381
2382 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322383}
2384
2385void TabContents::RenderViewReady(RenderViewHost* rvh) {
2386 if (rvh != render_view_host()) {
2387 // Don't notify the world, since this came from a renderer in the
2388 // background.
2389 return;
2390 }
2391
2392 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302393 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322394 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302395
2396 // Restore the focus to the tab (otherwise the focus will be on the top
2397 // window).
[email protected]484ae5912010-09-29 19:16:142398 if (was_crashed && !FocusLocationBarByDefault() &&
2399 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302400 Focus();
[email protected]484ae5912010-09-29 19:16:142401 }
[email protected]420ae012009-04-24 05:16:322402}
2403
2404void TabContents::RenderViewGone(RenderViewHost* rvh) {
2405 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092406 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322407 return;
2408 if (rvh != render_view_host()) {
2409 // The pending page's RenderViewHost is gone.
2410 return;
2411 }
2412
2413 SetIsLoading(false, NULL);
2414 NotifyDisconnected();
2415 SetIsCrashed(true);
2416
[email protected]ff9efc62010-02-18 22:10:542417 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212418 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542419 RemoveInfoBar(GetInfoBarDelegateAt(i));
2420
[email protected]8e537302009-06-10 21:19:582421 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552422 // Only do this if we're not in browser shutdown, so that TabContents
2423 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2424 // visible do not flash a sad tab page.
2425 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2426 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322427
2428 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002429 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322430}
2431
[email protected]2e4633c2009-07-09 16:58:062432void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2433 NotificationService::current()->Notify(
2434 NotificationType::RENDER_VIEW_HOST_DELETED,
2435 Source<TabContents>(this),
2436 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482437 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062438}
2439
[email protected]420ae012009-04-24 05:16:322440void TabContents::DidNavigate(RenderViewHost* rvh,
2441 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372442 int extra_invalidate_flags = 0;
2443
2444 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352445 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372446
[email protected]420ae012009-04-24 05:16:322447 render_manager_.DidNavigateMainFrame(rvh);
2448
[email protected]20ede072009-10-06 00:28:352449 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372450 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372451 }
2452
[email protected]420ae012009-04-24 05:16:322453 // Update the site of the SiteInstance if it doesn't have one yet.
2454 if (!GetSiteInstance()->has_site())
2455 GetSiteInstance()->SetSite(params.url);
2456
2457 // Need to update MIME type here because it's referred to in
2458 // UpdateNavigationCommands() called by RendererDidNavigate() to
2459 // determine whether or not to enable the encoding menu.
2460 // It's updated only for the main frame. For a subframe,
2461 // RenderView::UpdateURL does not set params.contents_mime_type.
2462 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2463 // TODO(jungshik): Add a test for the encoding menu to avoid
2464 // regressing it again.
2465 if (PageTransition::IsMainFrame(params.transition))
2466 contents_mime_type_ = params.contents_mime_type;
2467
2468 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372469 bool did_navigate = controller_.RendererDidNavigate(
2470 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392471
[email protected]a9c0bfe2010-09-17 08:35:222472 // Send notification about committed provisional loads. This notification is
2473 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2474 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2475 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072476 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2477 // that is not recorded in the navigation history. For the purpose of
2478 // tracking navigation events, we treat this event as a sub frame navigation
2479 // event.
2480 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2481 ProvisionalLoadDetails load_details(
2482 is_main_frame, details.is_in_page, params.url, std::string(), false,
2483 params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222484 load_details.set_transition_type(params.transition);
2485 // Whether or not a page transition was triggered by going backward or
2486 // forward in the history is only stored in the navigation controller's
2487 // entry list.
2488 if (did_navigate &&
2489 (controller_.GetActiveEntry()->transition_type() &
2490 PageTransition::FORWARD_BACK)) {
2491 load_details.set_transition_type(
2492 params.transition | PageTransition::FORWARD_BACK);
2493 }
2494 NotificationService::current()->Notify(
2495 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2496 Source<NavigationController>(&controller_),
2497 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222498 }
2499
[email protected]3e90d4a2009-07-03 17:38:392500 // Update history. Note that this needs to happen after the entry is complete,
2501 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582502 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392503 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582504 // URLs, we use a data: URL as the real value. We actually want to save the
2505 // about: URL to the history db and keep the data: URL hidden. This is what
2506 // the TabContents' URL getter does.
2507 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2508 CreateHistoryAddPageArgs(GetURL(), details, params));
2509 if (!delegate() ||
2510 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2511 details.type)) {
2512 UpdateHistoryForNavigation(add_page_args);
2513 }
[email protected]3e90d4a2009-07-03 17:38:392514 }
2515
[email protected]76543b92009-08-31 17:27:452516 if (!did_navigate)
2517 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322518
2519 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2520 // for the appropriate notification (best) or you can add it to
2521 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2522 // necessary, please).
2523
2524 // Run post-commit tasks.
2525 if (details.is_main_frame)
2526 DidNavigateMainFramePostCommit(details, params);
2527 DidNavigateAnyFramePostCommit(rvh, details, params);
2528}
2529
2530void TabContents::UpdateState(RenderViewHost* rvh,
2531 int32 page_id,
2532 const std::string& state) {
2533 DCHECK(rvh == render_view_host());
2534
2535 // We must be prepared to handle state updates for any page, these occur
2536 // when the user is scrolling and entering form data, as well as when we're
2537 // leaving a page, in which case our state may have already been moved to
2538 // the next page. The navigation controller will look up the appropriate
2539 // NavigationEntry and update it when it is notified via the delegate.
2540
2541 int entry_index = controller_.GetEntryIndexWithPageID(
2542 GetSiteInstance(), page_id);
2543 if (entry_index < 0)
2544 return;
2545 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2546
2547 if (state == entry->content_state())
2548 return; // Nothing to update.
2549 entry->set_content_state(state);
2550 controller_.NotifyEntryChanged(entry, entry_index);
2551}
2552
2553void TabContents::UpdateTitle(RenderViewHost* rvh,
2554 int32 page_id, const std::wstring& title) {
2555 // If we have a title, that's a pretty good indication that we've started
2556 // getting useful data.
2557 SetNotWaitingForResponse();
2558
2559 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482560 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582561 page_id);
[email protected]420ae012009-04-24 05:16:322562 if (!entry || !UpdateTitleForEntry(entry, title))
2563 return;
2564
2565 // Broadcast notifications when the UI should be updated.
2566 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032567 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322568}
2569
[email protected]420ae012009-04-24 05:16:322570void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402571 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322572 set_encoding(encoding);
2573}
2574
2575void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2576 if (delegate())
2577 delegate()->UpdateTargetURL(this, url);
2578}
2579
2580void TabContents::UpdateThumbnail(const GURL& url,
2581 const SkBitmap& bitmap,
2582 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442583 if (profile()->IsOffTheRecord())
2584 return;
2585
[email protected]420ae012009-04-24 05:16:322586 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492587 if (history::TopSites::IsEnabled()) {
[email protected]e6baed562010-11-02 22:33:442588 history::TopSites* ts = profile()->GetTopSites();
2589 if (ts)
2590 ts->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282591 } else {
[email protected]e6baed562010-11-02 22:33:442592 HistoryService* hs =
2593 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2594 if (hs)
[email protected]449478302009-06-09 20:04:282595 hs->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322596 }
2597}
2598
[email protected]c4e98902010-06-01 10:20:142599void TabContents::UpdateInspectorSetting(const std::string& key,
2600 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052601 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082602}
2603
[email protected]45aafc92010-06-07 14:18:532604void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052605 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532606}
2607
[email protected]420ae012009-04-24 05:16:322608void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292609 // The UI may be in an event-tracking loop, such as between the
2610 // mouse-down and mouse-up in text selection or a button click.
2611 // Defer the close until after tracking is complete, so that we
2612 // don't free objects out from under the UI.
2613 // TODO(shess): This could probably be integrated with the
2614 // IsDoingDrag() test below. Punting for now because I need more
2615 // research to understand how this impacts platforms other than Mac.
2616 // TODO(shess): This could get more fine-grained. For instance,
2617 // closing a tab in another window while selecting text in the
2618 // current window's Omnibox should be just fine.
2619 if (view()->IsEventTracking()) {
2620 view()->CloseTabAfterEventTracking();
2621 return;
2622 }
2623
[email protected]24a4d1062009-07-10 23:10:422624 // If we close the tab while we're in the middle of a drag, we'll crash.
2625 // Instead, cancel the drag and close it as soon as the drag ends.
2626 if (view()->IsDoingDrag()) {
2627 view()->CancelDragAndCloseTab();
2628 return;
2629 }
2630
[email protected]420ae012009-04-24 05:16:322631 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2632 if (delegate() && rvh == render_view_host())
2633 delegate()->CloseContents(this);
2634}
2635
2636void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2637 if (delegate() && delegate()->IsPopup(this))
2638 delegate()->MoveContents(this, new_bounds);
2639}
2640
[email protected]7ab1e7d62009-10-14 23:32:012641void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322642 SetIsLoading(true, NULL);
[email protected]9e823662010-10-13 23:36:002643 if (content_restrictions_) {
2644 content_restrictions_= 0;
2645 delegate()->ContentRestrictionsChanged(this);
2646 }
[email protected]420ae012009-04-24 05:16:322647}
2648
[email protected]7ab1e7d62009-10-14 23:32:012649void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322650 scoped_ptr<LoadNotificationDetails> details;
2651
2652 NavigationEntry* entry = controller_.GetActiveEntry();
2653 // An entry may not exist for a stop when loading an initial blank page or
2654 // if an iframe injected by script into a blank page finishes loading.
2655 if (entry) {
[email protected]420ae012009-04-24 05:16:322656 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2657
2658 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542659 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322660 entry->transition_type(),
2661 elapsed,
2662 &controller_,
2663 controller_.GetCurrentEntryIndex()));
2664 }
2665
2666 // Tell PasswordManager we've finished a page load, which serves as a
2667 // green light to save pending passwords and reset itself.
2668 GetPasswordManager()->DidStopLoading();
2669
2670 SetIsLoading(false, details.get());
2671}
2672
[email protected]25497492010-09-11 15:15:082673void TabContents::DocumentOnLoadCompletedInMainFrame(
2674 RenderViewHost* render_view_host,
2675 int32 page_id) {
2676 NotificationService::current()->Notify(
2677 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2678 Source<TabContents>(this),
2679 Details<int>(&page_id));
2680}
2681
[email protected]420ae012009-04-24 05:16:322682void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2683 const GURL& source_url,
2684 const GURL& target_url) {
2685 NavigationEntry* entry;
2686 if (page_id == -1)
2687 entry = controller_.pending_entry();
2688 else
2689 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2690 if (!entry || entry->url() != source_url)
2691 return;
2692 entry->set_url(target_url);
2693}
2694
[email protected]420ae012009-04-24 05:16:322695void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2696 WindowOpenDisposition disposition) {
2697 if (render_manager_.dom_ui()) {
2698 // When we're a DOM UI, it will provide a page transition type for us (this
2699 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2700 // generated suggestions).
2701 //
2702 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162703 // want web sites to see a referrer of "chrome://blah" (and some
2704 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322705 // send to the site), so we send no referrer.
2706 OpenURL(url, GURL(), disposition,
2707 render_manager_.dom_ui()->link_transition_type());
2708 } else {
2709 OpenURL(url, referrer, disposition, PageTransition::LINK);
2710 }
2711}
2712
[email protected]1ee614862009-07-06 20:29:182713void TabContents::DomOperationResponse(const std::string& json_string,
2714 int automation_id) {
2715}
2716
[email protected]8b8e7c92010-08-19 18:05:562717void TabContents::ProcessDOMUIMessage(
2718 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322719 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442720 // This can happen if someone uses window.open() to open an extension URL
2721 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562722 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322723 return;
2724 }
[email protected]8b8e7c92010-08-19 18:05:562725 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322726}
2727
2728void TabContents::ProcessExternalHostMessage(const std::string& message,
2729 const std::string& origin,
2730 const std::string& target) {
2731 if (delegate())
2732 delegate()->ForwardMessageToExternalHost(message, origin, target);
2733}
2734
[email protected]420ae012009-04-24 05:16:322735void TabContents::RunJavaScriptMessage(
2736 const std::wstring& message,
2737 const std::wstring& default_prompt,
2738 const GURL& frame_url,
2739 const int flags,
2740 IPC::Message* reply_msg,
2741 bool* did_suppress_message) {
2742 // Suppress javascript messages when requested and when inside a constrained
2743 // popup window (because that activates them and breaks them out of the
2744 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552745 // Also suppress messages when showing an interstitial. The interstitial is
2746 // shown over the previous page, we don't want the hidden page dialogs to
2747 // interfere with the interstitial.
2748 bool suppress_this_message = suppress_javascript_messages_ ||
2749 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322750 if (delegate())
2751 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312752 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322753
2754 *did_suppress_message = suppress_this_message;
2755
2756 if (!suppress_this_message) {
2757 base::TimeDelta time_since_last_message(
2758 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2759 bool show_suppress_checkbox = false;
2760 // Show a checkbox offering to suppress further messages if this message is
2761 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2762 if (time_since_last_message <
2763 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2764 show_suppress_checkbox = true;
2765
[email protected]d6ad7442010-09-05 19:06:522766 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2767 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322768 } else {
2769 // If we are suppressing messages, just reply as is if the user immediately
2770 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542771 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322772 }
2773}
2774
2775void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2776 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012777 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222778 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322779}
2780
2781void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2782 const std::string& json_arguments,
2783 IPC::Message* reply_msg) {
2784 if (delegate()) {
2785 HtmlDialogUIDelegate* dialog_delegate =
2786 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222787 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322788 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2789 }
2790}
2791
[email protected]4d44a1c2010-04-28 19:20:412792void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562793 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412794 GetPasswordManager()->PasswordFormsFound(forms);
2795}
2796
2797void TabContents::PasswordFormsVisible(
2798 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2799 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322800}
2801
[email protected]420ae012009-04-24 05:16:322802// Checks to see if we should generate a keyword based on the OSDD, and if
2803// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202804void TabContents::PageHasOSDD(
2805 RenderViewHost* render_view_host,
2806 int32 page_id,
2807 const GURL& url,
2808 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122809 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322810 DCHECK(url.is_valid());
2811 if (!IsActiveEntry(page_id))
2812 return;
[email protected]420ae012009-04-24 05:16:322813 if (!profile()->GetTemplateURLFetcher())
2814 return;
[email protected]420ae012009-04-24 05:16:322815 if (profile()->IsOffTheRecord())
2816 return;
2817
[email protected]2de7e002010-10-11 22:58:202818 TemplateURLFetcher::ProviderType provider_type;
2819 switch (msg_provider_type.type) {
2820 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2821 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2822 break;
2823
2824 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2825 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2826 break;
2827
2828 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2829 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2830 break;
2831
2832 default:
2833 NOTREACHED();
2834 return;
2835 }
2836
[email protected]420ae012009-04-24 05:16:322837 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2838 DCHECK(entry);
2839
2840 const NavigationEntry* base_entry = entry;
2841 if (IsFormSubmit(base_entry)) {
2842 // If the current page is a form submit, find the last page that was not
2843 // a form submit and use its url to generate the keyword from.
2844 int index = controller_.last_committed_entry_index() - 1;
2845 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2846 index--;
2847 if (index >= 0)
2848 base_entry = controller_.GetEntryAtIndex(index);
2849 else
2850 base_entry = NULL;
2851 }
2852
2853 // We want to use the user typed URL if available since that represents what
2854 // the user typed to get here, and fall back on the regular URL if not.
2855 if (!base_entry)
2856 return;
2857 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2858 base_entry->user_typed_url() : base_entry->url();
2859 if (!keyword_url.is_valid())
2860 return;
[email protected]2de7e002010-10-11 22:58:202861
[email protected]0b5b85c2010-10-11 23:00:122862 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2863 keyword_url,
2864 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532865
[email protected]0b5b85c2010-10-11 23:00:122866 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322867 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322868 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2869 keyword,
2870 url,
2871 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122872 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202873 provider_type);
[email protected]420ae012009-04-24 05:16:322874}
2875
[email protected]420ae012009-04-24 05:16:322876GURL TabContents::GetAlternateErrorPageURL() const {
2877 GURL url;
2878 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2879 if (profile()->IsOffTheRecord())
2880 return url;
2881
2882 PrefService* prefs = profile()->GetPrefs();
2883 DCHECK(prefs);
2884 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152885 url = google_util::AppendGoogleLocaleParam(
2886 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322887 url = google_util::AppendGoogleTLDParam(url);
2888 }
2889 return url;
2890}
2891
2892WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062893 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552894 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082895 WebPreferences web_prefs =
2896 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
2897
[email protected]9beff752010-09-22 19:35:432898 // Force accelerated compositing and 2d canvas off for chrome: and
2899 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432900 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2901 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082902 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432903 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082904 }
2905
[email protected]39553442010-09-09 00:01:552906#if defined(OS_MACOSX)
2907 // Disable accelerated compositing if IOSurface's are not supported,
2908 // as is the case in 10.5.
2909 if (!IOSurfaceSupport::Initialize())
2910 web_prefs.accelerated_compositing_enabled = false;
2911#endif
2912
[email protected]447021c2010-09-08 21:29:082913 return web_prefs;
[email protected]420ae012009-04-24 05:16:322914}
2915
[email protected]fa1cf0b82010-01-15 21:49:442916void TabContents::OnIgnoredUIEvent() {
2917 if (constrained_window_count()) {
2918 ConstrainedWindow* window = *constrained_window_begin();
2919 window->FocusConstrainedWindow();
2920 }
2921}
2922
[email protected]420ae012009-04-24 05:16:322923void TabContents::OnJSOutOfMemory() {
2924 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582925 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2926 NULL, true));
[email protected]420ae012009-04-24 05:16:322927}
2928
[email protected]420ae012009-04-24 05:16:322929void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2930 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342931 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322932 // delivered to a pending RenderViewHost. We must first run the onunload
2933 // handler of the old RenderViewHost before we can allow it to proceed.
2934 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2935 new_request_id);
2936}
2937
[email protected]420ae012009-04-24 05:16:322938void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2939 bool is_during_unload) {
2940 if (is_during_unload) {
2941 // Hang occurred while firing the beforeunload/unload handler.
2942 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112943 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322944
2945 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2946 return;
2947
2948 // If the tab hangs in the beforeunload/unload handler there's really
2949 // nothing we can do to recover. Pretend the unload listeners have
2950 // all fired and close the tab. If the hang is in the beforeunload handler
2951 // then the user will not have the option of cancelling the close.
2952 Close(rvh);
2953 return;
2954 }
2955
2956 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002957 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322958}
2959
2960void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002961 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322962}
2963
2964void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562965 net::LoadState load_state,
2966 uint64 upload_position,
2967 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322968 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562969 upload_position_ = upload_position;
2970 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292971 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192972 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292973 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532974 load_state_host_ =
2975 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322976 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2977 SetNotWaitingForResponse();
2978 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502979 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322980}
2981
[email protected]1ee614862009-07-06 20:29:182982bool TabContents::IsExternalTabContainer() const {
2983 if (!delegate())
2984 return false;
2985
2986 return delegate()->IsExternalTabContainer();
2987}
2988
[email protected]1ee614862009-07-06 20:29:182989void TabContents::DidInsertCSS() {
2990 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322991}
2992
[email protected]130efb02009-09-18 18:54:352993void TabContents::FocusedNodeChanged() {
2994 NotificationService::current()->Notify(
2995 NotificationType::FOCUS_CHANGED_IN_PAGE,
2996 Source<RenderViewHost>(render_view_host()),
2997 NotificationService::NoDetails());
2998}
2999
[email protected]b75b8292010-10-01 07:28:253000void TabContents::UpdateZoomLimits(int minimum_percent,
3001 int maximum_percent,
3002 bool remember) {
3003 minimum_zoom_percent_ = minimum_percent;
3004 maximum_zoom_percent_ = maximum_percent;
3005 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383006}
3007
[email protected]9e823662010-10-13 23:36:003008void TabContents::UpdateContentRestrictions(int restrictions) {
3009 content_restrictions_ = restrictions;
3010 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:323011}
3012
[email protected]420ae012009-04-24 05:16:323013void TabContents::BeforeUnloadFiredFromRenderManager(
3014 bool proceed,
3015 bool* proceed_to_fire_unload) {
3016 if (delegate())
3017 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3018}
3019
[email protected]3a3d47472010-07-15 21:03:543020void TabContents::DidStartLoadingFromRenderManager(
3021 RenderViewHost* render_view_host) {
3022 DidStartLoading();
3023}
3024
3025void TabContents::RenderViewGoneFromRenderManager(
3026 RenderViewHost* render_view_host) {
3027 RenderViewGone(render_view_host);
3028}
3029
[email protected]420ae012009-04-24 05:16:323030void TabContents::UpdateRenderViewSizeForRenderManager() {
3031 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263032 gfx::Size size = view_->GetContainerSize();
3033 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3034 // here during container initialization and normal window size will be set
3035 // later. In case of tab duplication this resizing to 0x0 prevents setting
3036 // normal size later so just ignore it.
3037 if (!size.IsEmpty())
3038 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323039}
3040
[email protected]3a3d47472010-07-15 21:03:543041void TabContents::NotifySwappedFromRenderManager() {
3042 NotifySwapped();
3043}
3044
3045NavigationController& TabContents::GetControllerForRenderManager() {
3046 return controller();
3047}
3048
[email protected]420ae012009-04-24 05:16:323049DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223050 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323051}
3052
3053NavigationEntry*
3054TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3055 return controller_.GetLastCommittedEntry();
3056}
3057
3058bool TabContents::CreateRenderViewForRenderManager(
3059 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323060 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523061
[email protected]674b3822010-08-04 04:02:513062 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323063 return false;
3064
3065 // Now that the RenderView has been created, we need to tell it its size.
3066 rwh_view->SetSize(view_->GetContainerSize());
3067
3068 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3069 render_view_host);
3070 return true;
3071}
3072
3073void TabContents::Observe(NotificationType type,
3074 const NotificationSource& source,
3075 const NotificationDetails& details) {
3076 switch (type.value) {
3077 case NotificationType::BOOKMARK_MODEL_LOADED:
3078 // BookmarkModel finished loading, fall through to update starred state.
3079 case NotificationType::URLS_STARRED: {
3080 // Somewhere, a URL has been starred.
3081 // Ignore notifications for profiles other than our current one.
3082 Profile* source_profile = Source<Profile>(source).ptr();
3083 if (!source_profile || !source_profile->IsSameProfile(profile()))
3084 return;
3085
3086 UpdateStarredStateForCurrentURL();
3087 break;
3088 }
3089 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513090 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323091 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3092 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3093 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533094 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3095 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323096 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173097 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3098 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323099 } else {
3100 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3101 }
3102 break;
3103 }
3104 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3105 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3106 break;
3107
3108 case NotificationType::NAV_ENTRY_COMMITTED: {
3109 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3110
3111 NavigationController::LoadCommittedDetails& committed_details =
3112 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3113 ExpireInfoBars(committed_details);
3114 break;
3115 }
3116
[email protected]d3ba77272009-09-03 00:06:093117#if defined(OS_LINUX)
3118 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543119 renderer_preferences_util::UpdateFromSystemSettings(
3120 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093121 render_view_host()->SyncRendererPrefs();
3122 break;
3123 }
3124#endif
3125
[email protected]6c32ce72010-03-08 05:18:063126 case NotificationType::USER_STYLE_SHEET_UPDATED:
3127 UpdateWebPreferences();
3128 break;
3129
[email protected]79580c62010-02-02 02:36:253130 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:293131 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:253132 settings_details(details);
[email protected]79580c62010-02-02 02:36:253133 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493134 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293135 if (entry)
[email protected]da0c8e92010-02-09 23:25:493136 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293137 if (settings_details.ptr()->update_all() ||
3138 settings_details.ptr()->pattern().Matches(entry_url)) {
3139 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233140 profile()->GetHostContentSettingsMap()->
3141 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253142 }
3143 break;
3144 }
3145
[email protected]e5adff72010-06-14 18:13:063146 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573147 break;
[email protected]a888b29e62010-04-01 13:38:573148
3149 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063150 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573151 break;
[email protected]a888b29e62010-04-01 13:38:573152
[email protected]88152052010-10-01 04:05:183153 case NotificationType::GOOGLE_URL_UPDATED:
3154 UpdateAlternateErrorPageURL();
3155 break;
3156
[email protected]420ae012009-04-24 05:16:323157 default:
3158 NOTREACHED();
3159 }
3160}
[email protected]aacd7cc2009-09-02 14:51:103161
[email protected]9adb9692010-10-29 23:14:023162void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083163 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433164
[email protected]a888b29e62010-04-01 13:38:573165 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083166 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3167 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573168 extension,
[email protected]807871f2010-09-16 01:04:483169 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3170 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573171 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3172 Extension::EXTENSION_ICON_SMALLISH),
3173 ImageLoadingTracker::CACHE);
3174 } else {
[email protected]98aa0b52010-05-06 17:03:083175 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573176 }
3177}
3178
[email protected]9adb9692010-10-29 23:14:023179const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:573180 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3181 if (!extensions_service)
3182 return NULL;
3183
[email protected]9adb9692010-10-29 23:14:023184 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573185 return extension ?
3186 extension : extensions_service->GetExtensionByWebExtent(url);
3187}
3188
[email protected]a888b29e62010-04-01 13:38:573189void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3190 int index) {
3191 if (image) {
[email protected]98aa0b52010-05-06 17:03:083192 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573193 NotifyNavigationStateChanged(INVALIDATE_TAB);
3194 }
3195}
3196
[email protected]beb440c2009-11-06 04:08:543197gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3198 return view_->GetTopLevelNativeWindow();
3199}
3200
3201void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3202 bool success,
3203 const std::wstring& prompt) {
3204 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3205 if (is_showing_before_unload_dialog_ && !success) {
3206 // If a beforeunload dialog is canceled, we need to stop the throbber from
3207 // spinning, since we forced it to start spinning in Navigate.
3208 DidStopLoading();
3209
3210 tab_close_start_time_ = base::TimeTicks();
3211 }
3212 is_showing_before_unload_dialog_ = false;
3213 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3214}
3215
3216void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3217 set_suppress_javascript_messages(suppress_message_boxes);
3218}
3219
[email protected]3a3d47472010-07-15 21:03:543220TabContents* TabContents::AsTabContents() {
3221 return this;
3222}
3223
3224ExtensionHost* TabContents::AsExtensionHost() {
3225 return NULL;
3226}
3227
[email protected]41fc0322009-09-04 22:23:403228void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103229 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3230}
[email protected]f45d2a72010-03-08 23:28:353231
3232void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3233 app_icon_ = app_icon;
3234 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3235}
[email protected]ea68c06a2010-04-23 17:25:373236
3237// After a successful *new* login attempt, we take the PasswordFormManager in
3238// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3239// the user makes up their mind with the "save password" infobar. Note if the
3240// login is one we already know about, the end of the line is
3241// provisional_save_manager_ because we just update it on success and so such
3242// forms never end up in an infobar.
3243class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3244 public:
3245 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463246 PasswordFormManager* form_to_save)
3247 : ConfirmInfoBarDelegate(tab_contents),
3248 form_to_save_(form_to_save),
[email protected]d75aba1d2010-08-02 23:35:583249 infobar_response_(NO_RESPONSE) {}
[email protected]ea68c06a2010-04-23 17:25:373250
[email protected]d75aba1d2010-08-02 23:35:583251 virtual ~SavePasswordInfoBarDelegate() {}
[email protected]ea68c06a2010-04-23 17:25:373252
[email protected]d75aba1d2010-08-02 23:35:583253 // Begin ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373254 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463255 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
[email protected]d75aba1d2010-08-02 23:35:583256 infobar_response_, NUM_RESPONSE_TYPES);
[email protected]ea68c06a2010-04-23 17:25:373257 delete this;
3258 }
3259
[email protected]d75aba1d2010-08-02 23:35:583260 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
3261
[email protected]e23d3a32010-08-13 19:39:583262 virtual string16 GetMessageText() const {
3263 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
[email protected]ea68c06a2010-04-23 17:25:373264 }
3265
3266 virtual SkBitmap* GetIcon() const {
3267 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3268 IDR_INFOBAR_SAVE_PASSWORD);
3269 }
3270
3271 virtual int GetButtons() const {
3272 return BUTTON_OK | BUTTON_CANCEL;
3273 }
3274
[email protected]e23d3a32010-08-13 19:39:583275 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]ea68c06a2010-04-23 17:25:373276 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:583277 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373278 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:583279 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373280 NOTREACHED();
[email protected]e23d3a32010-08-13 19:39:583281 return string16();
[email protected]ea68c06a2010-04-23 17:25:373282 }
3283
3284 virtual bool Accept() {
3285 DCHECK(form_to_save_.get());
3286 form_to_save_->Save();
[email protected]d75aba1d2010-08-02 23:35:583287 infobar_response_ = REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373288 return true;
3289 }
3290
3291 virtual bool Cancel() {
3292 DCHECK(form_to_save_.get());
3293 form_to_save_->PermanentlyBlacklist();
[email protected]d75aba1d2010-08-02 23:35:583294 infobar_response_ = DONT_REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373295 return true;
3296 }
[email protected]d75aba1d2010-08-02 23:35:583297 // End ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373298
3299 private:
3300 // The PasswordFormManager managing the form we're asking the user about,
3301 // and should update as per her decision.
3302 scoped_ptr<PasswordFormManager> form_to_save_;
3303
[email protected]12bb6822010-06-16 02:00:463304 // Used to track the results we get from the info bar.
3305 enum ResponseType {
[email protected]d75aba1d2010-08-02 23:35:583306 NO_RESPONSE = 0,
3307 REMEMBER_PASSWORD,
3308 DONT_REMEMBER_PASSWORD,
3309 NUM_RESPONSE_TYPES,
[email protected]12bb6822010-06-16 02:00:463310 };
3311 ResponseType infobar_response_;
3312
[email protected]ea68c06a2010-04-23 17:25:373313 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3314};
3315
3316void TabContents::FillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163317 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]ea68c06a2010-04-23 17:25:373318 render_view_host()->FillPasswordForm(form_data);
3319}
3320
3321void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3322 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3323}
3324
3325Profile* TabContents::GetProfileForPasswordManager() {
3326 return profile();
3327}
3328
3329bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3330 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3331}