blob: 4215528e02daaaa2cc4c9f02be2f7ca7fbceb11d [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"
[email protected]aacd7cc2009-09-02 14:51:1030#include "chrome/browser/character_encoding.h"
[email protected]5f24f212010-12-02 14:47:4531#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3332#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5433#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1434#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3235#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5436#include "chrome/browser/dom_ui/dom_ui.h"
37#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0238#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3239#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0140#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4941#include "chrome/browser/external_protocol_handler.h"
[email protected]eaa7dd182010-12-14 11:09:0042#include "chrome/browser/extensions/extension_service.h"
[email protected]ec0b6c42010-08-26 03:16:5843#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4244#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2545#include "chrome/browser/host_zoom_map.h"
[email protected]0189bc722009-08-28 21:56:4846#include "chrome/browser/favicon_service.h"
[email protected]ba70d082010-09-10 16:54:4947#include "chrome/browser/file_select_helper.h"
[email protected]f7578f52010-08-30 22:22:4948#include "chrome/browser/google/google_util.h"
[email protected]8897c382009-05-06 17:53:2649#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0750#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3251#include "chrome/browser/load_from_memory_cache_details.h"
52#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4453#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0554#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1055#include "chrome/browser/omnibox_search_hint.h"
[email protected]14a000d2010-04-29 21:44:2456#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5757#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0258#include "chrome/browser/prefs/pref_service.h"
[email protected]33f74972010-12-08 16:40:3659#include "chrome/browser/prerender/prerender_manager.h"
[email protected]dbeebd52010-11-16 20:34:1660#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0961#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3362#include "chrome/browser/profiles/profile.h"
[email protected]1db6ff152009-10-12 15:32:0763#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1664#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5465#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3766#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0767#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5468#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3269#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1170#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1671#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1272#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1673#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1774#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1775#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5476#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1677#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4378#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1679#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4980#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5781#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]3c9e1872010-11-18 16:17:4982#include "chrome/browser/tab_contents/web_navigation_observer.h"
[email protected]152b8ba32010-03-29 19:40:1683#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3584#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]45300ad42010-12-02 15:51:1485#include "chrome/browser/ui/find_bar/find_bar_state.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]de4761b2010-12-07 21:05:2188#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4989#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5790#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4891#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1492#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0993#include "chrome/common/extensions/url_pattern.h"
94#include "chrome/common/navigation_types.h"
95#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5696#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2997#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3298#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0299#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:18100#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:54101#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:37102#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:26103#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32104#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06105#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37106#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32107#include "net/base/mime_util.h"
108#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29109#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32110#include "net/base/registry_controlled_domain.h"
[email protected]b75b8292010-10-01 07:28:25111#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]1ee614862009-07-06 20:29:18112#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03113#include "webkit/glue/password_form.h"
[email protected]45446a52010-11-04 17:41:00114#include "webkit/glue/plugins/plugin_list.h"
[email protected]3e45ba92009-02-20 21:09:00115
[email protected]420ae012009-04-24 05:16:32116// Cross-Site Navigations
117//
118// If a TabContents is told to navigate to a different web site (as determined
119// by SiteInstance), it will replace its current RenderViewHost with a new
120// RenderViewHost dedicated to the new SiteInstance. This works as follows:
121//
122// - Navigate determines whether the destination is cross-site, and if so,
123// it creates a pending_render_view_host_ and moves into the PENDING
124// RendererState.
125// - The pending RVH is "suspended," so that no navigation messages are sent to
126// its renderer until the onbeforeunload JavaScript handler has a chance to
127// run in the current RVH.
128// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
129// that it has a pending cross-site request. ResourceDispatcherHost will
130// check for this when the response arrives.
131// - The current RVH runs its onbeforeunload handler. If it returns false, we
132// cancel all the pending logic and go back to NORMAL. Otherwise we allow
133// the pending RVH to send the navigation request to its renderer.
134// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
135// checks CrossSiteRequestManager to see that the RVH responsible has a
136// pending cross-site request, and then installs a CrossSiteEventHandler.
137// - When RDH receives a response, the BufferedEventHandler determines whether
138// it is a download. If so, it sends a message to the new renderer causing
139// it to cancel the request, and the download proceeds in the download
140// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34141// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32142// doesn't affect any functionality.
143// - After RDH receives a response and determines that it is safe and not a
144// download, it pauses the response to first run the old page's onunload
145// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34146// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32147// to the current RVH.
148// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
149// the ResourceDispatcherHost, who unpauses the response. Data is then sent
150// to the pending RVH.
151// - The pending renderer sends a FrameNavigate message that invokes the
152// DidNavigate method. This replaces the current RVH with the
153// pending RVH and goes back to the NORMAL RendererState.
154
155namespace {
156
157// Amount of time we wait between when a key event is received and the renderer
158// is queried for its state and pushed to the NavigationEntry.
159const int kQueryStateDelay = 5000;
160
[email protected]6ebdc9b2010-09-27 16:55:57161const int kSyncWaitDelay = 40;
162
[email protected]420ae012009-04-24 05:16:32163// If another javascript message box is displayed within
164// kJavascriptMessageExpectedDelay of a previous javascript message box being
165// dismissed, display an option to suppress future message boxes from this
166// contents.
167const int kJavascriptMessageExpectedDelay = 1000;
168
[email protected]420ae012009-04-24 05:16:32169// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51170const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32171 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17172 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32173 prefs::kWebKitJavaEnabled,
174 prefs::kWebKitJavascriptEnabled,
175 prefs::kWebKitLoadsImagesAutomatically,
176 prefs::kWebKitPluginsEnabled,
177 prefs::kWebKitUsesUniversalDetector,
178 prefs::kWebKitSerifFontFamily,
179 prefs::kWebKitSansSerifFontFamily,
180 prefs::kWebKitFixedFontFamily,
181 prefs::kWebKitDefaultFontSize,
182 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13183 prefs::kWebKitMinimumFontSize,
184 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36185 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32186 prefs::kDefaultCharset
187 // kWebKitStandardFontIsSerif needs to be added
188 // if we let users pick which font to use, serif or sans-serif when
189 // no font is specified or a CSS generic family (serif or sans-serif)
190 // is not specified.
191};
192
193const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
194
[email protected]420ae012009-04-24 05:16:32195// Returns true if the entry's transition type is FORM_SUBMIT.
196bool IsFormSubmit(const NavigationEntry* entry) {
197 return (PageTransition::StripQualifier(entry->transition_type()) ==
198 PageTransition::FORM_SUBMIT);
199}
200
201#if defined(OS_WIN)
202
203BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
204 // Note: erase is required to properly paint some widgets borders. This can
205 // be seen with textfields.
206 InvalidateRect(hwnd, NULL, TRUE);
207 return TRUE;
208}
209#endif
210
[email protected]5e369672009-11-03 23:48:30211ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16212 Profile* profile, const NavigationEntry& entry,
213 NavigationController::ReloadType reload_type) {
214 switch (reload_type) {
215 case NavigationController::RELOAD:
216 return ViewMsg_Navigate_Params::RELOAD;
217 case NavigationController::RELOAD_IGNORING_CACHE:
218 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
219 case NavigationController::NO_RELOAD:
220 break; // Fall through to rest of function.
221 }
[email protected]5e369672009-11-03 23:48:30222
223 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
224 profile->DidLastSessionExitCleanly())
225 return ViewMsg_Navigate_Params::RESTORE;
226
227 return ViewMsg_Navigate_Params::NORMAL;
228}
229
[email protected]876bc832010-09-07 16:29:54230void MakeNavigateParams(const NavigationEntry& entry,
231 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16232 NavigationController::ReloadType reload_type,
233 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34234 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54235 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00236 params->current_history_list_offset = controller.last_committed_entry_index();
237 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34238 params->url = entry.url();
239 params->referrer = entry.referrer();
240 params->transition = entry.transition_type();
241 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00242 params->navigation_type =
243 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34244 params->request_time = base::Time::Now();
245}
246
[email protected]851b1eb2010-08-09 13:32:29247class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
248 public:
249 DisabledPluginInfoBar(TabContents* tab_contents,
250 const string16& name,
251 const GURL& update_url)
252 : ConfirmInfoBarDelegate(tab_contents),
253 tab_contents_(tab_contents),
254 name_(name),
255 update_url_(update_url) {
256 tab_contents->AddInfoBar(this);
257 }
258
259 virtual int GetButtons() const {
260 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
261 }
262
[email protected]e23d3a32010-08-13 19:39:58263 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29264 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58265 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29266 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58267 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29268 return ConfirmInfoBarDelegate::GetButtonLabel(button);
269 }
270
[email protected]e23d3a32010-08-13 19:39:58271 virtual string16 GetMessageText() const {
272 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29273 }
274
[email protected]e23d3a32010-08-13 19:39:58275 virtual string16 GetLinkText() {
276 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29277 }
278
279 virtual SkBitmap* GetIcon() const {
280 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
281 IDR_INFOBAR_PLUGIN_INSTALL);
282 }
283
284 virtual bool Accept() {
285 tab_contents_->OpenURL(update_url_, GURL(),
[email protected]57b66d02010-09-30 11:24:51286 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29287 return false;
288 }
289
290 virtual bool Cancel() {
291 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
[email protected]57b66d02010-09-30 11:24:51292 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29293 return false;
294 }
295
296 virtual bool LinkClicked(WindowOpenDisposition disposition) {
297 // TODO(bauerb): Navigate to a help page explaining why we disabled
298 // the plugin, once we have one.
299 return false;
300 }
301
302 private:
303 TabContents* tab_contents_;
304 string16 name_;
305 GURL update_url_;
306};
307
[email protected]420ae012009-04-24 05:16:32308} // namespace
309
310// -----------------------------------------------------------------------------
311
[email protected]fdd61c62009-04-22 19:22:57312// static
313int TabContents::find_request_id_counter_ = -1;
314
[email protected]420ae012009-04-24 05:16:32315
[email protected]420ae012009-04-24 05:16:32316TabContents::TabContents(Profile* profile,
317 SiteInstance* site_instance,
318 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07319 const TabContents* base_tab_contents,
320 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42321 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07322 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
323 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13324 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22325 TabContentsView::Create(this))),
326 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57327 property_bag_(),
328 registrar_(),
[email protected]12802702010-07-09 19:43:09329 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
330 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57331 save_package_(),
[email protected]6db0def92010-03-02 19:55:45332 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21333 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57334 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),
[email protected]443b80e2010-12-14 00:42:23338 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
339 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34340 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34341 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57342 current_load_start_(),
343 load_state_(net::LOAD_STATE_IDLE),
344 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56345 upload_size_(0),
346 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57347 received_page_title_(false),
348 is_starred_(false),
349 contents_mime_type_(),
350 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40351 blocked_contents_(NULL),
352 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49353 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47354 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57355 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57356 find_ui_active_(false),
357 find_op_aborted_(false),
358 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12359 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12360 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08361 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57362 capturing_contents_(false),
363 is_being_destroyed_(false),
364 notify_disconnection_(false),
365 history_requests_(),
366#if defined(OS_WIN)
367 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
368#endif
369 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44370 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01371 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54372 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54373 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16374 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38375 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25376 minimum_zoom_percent_(
377 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
378 maximum_zoom_percent_(
379 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00380 temporary_zoom_settings_(false),
381 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54382 renderer_preferences_util::UpdateFromSystemSettings(
383 &renderer_preferences_, profile);
384
[email protected]9fb83e82010-07-02 18:24:55385 content_settings_delegate_.reset(
386 new TabSpecificContentSettings(this, profile));
387
[email protected]12636df2009-09-28 22:32:21388 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32389
[email protected]34ac70502009-09-25 17:07:23390 // We have the initial size of the view be based on the size of the passed in
391 // tab contents (normally a tab from the same window).
392 view_->CreateView(base_tab_contents ?
393 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32394
395 // Register for notifications about all interested prefs change.
396 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28397 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32398 if (prefs) {
399 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28400 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32401 }
402
403 // Register for notifications about URL starredness changing on any profile.
404 registrar_.Add(this, NotificationType::URLS_STARRED,
405 NotificationService::AllSources());
406 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
407 NotificationService::AllSources());
408 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
409 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09410#if defined(OS_LINUX)
411 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
412 NotificationService::AllSources());
413#endif
[email protected]420ae012009-04-24 05:16:32414
[email protected]6c32ce72010-03-08 05:18:06415 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
416 NotificationService::AllSources());
417
[email protected]79580c62010-02-02 02:36:25418 // Register for notifications about content setting changes.
419 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
420 NotificationService::AllSources());
421
[email protected]a888b29e62010-04-01 13:38:57422 // Listen for extension changes so we can update extension_for_current_page_.
423 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
424 NotificationService::AllSources());
425 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
426 NotificationService::AllSources());
427 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
428 NotificationService::AllSources());
429
[email protected]88152052010-10-01 04:05:18430 // Listen for Google URL changes
431 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
432 NotificationService::AllSources());
433
[email protected]c8865482009-07-23 20:40:10434 // Set-up the showing of the omnibox search infobar if applicable.
435 if (OmniboxSearchHint::IsEnabled(profile))
436 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35437}
initial.commit09911bf2008-07-26 23:55:29438
439TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32440 is_being_destroyed_ = true;
441
[email protected]bfe4c1582009-10-02 18:11:09442 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32443 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28444 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32445
[email protected]420ae012009-04-24 05:16:32446 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00447 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32448
[email protected]420ae012009-04-24 05:16:32449 // First cleanly close all child windows.
450 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
451 // some of these to close. CloseWindows is async, so it might get called
452 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49453 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32454
[email protected]c65e2f152010-10-14 15:30:40455 // Close all blocked contents.
456 if (blocked_contents_)
457 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13458
[email protected]420ae012009-04-24 05:16:32459 // Notify any observer that have a reference on this tab contents.
460 NotificationService::current()->Notify(
461 NotificationType::TAB_CONTENTS_DESTROYED,
462 Source<TabContents>(this),
463 NotificationService::NoDetails());
464
[email protected]1e5e74f2009-05-27 20:55:12465 // Notify any lasting InfobarDelegates that have not yet been removed that
466 // whatever infobar they were handling in this TabContents has closed,
467 // because the TabContents is going away entirely.
468 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
469 // notification may trigger infobars calls that access their delegate. (and
470 // some implementations of InfoBarDelegate do delete themselves on
471 // InfoBarClosed()).
472 for (int i = 0; i < infobar_delegate_count(); ++i) {
473 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
474 delegate->InfoBarClosed();
475 }
476 infobar_delegates_.clear();
477
[email protected]420ae012009-04-24 05:16:32478 // TODO(brettw) this should be moved to the view.
479#if defined(OS_WIN)
480 // If we still have a window handle, destroy it. GetNativeView can return
481 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42482 if (GetNativeView()) {
483 RenderViewHost* host = render_view_host();
484 if (host && host->view()) {
485 host->view()->WillWmDestroy();
486 }
[email protected]420ae012009-04-24 05:16:32487 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42488 }
[email protected]420ae012009-04-24 05:16:32489#endif
[email protected]7ab1e7d62009-10-14 23:32:01490
491 // OnCloseStarted isn't called in unit tests.
492 if (!tab_close_start_time_.is_null()) {
493 UMA_HISTOGRAM_TIMES("Tab.Close",
494 base::TimeTicks::Now() - tab_close_start_time_);
495 }
initial.commit09911bf2008-07-26 23:55:29496}
497
[email protected]d5f942ba2008-09-26 19:30:34498// static
499void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32500 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
501
502 WebPreferences pref_defaults;
503 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
504 pref_defaults.javascript_enabled);
505 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
506 pref_defaults.web_security_enabled);
507 prefs->RegisterBooleanPref(
508 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
509 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
510 pref_defaults.loads_images_automatically);
511 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
512 pref_defaults.plugins_enabled);
513 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
514 pref_defaults.dom_paste_enabled);
515 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
516 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14517 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32518 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
519 pref_defaults.text_areas_are_resizable);
520 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
521 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36522 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
523 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32524
525 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
526 IDS_ACCEPT_LANGUAGES);
527 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
528 IDS_DEFAULT_ENCODING);
529 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
530 IDS_STANDARD_FONT_IS_SERIF);
531 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
532 IDS_FIXED_FONT_FAMILY);
533 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
534 IDS_SERIF_FONT_FAMILY);
535 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
536 IDS_SANS_SERIF_FONT_FAMILY);
537 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
538 IDS_CURSIVE_FONT_FAMILY);
539 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
540 IDS_FANTASY_FONT_FAMILY);
541 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
542 IDS_DEFAULT_FONT_SIZE);
543 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
544 IDS_DEFAULT_FIXED_FONT_SIZE);
545 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
546 IDS_MINIMUM_FONT_SIZE);
547 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
548 IDS_MINIMUM_LOGICAL_FONT_SIZE);
549 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
550 IDS_USES_UNIVERSAL_DETECTOR);
551 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
552 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29553}
554
[email protected]13367f72009-07-08 16:39:02555// Returns true if contains content rendered by an extension.
556bool TabContents::HostsExtension() const {
557 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34558}
559
[email protected]cf28ec52010-04-09 22:56:34560AutoFillManager* TabContents::GetAutoFillManager() {
561 if (autofill_manager_.get() == NULL)
562 autofill_manager_.reset(new AutoFillManager(this));
563 return autofill_manager_.get();
564}
565
[email protected]6e95706d2009-04-23 22:55:01566PluginInstaller* TabContents::GetPluginInstaller() {
567 if (plugin_installer_.get() == NULL)
568 plugin_installer_.reset(new PluginInstaller(this));
569 return plugin_installer_.get();
570}
571
[email protected]1f18184a2010-07-21 19:34:49572TabContentsSSLHelper* TabContents::GetSSLHelper() {
573 if (ssl_helper_.get() == NULL)
574 ssl_helper_.reset(new TabContentsSSLHelper(this));
575 return ssl_helper_.get();
576}
577
[email protected]8cb5d5b2010-02-09 11:36:16578RenderProcessHost* TabContents::GetRenderProcessHost() const {
579 return render_manager_.current_host()->process();
580}
581
[email protected]9adb9692010-10-29 23:14:02582void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46583 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08584 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10585
[email protected]98aa0b52010-05-06 17:03:08586 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57587
[email protected]fca656c2010-02-10 20:30:10588 NotificationService::current()->Notify(
589 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
590 Source<TabContents>(this),
591 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49592}
593
[email protected]98aa0b52010-05-06 17:03:08594void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
595 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40596 return;
597
[email protected]eaa7dd182010-12-14 11:09:00598 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50599 if (!extension_service || !extension_service->is_ready())
600 return;
601
602 const Extension* extension =
603 extension_service->GetExtensionById(extension_app_id, false);
604 if (extension)
605 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40606}
607
[email protected]98aa0b52010-05-06 17:03:08608SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08609 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51610 return NULL;
611
[email protected]98aa0b52010-05-06 17:03:08612 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51613}
614
[email protected]d5f942ba2008-09-26 19:30:34615const GURL& TabContents::GetURL() const {
616 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57617 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54618 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34619}
620
[email protected]96d185d2009-04-24 03:28:54621const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55622 // Transient entries take precedence. They are used for interstitial pages
623 // that are shown on top of existing pages.
624 NavigationEntry* entry = controller_.GetTransientEntry();
625 if (entry)
626 return entry->GetTitleForDisplay(&controller_);
627
[email protected]96d185d2009-04-24 03:28:54628 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
629 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
630 if (our_dom_ui) {
631 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55632 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54633 if (!(entry && entry->IsViewSourceMode())) {
634 // Give the DOM UI the chance to override our title.
635 const string16& title = our_dom_ui->overridden_title();
636 if (!title.empty())
637 return title;
638 }
639 }
640
641 // We use the title for the last committed entry rather than a pending
642 // navigation entry. For example, when the user types in a URL, we want to
643 // keep the old page's title until the new load has committed and we get a new
644 // title.
[email protected]96d185d2009-04-24 03:28:54645 entry = controller_.GetLastCommittedEntry();
646 if (entry)
647 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54648 return EmptyString16();
649}
650
[email protected]bbbc1ef2010-02-12 18:03:41651// static
652string16 TabContents::GetDefaultTitle() {
653 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
654}
655
[email protected]d5f942ba2008-09-26 19:30:34656int32 TabContents::GetMaxPageID() {
657 if (GetSiteInstance())
658 return GetSiteInstance()->max_page_id();
659 else
660 return max_page_id_;
661}
662
663void TabContents::UpdateMaxPageID(int32 page_id) {
664 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34665 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34666 // testing.
667 if (GetSiteInstance())
668 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16669 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34670}
671
[email protected]96d185d2009-04-24 03:28:54672SiteInstance* TabContents::GetSiteInstance() const {
673 return render_manager_.current_host()->site_instance();
674}
675
[email protected]96d185d2009-04-24 03:28:54676bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15677 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54678 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15679 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01680 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54681 return true;
[email protected]8ab24cc2009-11-13 20:56:15682 }
[email protected]83e3895b2009-06-11 00:07:16683
[email protected]96d185d2009-04-24 03:28:54684 DOMUI* dom_ui = GetDOMUIForCurrentState();
685 if (dom_ui)
686 return !dom_ui->should_hide_url();
687 return true;
688}
689
[email protected]d5f942ba2008-09-26 19:30:34690SkBitmap TabContents::GetFavIcon() const {
691 // Like GetTitle(), we also want to use the favicon for the last committed
692 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57693 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47694 if (entry)
695 return entry->favicon().bitmap();
696
[email protected]ce3fa3c2009-04-20 19:55:57697 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34698 if (entry)
699 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34700 return SkBitmap();
701}
702
[email protected]0b303cc2009-09-28 22:35:15703bool TabContents::FavIconIsValid() const {
704 NavigationEntry* entry = controller_.GetTransientEntry();
705 if (entry)
706 return entry->favicon().is_valid();
707
708 entry = controller_.GetLastCommittedEntry();
709 if (entry)
710 return entry->favicon().is_valid();
711
712 return false;
713}
714
[email protected]96d185d2009-04-24 03:28:54715bool TabContents::ShouldDisplayFavIcon() {
716 // Always display a throbber during pending loads.
717 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
718 return true;
719
720 DOMUI* dom_ui = GetDOMUIForCurrentState();
721 if (dom_ui)
722 return !dom_ui->hide_favicon();
723 return true;
724}
725
[email protected]96d185d2009-04-24 03:28:54726std::wstring TabContents::GetStatusText() const {
727 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
728 return std::wstring();
729
730 switch (load_state_) {
731 case net::LOAD_STATE_WAITING_FOR_CACHE:
732 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04733 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
734 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54735 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
736 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
737 case net::LOAD_STATE_RESOLVING_HOST:
738 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
739 case net::LOAD_STATE_CONNECTING:
740 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06741 case net::LOAD_STATE_SSL_HANDSHAKE:
742 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54743 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56744 if (upload_size_)
745 return l10n_util::GetStringF(
746 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
747 static_cast<int>((100 * upload_position_) / upload_size_));
748 else
749 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54750 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
751 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
752 load_state_host_);
753 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
754 case net::LOAD_STATE_IDLE:
755 case net::LOAD_STATE_READING_RESPONSE:
756 break;
757 }
758
759 return std::wstring();
760}
761
[email protected]3c9e1872010-11-18 16:17:49762void TabContents::AddNavigationObserver(WebNavigationObserver* observer) {
763 web_navigation_observers_.AddObserver(observer);
764}
765
766void TabContents::RemoveNavigationObserver(WebNavigationObserver* observer) {
767 web_navigation_observers_.RemoveObserver(observer);
768}
769
[email protected]443b80e2010-12-14 00:42:23770void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
771 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34772 return;
773
[email protected]443b80e2010-12-14 00:42:23774 crashed_status_ = status;
775 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50776 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34777}
778
[email protected]744ef172009-10-16 21:53:46779void TabContents::PageActionStateChanged() {
780 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00781}
[email protected]ce5c4502009-05-06 16:46:11782
[email protected]d5f942ba2008-09-26 19:30:34783void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
784 if (delegate_)
785 delegate_->NavigationStateChanged(this, changed_flags);
786}
787
[email protected]96d185d2009-04-24 03:28:54788void TabContents::DidBecomeSelected() {
789 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16790 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
791 if (rwhv) {
792 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43793#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16794 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43795#endif
796 }
[email protected]96d185d2009-04-24 03:28:54797
[email protected]8cb5d5b2010-02-09 11:36:16798 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11799 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54800}
801
[email protected]1b072562010-12-13 19:37:45802void TabContents::FadeForInstant() {
803 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
804 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
805 if (rwhv)
806 rwhv->SetVisuallyDeemphasized(&whitish, true);
807}
808
809void TabContents::CancelInstantFade() {
810 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
811 if (rwhv)
812 rwhv->SetVisuallyDeemphasized(NULL, false);
813}
814
[email protected]96d185d2009-04-24 03:28:54815void TabContents::WasHidden() {
816 if (!capturing_contents()) {
817 // |render_view_host()| can be NULL if the user middle clicks a link to open
818 // a tab in then background, then closes the tab before selecting it. This
819 // is because closing the tab calls TabContents::Destroy(), which removes
820 // the |render_view_host()|; then when we actually destroy the window,
821 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16822 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
823 if (rwhv)
824 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54825 }
826
827 NotificationService::current()->Notify(
828 NotificationType::TAB_CONTENTS_HIDDEN,
829 Source<TabContents>(this),
830 NotificationService::NoDetails());
831}
832
[email protected]d5f942ba2008-09-26 19:30:34833void TabContents::Activate() {
834 if (delegate_)
835 delegate_->ActivateContents(this);
836}
837
[email protected]ea42e7782010-08-23 23:58:12838void TabContents::Deactivate() {
839 if (delegate_)
840 delegate_->DeactivateContents(this);
841}
842
[email protected]96d185d2009-04-24 03:28:54843void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16844 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
845 if (rwhv)
846 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54847}
848
849void TabContents::HideContents() {
850 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
851 // our superclass HideContents(), because some callers want to be very picky
852 // about the order in which these get called. In addition to making the code
853 // here practically impossible to understand, this also means we end up
854 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34855 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54856 WasHidden();
857}
858
[email protected]5aab5e22010-12-08 22:13:29859bool TabContents::NeedToFireBeforeUnload() {
860 // TODO(creis): Should we fire even for interstitial pages?
861 return notify_disconnection() &&
862 !showing_interstitial_page() &&
863 !render_view_host()->SuddenTerminationAllowed();
864}
865
[email protected]c0588052008-10-27 23:01:50866void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34867 WindowOpenDisposition disposition,
868 PageTransition::Type transition) {
869 if (delegate_)
[email protected]c0588052008-10-27 23:01:50870 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34871}
872
[email protected]1ccb3568d2010-02-19 10:51:16873bool TabContents::NavigateToPendingEntry(
874 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54875 return NavigateToEntry(*controller_.pending_entry(), reload_type);
876}
[email protected]96d185d2009-04-24 03:28:54877
[email protected]876bc832010-09-07 16:29:54878bool TabContents::NavigateToEntry(
879 const NavigationEntry& entry,
880 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54881 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
882 if (!dest_render_view_host)
883 return false; // Unable to create the desired render view host.
884
[email protected]770dd8b2010-05-24 18:11:39885 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
886 dest_render_view_host->EnablePreferredSizeChangedMode(
887 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
888 }
[email protected]9fb325e2010-05-06 18:23:24889
[email protected]05fdd492010-11-15 17:52:07890 // For security, we should never send non-DOM-UI URLs to a DOM UI renderer.
891 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58892 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40893 bool is_allowed_in_dom_ui_renderer =
[email protected]05fdd492010-11-15 17:52:07894 DOMUIFactory::IsURLAcceptableForDOMUI(profile(), entry.url());
[email protected]54ec6472010-04-09 19:39:58895 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40896 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58897
[email protected]96d185d2009-04-24 03:28:54898 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12899 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32900 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00901 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
902 dest_render_view_host,
903 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32904 }
[email protected]96d185d2009-04-24 03:28:54905
906 // Used for page load time metrics.
907 current_load_start_ = base::TimeTicks::Now();
908
909 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34910 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54911 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04912 if (delegate_) {
913 navigate_params.extra_headers =
914 delegate_->GetNavigationHeaders(navigate_params.url);
915 }
[email protected]056de2d2009-06-26 16:41:34916 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54917
918 if (entry.page_id() == -1) {
919 // HACK!! This code suppresses javascript: URLs from being added to
920 // session history, which is what we want to do for javascript: URLs that
921 // do not generate content. What we really need is a message from the
922 // renderer telling us that a new page was not created. The same message
923 // could be used for mailto: URLs and the like.
924 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
925 return false;
926 }
927
[email protected]3c9e1872010-11-18 16:17:49928 // Notify observers about navigation.
929 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
930 NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54931
[email protected]1ccb3568d2010-02-19 10:51:16932 if (reload_type != NavigationController::NO_RELOAD &&
933 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48934 FaviconService* favicon_service =
935 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
936 if (favicon_service)
937 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54938 }
939
[email protected]d5f942ba2008-09-26 19:30:34940 return true;
941}
942
[email protected]96d185d2009-04-24 03:28:54943void TabContents::Stop() {
944 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09945 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54946}
947
[email protected]96d185d2009-04-24 03:28:54948void TabContents::DisassociateFromPopupCount() {
949 render_view_host()->DisassociateFromPopupCount();
950}
951
952TabContents* TabContents::Clone() {
953 // We create a new SiteInstance so that the new tab won't share processes
954 // with the old one. This can be changed in the future if we need it to share
955 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32956 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54957 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07958 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54959 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08960 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08961 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54962 return tc;
963}
964
[email protected]4d677202009-07-19 07:37:12965void TabContents::ShowPageInfo(const GURL& url,
966 const NavigationEntry::SSLStatus& ssl,
967 bool show_history) {
968 if (!delegate_)
969 return;
970
[email protected]bb678332009-07-21 00:15:50971 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12972}
973
initial.commit09911bf2008-07-26 23:55:29974ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28975 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29976 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28977 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29978 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44979
980 if (child_windows_.size() == 1) {
981 window->ShowConstrainedWindow();
982 BlockTabContent(true);
983 }
984
initial.commit09911bf2008-07-26 23:55:29985 return window;
986}
987
[email protected]fa1cf0b82010-01-15 21:49:44988void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55989 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45990 // 70% opaque grey.
991 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55992 if (rwhv)
[email protected]1b072562010-12-13 19:37:45993 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44994 render_view_host()->set_ignore_input_events(blocked);
995 if (delegate_)
996 delegate_->SetTabContentBlocked(this, blocked);
997}
998
initial.commit09911bf2008-07-26 23:55:29999void TabContents::AddNewContents(TabContents* new_contents,
1000 WindowOpenDisposition disposition,
1001 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:291002 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:401003 if (all_contents_blocked_) {
1004 if (!blocked_contents_)
1005 blocked_contents_ = new BlockedContentContainer(this);
1006 blocked_contents_->AddTabContents(
1007 new_contents, disposition, initial_pos, user_gesture);
1008 return;
1009 }
1010
initial.commit09911bf2008-07-26 23:55:291011 if (!delegate_)
1012 return;
1013
[email protected]35f7d212009-04-29 21:19:271014 if ((disposition == NEW_POPUP) && !user_gesture &&
1015 !CommandLine::ForCurrentProcess()->HasSwitch(
1016 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:221017 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:311018 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:291019 delegate_->GetConstrainingContents(this)->AddPopup(
1020 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:311021 } else {
[email protected]0aa55312008-10-17 21:53:081022 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:291023 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1024 user_gesture);
[email protected]7f37dd92009-09-15 16:35:491025 NotificationService::current()->Notify(
1026 NotificationType::TAB_ADDED,
1027 Source<TabContentsDelegate>(delegate_),
1028 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291029 }
initial.commit09911bf2008-07-26 23:55:291030
[email protected]8cc8d492010-02-02 10:40:491031 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401032 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291033}
1034
[email protected]bcd9dc42010-01-23 16:38:181035bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201036 bool is_js_code, const std::string& code_string,
1037 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511038 RenderViewHost* host = render_view_host();
1039 if (!host)
1040 return false;
1041
1042 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171043 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511044 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351045}
1046
[email protected]96d185d2009-04-24 03:28:541047void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491048 if (is_being_destroyed_)
1049 return;
[email protected]9fb83e82010-07-02 18:24:551050 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491051 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401052 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541053}
1054
[email protected]5c9e97a2009-09-09 23:48:301055gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541056 return view_->GetContentNativeView();
1057}
1058
1059gfx::NativeView TabContents::GetNativeView() const {
1060 return view_->GetNativeView();
1061}
1062
1063void TabContents::GetContainerBounds(gfx::Rect *out) const {
1064 view_->GetContainerBounds(out);
1065}
1066
1067void TabContents::Focus() {
1068 view_->Focus();
1069}
1070
[email protected]90daadb42009-06-08 21:27:281071void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541072 if (showing_interstitial_page()) {
1073 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1074 return;
1075 }
[email protected]96d185d2009-04-24 03:28:541076 render_view_host()->SetInitialFocus(reverse);
1077}
1078
1079bool TabContents::FocusLocationBarByDefault() {
1080 DOMUI* dom_ui = GetDOMUIForCurrentState();
1081 if (dom_ui)
1082 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431083 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251084 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431085 return true;
[email protected]96d185d2009-04-24 03:28:541086 return false;
1087}
1088
[email protected]a26dc362010-04-23 01:48:581089void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381090 if (delegate())
[email protected]a26dc362010-04-23 01:48:581091 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381092}
1093
[email protected]616ed5a2008-11-21 22:27:241094void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321095 if (delegate_ && !delegate_->infobars_enabled()) {
1096 delegate->InfoBarClosed();
1097 return;
1098 }
1099
[email protected]616ed5a2008-11-21 22:27:241100 // Look through the existing InfoBarDelegates we have for a match. If we've
1101 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051102 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451103 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1104 // Tell the new infobar to close so that it can clean itself up.
1105 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241106 return;
[email protected]6d27a7b2009-12-18 23:25:451107 }
[email protected]616ed5a2008-11-21 22:27:241108 }
1109
1110 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561111 NotificationService::current()->Notify(
1112 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1113 Source<TabContents>(this),
1114 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241115
1116 // Add ourselves as an observer for navigations the first time a delegate is
1117 // added. We use this notification to expire InfoBars that need to expire on
1118 // page transitions.
1119 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561120 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571121 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241122 }
1123}
1124
1125void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321126 if (delegate_ && !delegate_->infobars_enabled()) {
1127 return;
1128 }
1129
[email protected]616ed5a2008-11-21 22:27:241130 std::vector<InfoBarDelegate*>::iterator it =
1131 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1132 if (it != infobar_delegates_.end()) {
1133 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561134 NotificationService::current()->Notify(
1135 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1136 Source<TabContents>(this),
1137 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241138
[email protected]cdadf6f2010-08-20 16:36:081139 // Just to be safe, make sure the delegate was not removed by an observer.
1140 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1141 if (it != infobar_delegates_.end()) {
1142 infobar_delegates_.erase(it);
1143 // Remove ourselves as an observer if we are tracking no more InfoBars.
1144 if (infobar_delegates_.empty()) {
1145 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1146 Source<NavigationController>(&controller_));
1147 }
1148 } else {
1149 // If you hit this NOTREACHED, please comment in bug
1150 // http://crbug.com/50428 how you got there.
1151 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031152 }
[email protected]616ed5a2008-11-21 22:27:241153 }
1154}
[email protected]3edd9522009-03-04 22:19:411155
[email protected]f81821c2009-08-07 01:29:471156void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1157 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321158 if (delegate_ && !delegate_->infobars_enabled()) {
1159 new_delegate->InfoBarClosed();
1160 return;
1161 }
1162
[email protected]f81821c2009-08-07 01:29:471163 std::vector<InfoBarDelegate*>::iterator it =
1164 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1165 DCHECK(it != infobar_delegates_.end());
1166
1167 // Notify the container about the change of plans.
1168 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1169 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1170 old_delegate, new_delegate));
1171 NotificationService::current()->Notify(
1172 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1173 Source<TabContents>(this),
1174 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1175
[email protected]cdadf6f2010-08-20 16:36:081176 // Just to be safe, make sure the delegate was not removed by an observer.
1177 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1178 if (it != infobar_delegates_.end()) {
1179 // Remove the old one.
1180 infobar_delegates_.erase(it);
1181 } else {
1182 // If you hit this NOTREACHED, please comment in bug
1183 // http://crbug.com/50428 how you got there.
1184 NOTREACHED();
1185 }
[email protected]f81821c2009-08-07 01:29:471186
1187 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081188 DCHECK(find(infobar_delegates_.begin(),
1189 infobar_delegates_.end(), new_delegate) ==
1190 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471191 infobar_delegates_.push_back(new_delegate);
1192}
1193
[email protected]20ede072009-10-06 00:28:351194bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271195 if (showing_interstitial_page())
1196 return false;
1197
[email protected]c8f74942010-09-03 10:04:141198 // Do not show bookmarks bar if bookmarks aren't enabled.
1199 if (!browser_defaults::bookmarks_enabled)
1200 return false;
1201
[email protected]96d185d2009-04-24 03:28:541202 // See GetDOMUIForCurrentState() comment for more info. This case is very
1203 // similar, but for non-first loads, we want to use the committed entry. This
1204 // is so the bookmarks bar disappears at the same time the page does.
1205 if (controller_.GetLastCommittedEntry()) {
1206 // Not the first load, always use the committed DOM UI.
[email protected]d6219912010-11-17 19:47:371207 return (render_manager_.dom_ui() == NULL) ?
1208 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541209 }
1210
1211 // When it's the first load, we know either the pending one or the committed
1212 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1213 // of them will be valid, so we can just check both.
1214 if (render_manager_.pending_dom_ui())
1215 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
[email protected]d6219912010-11-17 19:47:371216 return (render_manager_.dom_ui() == NULL) ?
1217 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541218}
1219
[email protected]3edd9522009-03-04 22:19:411220void TabContents::ToolbarSizeChanged(bool is_animating) {
1221 TabContentsDelegate* d = delegate();
1222 if (d)
1223 d->ToolbarSizeChanged(this, is_animating);
1224}
[email protected]616ed5a2008-11-21 22:27:241225
[email protected]fc6fb7fb2009-11-07 02:35:041226bool TabContents::CanDownload(int request_id) {
1227 TabContentsDelegate* d = delegate();
1228 if (d)
1229 return d->CanDownload(request_id);
1230 return true;
1231}
1232
[email protected]d5f942ba2008-09-26 19:30:341233void TabContents::OnStartDownload(DownloadItem* download) {
1234 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341235
1236 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311237 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341238
[email protected]5b928b62010-08-03 11:46:511239 if (tab_contents && tab_contents->delegate())
1240 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411241}
[email protected]3edd9522009-03-04 22:19:411242
[email protected]d5f942ba2008-09-26 19:30:341243void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371244 ConstrainedWindowList::iterator i(
1245 std::find(child_windows_.begin(), child_windows_.end(), window));
1246 bool removed_topmost_window = i == child_windows_.begin();
1247 if (i != child_windows_.end())
1248 child_windows_.erase(i);
1249 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441250 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371251 } else {
1252 if (removed_topmost_window)
1253 child_windows_[0]->ShowConstrainedWindow();
1254 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441255 }
[email protected]66ba4932009-06-04 19:22:131256}
[email protected]d5f942ba2008-09-26 19:30:341257
[email protected]c65e2f152010-10-14 15:30:401258void TabContents::WillCloseBlockedContentContainer(
1259 BlockedContentContainer* container) {
1260 DCHECK(blocked_contents_ == container);
1261 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491262 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341263}
1264
[email protected]d5f942ba2008-09-26 19:30:341265void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351266#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061267 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351268#endif
[email protected]d5f942ba2008-09-26 19:30:341269}
1270
[email protected]c1dc9f132009-11-20 23:13:211271void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121272 bool forward_direction,
1273 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211274 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011275 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211276 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531277 string16 last_search_prepopulate_text =
1278 FindBarState::GetLastPrepopulateText(profile());
1279
[email protected]87fae512009-12-11 02:20:211280 // Try the last thing we searched for on this tab, then the last thing
1281 // searched for on any tab.
1282 if (!previous_find_text_.empty())
1283 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531284 else if (!last_search_prepopulate_text.empty())
1285 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211286 else
[email protected]e491f1c2009-05-22 20:28:121287 return;
[email protected]e491f1c2009-05-22 20:28:121288 }
[email protected]6e95706d2009-04-23 22:55:011289
[email protected]101c90e2009-10-26 21:14:441290 // Keep track of the previous search.
1291 previous_find_text_ = find_text_;
1292
[email protected]6e95706d2009-04-23 22:55:011293 // This is a FindNext operation if we are searching for the same text again,
1294 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1295 // exception to this is if the Find was aborted (then we don't want FindNext
1296 // because the highlighting has been cleared and we need it to reappear). We
1297 // therefore treat FindNext after an aborted Find operation as a full fledged
1298 // Find.
[email protected]c1dc9f132009-11-20 23:13:211299 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121300 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011301 !find_op_aborted_;
1302 if (!find_next)
1303 current_find_request_id_ = find_request_id_counter_++;
1304
[email protected]c1dc9f132009-11-20 23:13:211305 if (!search_string.empty())
1306 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121307 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011308
1309 find_op_aborted_ = false;
1310
1311 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531312 FindBarState* find_bar_state = profile()->GetFindBarState();
1313 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011314 render_view_host()->StartFinding(current_find_request_id_,
1315 find_text_,
1316 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121317 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011318 find_next);
1319}
1320
[email protected]5bc8fe92010-03-11 18:19:001321void TabContents::StopFinding(
1322 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011323 if (selection_action == FindBarController::kClearSelection) {
1324 // kClearSelection means the find string has been cleared by the user, but
1325 // the UI has not been dismissed. In that case we want to clear the
1326 // previously remembered search (http://crbug.com/42639).
1327 previous_find_text_ = string16();
1328 } else {
[email protected]2d2dffc2009-06-09 21:41:001329 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011330 if (!find_text_.empty())
1331 previous_find_text_ = find_text_;
1332 }
[email protected]101c90e2009-10-26 21:14:441333 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011334 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121335 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001336 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011337}
1338
[email protected]420ae012009-04-24 05:16:321339void TabContents::OnSavePage() {
1340 // If we can not save the page, try to download it.
1341 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1342 DownloadManager* dlm = profile()->GetDownloadManager();
1343 const GURL& current_page_url = GetURL();
1344 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221345 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321346 return;
1347 }
1348
1349 Stop();
1350
1351 // Create the save package and possibly prompt the user for the name to save
1352 // the page as. The user prompt is an asynchronous operation that runs on
1353 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221354 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321355 save_package_->GetSaveInfo();
1356}
1357
1358// Used in automated testing to bypass prompting the user for file names.
1359// Instead, the names and paths are hard coded rather than running them through
1360// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111361bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321362 SavePackage::SavePackageType save_type) {
1363 // Stop the page from navigating.
1364 Stop();
1365
[email protected]828cabe2009-09-26 22:47:111366 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591367 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321368}
1369
[email protected]89d6e6e2009-12-03 23:06:511370void TabContents::EmailPageLocation() {
1371 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1372 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1373 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1374 title + "&body=%0A%0A" + page_url;
1375 platform_util::OpenExternal(GURL(mailto));
1376}
1377
[email protected]420ae012009-04-24 05:16:321378void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161379 if (CommandLine::ForCurrentProcess()->HasSwitch(
1380 switches::kEnablePrintPreview)) {
1381 if (showing_interstitial_page())
1382 return;
1383 render_view_host()->PrintPreview();
1384 } else {
1385 PrintNow();
1386 }
[email protected]420ae012009-04-24 05:16:321387}
1388
1389bool TabContents::PrintNow() {
1390 // We can't print interstitial page for now.
1391 if (showing_interstitial_page())
1392 return false;
1393
1394 return render_view_host()->PrintPages();
1395}
1396
[email protected]82270452009-06-19 15:58:011397void TabContents::PrintingDone(int document_cookie, bool success) {
1398 render_view_host()->PrintingDone(document_cookie, success);
1399}
1400
[email protected]420ae012009-04-24 05:16:321401bool TabContents::IsActiveEntry(int32 page_id) {
1402 NavigationEntry* active_entry = controller_.GetActiveEntry();
1403 return (active_entry != NULL &&
1404 active_entry->site_instance() == GetSiteInstance() &&
1405 active_entry->page_id() == page_id);
1406}
1407
[email protected]b2fe07d12010-02-09 14:38:081408void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161409 set_encoding(encoding);
1410 render_view_host()->SetPageEncoding(encoding);
1411}
1412
[email protected]b2fe07d12010-02-09 14:38:081413void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161414 reset_encoding();
1415 render_view_host()->ResetPageEncodingToDefault();
1416}
1417
1418void TabContents::WindowMoveOrResizeStarted() {
1419 render_view_host()->WindowMoveOrResizeStarted();
1420}
1421
[email protected]c65e2f152010-10-14 15:30:401422void TabContents::SetAllContentsBlocked(bool value) {
1423 if (all_contents_blocked_ == value)
1424 return;
1425
1426 all_contents_blocked_ = value;
1427 if (!all_contents_blocked_ && blocked_contents_) {
1428 std::vector<TabContents*> blocked;
1429 blocked_contents_->GetBlockedContents(&blocked);
1430 for (size_t i = 0; i < blocked.size(); ++i)
1431 blocked_contents_->LaunchForContents(blocked[i]);
1432 }
1433}
1434
[email protected]3f8eb7f2009-10-02 23:58:051435void TabContents::LogNewTabTime(const std::string& event_name) {
1436 // Not all new tab pages get timed. In those cases, we don't have a
1437 // new_tab_start_time_.
1438 if (new_tab_start_time_.is_null())
1439 return;
1440
1441 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441442 MetricEventDurationDetails details(event_name,
1443 static_cast<int>(duration.InMilliseconds()));
1444
[email protected]7ab1e7d62009-10-14 23:32:011445 if (event_name == "Tab.NewTabScriptStart") {
1446 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1447 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1448 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1449 } else if (event_name == "Tab.NewTabOnload") {
1450 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051451 // The new tab page has finished loading; reset it.
1452 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441453 } else {
1454 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051455 }
[email protected]84abba62009-10-07 17:01:441456 NotificationService::current()->Notify(
1457 NotificationType::METRIC_EVENT_DURATION,
1458 Source<TabContents>(this),
1459 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051460}
1461
[email protected]7ab1e7d62009-10-14 23:32:011462void TabContents::OnCloseStarted() {
1463 if (tab_close_start_time_.is_null())
1464 tab_close_start_time_ = base::TimeTicks::Now();
1465}
1466
[email protected]46624bf2010-06-09 16:04:191467bool TabContents::ShouldAcceptDragAndDrop() const {
1468#if defined(OS_CHROMEOS)
1469 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1470 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201471 if (delegate() && delegate()->IsPopup(this))
1472 return false;
1473 return true;
[email protected]46624bf2010-06-09 16:04:191474#else
1475 return true;
1476#endif
1477}
1478
[email protected]ec0b6c42010-08-26 03:16:581479void TabContents::UpdateHistoryForNavigation(
1480 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1481 if (profile()->IsOffTheRecord())
1482 return;
1483
1484 // Add to history service.
1485 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1486 if (hs)
1487 hs->AddPage(*add_page_args);
1488}
1489
1490void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1491 if (profile()->IsOffTheRecord())
1492 return;
1493
1494 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1495 if (hs)
1496 hs->SetPageTitle(entry.virtual_url(), entry.title());
1497}
1498
[email protected]d0b8d092010-10-25 04:05:171499double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251500 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1501 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171502 return 0;
[email protected]b75b8292010-10-01 07:28:251503
1504 double zoom_level;
1505 if (temporary_zoom_settings_) {
1506 zoom_level = zoom_map->GetTemporaryZoomLevel(
1507 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1508 } else {
1509 zoom_level = zoom_map->GetZoomLevel(GetURL());
1510 }
[email protected]d0b8d092010-10-25 04:05:171511 return zoom_level;
1512}
[email protected]b75b8292010-10-01 07:28:251513
[email protected]d0b8d092010-10-25 04:05:171514int TabContents::GetZoomPercent(bool* enable_increment,
1515 bool* enable_decrement) {
1516 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251517 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171518 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251519 *enable_decrement = percent > minimum_zoom_percent_;
1520 *enable_increment = percent < maximum_zoom_percent_;
1521 return percent;
1522}
1523
[email protected]96d185d2009-04-24 03:28:541524// Notifies the RenderWidgetHost instance about the fact that the page is
1525// loading, or done loading and calls the base implementation.
1526void TabContents::SetIsLoading(bool is_loading,
1527 LoadNotificationDetails* details) {
1528 if (is_loading == is_loading_)
1529 return;
1530
1531 if (!is_loading) {
1532 load_state_ = net::LOAD_STATE_IDLE;
1533 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561534 upload_size_ = 0;
1535 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541536 }
1537
1538 render_manager_.SetIsLoading(is_loading);
1539
1540 is_loading_ = is_loading;
1541 waiting_for_response_ = is_loading;
1542
[email protected]6ebdc9b2010-09-27 16:55:571543 if (delegate_)
1544 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351545 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541546
1547 NotificationType type = is_loading ? NotificationType::LOAD_START :
1548 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111549 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541550 if (details)
1551 det = Details<LoadNotificationDetails>(details);
1552 NotificationService::current()->Notify(type,
1553 Source<NavigationController>(&controller_),
1554 det);
1555}
1556
[email protected]b6c874582009-05-08 19:38:311557void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291558 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061559 // A page can't spawn popups (or do anything else, either) until its load
1560 // commits, so when we reach here, the popup was spawned by the
1561 // NavigationController's last committed entry, not the active entry. For
1562 // example, if a page opens a popup in an onunload() handler, then the active
1563 // entry is the page to be loaded as we navigate away from the unloading
1564 // page. For this reason, we can't use GetURL() to get the opener URL,
1565 // because it returns the active entry.
1566 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1567 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1568
1569 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491570 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091571 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491572 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1573 } else {
[email protected]c65e2f152010-10-14 15:30:401574 if (!blocked_contents_)
1575 blocked_contents_ = new BlockedContentContainer(this);
1576 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1577 true);
[email protected]55126132010-08-19 14:53:281578 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1579 std::string());
[email protected]8cc8d492010-02-02 10:40:491580 }
[email protected]b9681312008-11-07 00:08:261581}
[email protected]616ed5a2008-11-21 22:27:241582
[email protected]616ed5a2008-11-21 22:27:241583void TabContents::ExpireInfoBars(
1584 const NavigationController::LoadCommittedDetails& details) {
1585 // Only hide InfoBars when the user has done something that makes the main
1586 // frame load. We don't want various automatic or subframe navigations making
1587 // it disappear.
1588 if (!details.is_user_initiated_main_frame_load())
1589 return;
1590
[email protected]f86a07022008-11-25 01:06:051591 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241592 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081593 if (!delegate) {
1594 // If you hit this NOTREACHED, please comment in bug
1595 // http://crbug.com/50428 how you got there.
1596 NOTREACHED();
1597 continue;
1598 }
1599
[email protected]f86a07022008-11-25 01:06:051600 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241601 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241602 }
1603}
[email protected]fdd61c62009-04-22 19:22:571604
[email protected]96d185d2009-04-24 03:28:541605DOMUI* TabContents::GetDOMUIForCurrentState() {
1606 // When there is a pending navigation entry, we want to use the pending DOMUI
1607 // that goes along with it to control the basic flags. For example, we want to
1608 // show the pending URL in the URL bar, so we want the display_url flag to
1609 // be from the pending entry.
1610 //
1611 // The confusion comes because there are multiple possibilities for the
1612 // initial load in a tab as a side effect of the way the RenderViewHostManager
1613 // works.
1614 //
1615 // - For the very first tab the load looks "normal". The new tab DOM UI is
1616 // the pending one, and we want it to apply here.
1617 //
1618 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1619 // get switched to the one previously associated with the new tab pages.
1620 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1621 // have a committed DOM UI in this case.
1622 //
1623 // This condition handles all of these cases:
1624 //
1625 // - First load in first tab: no committed nav entry + pending nav entry +
1626 // pending dom ui:
1627 // -> Use pending DOM UI if any.
1628 //
1629 // - First load in second tab: no committed nav entry + pending nav entry +
1630 // no pending DOM UI:
1631 // -> Use the committed DOM UI if any.
1632 //
1633 // - Second navigation in any tab: committed nav entry + pending nav entry:
1634 // -> Use pending DOM UI if any.
1635 //
1636 // - Normal state with no load: committed nav entry + no pending nav entry:
1637 // -> Use committed DOM UI.
1638 if (controller_.pending_entry() &&
1639 (controller_.GetLastCommittedEntry() ||
1640 render_manager_.pending_dom_ui()))
1641 return render_manager_.pending_dom_ui();
1642 return render_manager_.dom_ui();
1643}
[email protected]420ae012009-04-24 05:16:321644
1645void TabContents::DidNavigateMainFramePostCommit(
1646 const NavigationController::LoadCommittedDetails& details,
1647 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441648 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1649 // If this is a window.open navigation, use the same DOMUI as the renderer
1650 // that opened the window, as long as both renderers have the same
1651 // privileges.
[email protected]583d45c12010-08-31 02:48:121652 if (opener_dom_ui_type_ ==
1653 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441654 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1655 // dom_ui might be NULL if the URL refers to a non-existent extension.
1656 if (dom_ui) {
1657 render_manager_.SetDOMUIPostCommit(dom_ui);
1658 dom_ui->RenderViewCreated(render_view_host());
1659 }
1660 }
1661 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1662 }
1663
[email protected]420ae012009-04-24 05:16:321664 if (details.is_user_initiated_main_frame_load()) {
1665 // Clear the status bubble. This is a workaround for a bug where WebKit
1666 // doesn't let us know that the cursor left an element during a
1667 // transition (this is also why the mouse cursor remains as a hand after
1668 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1669 // clear the bubble when a user navigates to a named anchor in the same
1670 // page.
1671 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321672 }
1673
1674 // The keyword generator uses the navigation entries, so must be called after
1675 // the commit.
1676 GenerateKeywordIfNecessary(params);
1677
1678 // Allow the new page to set the title again.
1679 received_page_title_ = false;
1680
1681 // Get the favicon, either from history or request it from the net.
1682 fav_icon_helper_.FetchFavIcon(details.entry->url());
1683
[email protected]0de80162010-02-03 04:52:351684 // Clear all page actions, blocked content notifications and browser actions
1685 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141686 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:001687 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:081688 if (service) {
1689 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571690 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081691 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521692 if (browser_action) {
1693 browser_action->ClearAllValuesForTab(controller().session_id().id());
1694 NotificationService::current()->Notify(
1695 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571696 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521697 NotificationService::NoDetails());
1698 }
[email protected]92c6f9b92009-10-24 04:35:081699
[email protected]5d246db22009-10-27 06:17:571700 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521701 service->extensions()->at(i)->page_action();
1702 if (page_action) {
1703 page_action->ClearAllValuesForTab(controller().session_id().id());
1704 PageActionStateChanged();
1705 }
[email protected]92c6f9b92009-10-24 04:35:081706 }
[email protected]aece2c7f2009-08-27 20:43:171707 }
[email protected]0de80162010-02-03 04:52:351708
1709 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401710 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341711 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401712 blocked_contents_->Destroy();
1713 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351714 }
1715
1716 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411717 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551718 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471719
1720 // Once the main frame is navigated, we're no longer considered to have
1721 // displayed insecure content.
1722 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171723 }
[email protected]ce5c4502009-05-06 16:46:111724
[email protected]8cc8d492010-02-02 10:40:491725 // Close constrained windows if necessary.
1726 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1727 details.previous_url, details.entry->url()))
1728 CloseConstrainedWindows();
1729
[email protected]420ae012009-04-24 05:16:321730 // Update the starred state.
1731 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531732
[email protected]3c9e1872010-11-18 16:17:491733 // Notify observers about navigation.
1734 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1735 DidNavigateMainFramePostCommit(details, params));
1736
[email protected]c07c9752010-03-12 05:57:531737 // Clear the cache of forms in AutoFill.
1738 if (autofill_manager_.get())
1739 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321740}
1741
1742void TabContents::DidNavigateAnyFramePostCommit(
1743 RenderViewHost* render_view_host,
1744 const NavigationController::LoadCommittedDetails& details,
1745 const ViewHostMsg_FrameNavigate_Params& params) {
1746 // If we navigate, start showing messages again. This does nothing to prevent
1747 // a malicious script from spamming messages, since the script could just
1748 // reload the page to stop blocking.
1749 suppress_javascript_messages_ = false;
1750
[email protected]3c9e1872010-11-18 16:17:491751 // Notify observers about navigation.
1752 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1753 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551754
1755 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581756 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321757}
1758
[email protected]8cc8d492010-02-02 10:40:491759void TabContents::CloseConstrainedWindows() {
1760 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321761 // We use indices instead of iterators in case CloseWindow does something
1762 // that may invalidate an iterator.
1763 int size = static_cast<int>(child_windows_.size());
1764 for (int i = size - 1; i >= 0; --i) {
1765 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441766 if (window) {
[email protected]420ae012009-04-24 05:16:321767 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441768 BlockTabContent(false);
1769 }
[email protected]420ae012009-04-24 05:16:321770 }
1771}
1772
1773void TabContents::UpdateStarredStateForCurrentURL() {
1774 BookmarkModel* model = profile()->GetBookmarkModel();
1775 const bool old_state = is_starred_;
1776 is_starred_ = (model && model->IsBookmarked(GetURL()));
1777
1778 if (is_starred_ != old_state && delegate())
1779 delegate()->URLStarredChanged(this, is_starred_);
1780}
1781
1782void TabContents::UpdateAlternateErrorPageURL() {
1783 GURL url = GetAlternateErrorPageURL();
1784 render_view_host()->SetAlternateErrorPageURL(url);
1785}
1786
1787void TabContents::UpdateWebPreferences() {
1788 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1789}
1790
[email protected]d0b8d092010-10-25 04:05:171791void TabContents::UpdateZoomLevel() {
1792 render_view_host()->SetZoomLevel(GetZoomLevel());
1793}
1794
[email protected]420ae012009-04-24 05:16:321795void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1796 RenderViewHost* rvh) {
1797 // If we are creating a RVH for a restored controller, then we might
1798 // have more page IDs than the SiteInstance's current max page ID. We must
1799 // make sure that the max page ID is larger than any restored page ID.
1800 // Note that it is ok for conflicting page IDs to exist in another tab
1801 // (i.e., NavigationController), but if any page ID is larger than the max,
1802 // the back/forward list will get confused.
1803 int max_restored_page_id = controller_.max_restored_page_id();
1804 if (max_restored_page_id > 0) {
1805 int curr_max_page_id = site_instance->max_page_id();
1806 if (max_restored_page_id > curr_max_page_id) {
1807 // Need to update the site instance immediately.
1808 site_instance->UpdateMaxPageID(max_restored_page_id);
1809
1810 // Also tell the renderer to update its internal representation. We
1811 // need to reserve enough IDs to make all restored page IDs less than
1812 // the max.
1813 if (curr_max_page_id < 0)
1814 curr_max_page_id = 0;
1815 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1816 }
1817 }
1818}
1819
[email protected]ec0b6c42010-08-26 03:16:581820scoped_refptr<history::HistoryAddPageArgs>
1821TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541822 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471823 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321824 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581825 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1826 new history::HistoryAddPageArgs(
1827 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1828 params.redirects, params.transition, history::SOURCE_BROWSED,
1829 details.did_replace_entry));
1830 if (PageTransition::IsMainFrame(params.transition) &&
1831 virtual_url != params.url) {
1832 // Hack on the "virtual" URL so that it will appear in history. For some
1833 // types of URLs, we will display a magic URL that is different from where
1834 // the page is actually navigated. We want the user to see in history what
1835 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1836 // only applies to the main frame, as the virtual URL doesn't apply to
1837 // sub-frames.
1838 add_page_args->url = virtual_url;
1839 if (!add_page_args->redirects.empty())
1840 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321841 }
[email protected]ec0b6c42010-08-26 03:16:581842 return add_page_args;
[email protected]420ae012009-04-24 05:16:321843}
1844
1845bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1846 const std::wstring& title) {
1847 // For file URLs without a title, use the pathname instead. In the case of a
1848 // synthesized title, we don't want the update to count toward the "one set
1849 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251850 string16 final_title;
[email protected]420ae012009-04-24 05:16:321851 bool explicit_set;
1852 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251853 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321854 explicit_set = false; // Don't count synthetic titles toward the set limit.
1855 } else {
[email protected]e53668962010-06-23 15:35:251856 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321857 explicit_set = true;
1858 }
1859
[email protected]e53668962010-06-23 15:35:251860 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321861 return false; // Nothing changed, don't bother.
1862
[email protected]e53668962010-06-23 15:35:251863 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321864
[email protected]ec0b6c42010-08-26 03:16:581865 if (!received_page_title_) {
1866 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321867 received_page_title_ = explicit_set;
1868 }
1869
1870 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251871 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321872
[email protected]cbc0e1b2010-04-12 18:33:041873 NotificationService::current()->Notify(
1874 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1875 Source<TabContents>(this),
1876 NotificationService::NoDetails());
1877
[email protected]420ae012009-04-24 05:16:321878 return true;
1879}
1880
1881void TabContents::NotifySwapped() {
1882 // After sending out a swap notification, we need to send a disconnect
1883 // notification so that clients that pick up a pointer to |this| can NULL the
1884 // pointer. See Bug 1230284.
1885 notify_disconnection_ = true;
1886 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341887 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221888 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321889 NotificationService::NoDetails());
1890}
1891
1892void TabContents::NotifyConnected() {
1893 notify_disconnection_ = true;
1894 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341895 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221896 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321897 NotificationService::NoDetails());
1898}
1899
1900void TabContents::NotifyDisconnected() {
1901 if (!notify_disconnection_)
1902 return;
1903
1904 notify_disconnection_ = false;
1905 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341906 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221907 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321908 NotificationService::NoDetails());
1909}
1910
1911void TabContents::GenerateKeywordIfNecessary(
1912 const ViewHostMsg_FrameNavigate_Params& params) {
1913 if (!params.searchable_form_url.is_valid())
1914 return;
1915
1916 if (profile()->IsOffTheRecord())
1917 return;
1918
1919 int last_index = controller_.last_committed_entry_index();
1920 // When there was no previous page, the last index will be 0. This is
1921 // normally due to a form submit that opened in a new tab.
1922 // TODO(brettw) bug 916126: we should support keywords when form submits
1923 // happen in new tabs.
1924 if (last_index <= 0)
1925 return;
1926 const NavigationEntry* previous_entry =
1927 controller_.GetEntryAtIndex(last_index - 1);
1928 if (IsFormSubmit(previous_entry)) {
1929 // Only generate a keyword if the previous page wasn't itself a form
1930 // submit.
1931 return;
1932 }
1933
1934 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1935 previous_entry->user_typed_url() : previous_entry->url();
1936 std::wstring keyword =
1937 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1938 if (keyword.empty())
1939 return;
1940
1941 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1942 if (!url_model)
1943 return;
1944
1945 if (!url_model->loaded()) {
1946 url_model->Load();
1947 return;
1948 }
1949
1950 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191951 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321952 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1953 return;
1954
1955 if (current_url) {
1956 if (current_url->originating_url().is_valid()) {
1957 // The existing keyword was generated from an OpenSearch description
1958 // document, don't regenerate.
1959 return;
1960 }
1961 url_model->Remove(current_url);
1962 }
1963 TemplateURL* new_url = new TemplateURL();
1964 new_url->set_keyword(keyword);
1965 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191966 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321967 new_url->add_input_encoding(params.searchable_form_encoding);
1968 DCHECK(controller_.GetLastCommittedEntry());
1969 const GURL& favicon_url =
1970 controller_.GetLastCommittedEntry()->favicon().url();
1971 if (favicon_url.is_valid()) {
1972 new_url->SetFavIconURL(favicon_url);
1973 } else {
1974 // The favicon url isn't valid. This means there really isn't a favicon,
1975 // or the favicon url wasn't obtained before the load started. This assumes
1976 // the later.
1977 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1978 // its url.
1979 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1980 }
1981 new_url->set_safe_for_autoreplace(true);
1982 url_model->Add(new_url);
1983}
1984
[email protected]bf5c2ff392009-07-08 16:24:331985void TabContents::OnUserGesture() {
1986 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011987 DownloadRequestLimiter* limiter =
1988 g_browser_process->download_request_limiter();
1989 if (limiter)
1990 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261991 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331992}
1993
1994void TabContents::OnFindReply(int request_id,
1995 int number_of_matches,
1996 const gfx::Rect& selection_rect,
1997 int active_match_ordinal,
1998 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421999 // Ignore responses for requests that have been aborted.
2000 if (find_op_aborted_)
2001 return;
2002
[email protected]bf5c2ff392009-07-08 16:24:332003 // Ignore responses for requests other than the one we have most recently
2004 // issued. That way we won't act on stale results when the user has
2005 // already typed in another query.
2006 if (request_id != current_find_request_id_)
2007 return;
2008
2009 if (number_of_matches == -1)
2010 number_of_matches = last_search_result_.number_of_matches();
2011 if (active_match_ordinal == -1)
2012 active_match_ordinal = last_search_result_.active_match_ordinal();
2013
2014 gfx::Rect selection = selection_rect;
2015 if (selection.IsEmpty())
2016 selection = last_search_result_.selection_rect();
2017
2018 // Notify the UI, automation and any other observers that a find result was
2019 // found.
2020 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
2021 selection, active_match_ordinal,
2022 final_update);
2023 NotificationService::current()->Notify(
2024 NotificationType::FIND_RESULT_AVAILABLE,
2025 Source<TabContents>(this),
2026 Details<FindNotificationDetails>(&last_search_result_));
2027}
2028
2029void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542030 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2031 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2032 if (!entry)
2033 return;
2034 // Note that we don't call NavigationController::GotToOffset() as we don't
2035 // want to create a pending navigation entry (it might end up lingering
2036 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522037 entry->set_transition_type(entry->transition_type() |
2038 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542039 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2040 }
[email protected]bf5c2ff392009-07-08 16:24:332041}
2042
[email protected]bf5c2ff392009-07-08 16:24:332043void TabContents::OnMissingPluginStatus(int status) {
2044#if defined(OS_WIN)
2045// TODO(PORT): pull in when plug-ins work
2046 GetPluginInstaller()->OnMissingPluginStatus(status);
2047#endif
2048}
2049
2050void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332051 DCHECK(!plugin_path.value().empty());
2052
2053 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]45446a52010-11-04 17:41:002054 WebPluginInfo plugin_info;
2055 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
2056 plugin_path, &plugin_info) &&
2057 !plugin_info.name.empty()) {
2058 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372059#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002060 // Many plugins on the Mac have .plugin in the actual name, which looks
2061 // terrible, so look for that and strip it off if present.
2062 const std::wstring plugin_extension(L".plugin");
2063 if (EndsWith(plugin_name, plugin_extension, true))
2064 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372065#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332066 }
[email protected]2ae8a922010-06-28 20:27:532067 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2068 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332069 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582070 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2071 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532072 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332073}
2074
2075void TabContents::OnCrashedWorker() {
2076 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582077 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422078 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332079}
2080
[email protected]38789d82010-11-17 06:03:442081void TabContents::OnDidGetApplicationInfo(int32 page_id,
2082 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512083 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332084
[email protected]ed5431872009-11-17 08:39:512085 if (delegate())
2086 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332087}
2088
[email protected]bb461532010-11-26 21:50:232089void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
2090 if (delegate())
2091 delegate()->OnInstallApplication(this, info);
2092}
2093
[email protected]851b1eb2010-08-09 13:32:292094void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2095 const GURL& update_url) {
2096 new DisabledPluginInfoBar(this, name, update_url);
2097}
2098
[email protected]a2cf65eb2010-01-18 08:20:382099void TabContents::OnPageContents(const GURL& url,
2100 int renderer_process_id,
2101 int32 page_id,
[email protected]e5106202010-06-11 21:12:362102 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102103 const std::string& language,
2104 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382105 // Don't index any https pages. People generally don't want their bank
2106 // accounts, etc. indexed on their computer, especially since some of these
2107 // things are not marked cachable.
2108 // TODO(brettw) we may want to consider more elaborate heuristics such as
2109 // the cachability of the page. We may also want to consider subframes (this
2110 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272111 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2112 // content indexing for chromeos in some future releases.
2113#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382114 if (!url.SchemeIsSecure()) {
2115 Profile* p = profile();
2116 if (p && !p->IsOffTheRecord()) {
2117 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2118 if (hs)
2119 hs->SetPageContents(url, contents);
2120 }
2121 }
[email protected]ccd40a52010-05-11 16:15:272122#endif
[email protected]a8a81292010-01-21 00:32:452123
[email protected]1c57b7b2010-07-12 17:38:102124 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452125
2126 std::string lang = language;
2127 NotificationService::current()->Notify(
2128 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152129 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452130 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382131}
2132
[email protected]7e0831b2010-02-01 08:45:152133void TabContents::OnPageTranslated(int32 page_id,
2134 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162135 const std::string& translated_lang,
2136 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552137 language_state_.set_current_language(translated_lang);
2138 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162139 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152140 NotificationService::current()->Notify(
2141 NotificationType::PAGE_TRANSLATED,
2142 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162143 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152144}
2145
[email protected]ce833282010-11-04 15:48:392146void TabContents::OnSetSuggestions(
2147 int32 page_id,
2148 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262149 if (delegate())
[email protected]ce833282010-11-04 15:48:392150 delegate()->OnSetSuggestions(page_id, suggestions);
2151}
2152
2153void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2154 if (delegate())
2155 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262156}
2157
[email protected]bf5c2ff392009-07-08 16:24:332158void TabContents::DidStartProvisionalLoadForFrame(
2159 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182160 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332161 bool is_main_frame,
[email protected]ea51f1f2010-12-01 10:07:272162 bool is_error_page,
[email protected]bf5c2ff392009-07-08 16:24:332163 const GURL& url) {
2164 ProvisionalLoadDetails details(is_main_frame,
2165 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412166 url, std::string(), false,
2167 is_error_page, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332168 NotificationService::current()->Notify(
2169 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2170 Source<NavigationController>(&controller_),
2171 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142172 if (is_main_frame) {
[email protected]ea51f1f2010-12-01 10:07:272173 // If we're displaying a network error page do not reset the content
2174 // settings delegate's cookies so the user has a chance to modify cookie
2175 // settings.
2176 if (!is_error_page)
2177 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142178 content_settings_delegate_->ClearGeolocationContentSettings();
2179 }
[email protected]bf5c2ff392009-07-08 16:24:332180}
2181
2182void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202183 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332184 NotificationService::current()->Notify(
2185 NotificationType::RESOURCE_RESPONSE_STARTED,
2186 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202187 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332188}
2189
[email protected]3dbb80b2010-02-09 22:41:202190void TabContents::DidRedirectResource(
2191 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332192 NotificationService::current()->Notify(
2193 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2194 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202195 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332196}
2197
2198void TabContents::DidLoadResourceFromMemoryCache(
2199 const GURL& url,
2200 const std::string& frame_origin,
2201 const std::string& main_frame_origin,
2202 const std::string& security_info) {
2203 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442204 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332205 SSLManager::DeserializeSecurityInfo(security_info,
2206 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042207 &security_bits,
2208 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332209 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162210 GetRenderProcessHost()->id(), cert_id,
2211 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332212
2213 NotificationService::current()->Notify(
2214 NotificationType::LOAD_FROM_MEMORY_CACHE,
2215 Source<NavigationController>(&controller_),
2216 Details<LoadFromMemoryCacheDetails>(&details));
2217}
2218
[email protected]e3d60e5d2009-09-25 21:08:292219void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472220 displayed_insecure_content_ = true;
2221 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292222}
2223
2224void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592225 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292226}
2227
[email protected]bf5c2ff392009-07-08 16:24:332228void TabContents::DidFailProvisionalLoadWithError(
2229 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182230 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332231 bool is_main_frame,
2232 int error_code,
2233 const GURL& url,
2234 bool showing_repost_interstitial) {
2235 if (net::ERR_ABORTED == error_code) {
2236 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2237 // This means that the interstitial won't be torn down properly, which is
2238 // bad. But if we have an interstitial, go back to another tab type, and
2239 // then load the same interstitial again, we could end up getting the first
2240 // interstitial's "failed" message (as a result of the cancel) when we're on
2241 // the second one.
2242 //
2243 // We can't tell this apart, so we think we're tearing down the current page
2244 // which will cause a crash later one. There is also some code in
2245 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2246 // out because of this problem.
2247 //
2248 // http://code.google.com/p/chromium/issues/detail?id=2855
2249 // Because this will not tear down the interstitial properly, if "back" is
2250 // back to another tab type, the interstitial will still be somewhat alive
2251 // in the previous tab type. If you navigate somewhere that activates the
2252 // tab with the interstitial again, you'll see a flash before the new load
2253 // commits of the interstitial page.
2254 if (showing_interstitial_page()) {
2255 LOG(WARNING) << "Discarding message during interstitial.";
2256 return;
2257 }
2258
2259 // This will discard our pending entry if we cancelled the load (e.g., if we
2260 // decided to download the file instead of load it). Only discard the
2261 // pending entry if the URLs match, otherwise the user initiated a navigate
2262 // before the page loaded so that the discard would discard the wrong entry.
2263 NavigationEntry* pending_entry = controller_.pending_entry();
2264 if (pending_entry && pending_entry->url() == url) {
2265 controller_.DiscardNonCommittedEntries();
2266 // Update the URL display.
2267 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2268 }
2269
2270 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2271 }
2272
2273 // Send out a notification that we failed a provisional load with an error.
2274 ProvisionalLoadDetails details(is_main_frame,
2275 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412276 url, std::string(), false, false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332277 details.set_error_code(error_code);
2278
2279 NotificationService::current()->Notify(
2280 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2281 Source<NavigationController>(&controller_),
2282 Details<ProvisionalLoadDetails>(&details));
2283}
2284
[email protected]4b8e2b02010-11-30 09:15:182285void TabContents::DocumentLoadedInFrame(int64 frame_id) {
[email protected]bf5c2ff392009-07-08 16:24:332286 controller_.DocumentLoadedInFrame();
[email protected]622474d2010-11-04 09:21:082287 NotificationService::current()->Notify(
2288 NotificationType::FRAME_DOM_CONTENT_LOADED,
2289 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182290 Details<int64>(&frame_id));
[email protected]bf5c2ff392009-07-08 16:24:332291}
2292
[email protected]4b8e2b02010-11-30 09:15:182293void TabContents::DidFinishLoad(int64 frame_id) {
[email protected]fdd94a02010-11-05 08:07:172294 NotificationService::current()->Notify(
2295 NotificationType::FRAME_DID_FINISH_LOAD,
2296 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182297 Details<int64>(&frame_id));
[email protected]fdd94a02010-11-05 08:07:172298}
2299
[email protected]dcd5b332010-08-11 08:55:182300void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562301 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242302 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562303}
2304
[email protected]8d3347f2009-07-09 22:00:212305RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322306 return view_.get();
2307}
2308
[email protected]8d3347f2009-07-09 22:00:212309RenderViewHostDelegate::RendererManagement*
2310TabContents::GetRendererManagementDelegate() {
2311 return &render_manager_;
2312}
2313
[email protected]bf5c2ff392009-07-08 16:24:332314RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212315 TabContents::GetBrowserIntegrationDelegate() {
2316 return this;
[email protected]bf5c2ff392009-07-08 16:24:332317}
2318
[email protected]8d3347f2009-07-09 22:00:212319RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2320 return this;
[email protected]bf5c2ff392009-07-08 16:24:332321}
2322
[email protected]46ba9082010-06-22 10:00:582323RenderViewHostDelegate::ContentSettings*
2324TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552325 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582326}
2327
[email protected]8d3347f2009-07-09 22:00:212328RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322329 return save_package_.get(); // May be NULL, but we can return NULL.
2330}
2331
[email protected]8d3347f2009-07-09 22:00:212332RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092333 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212334}
2335
2336RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2337 return &fav_icon_helper_;
2338}
2339
[email protected]e8dbd674b2010-03-11 18:34:402340RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452341 if (autocomplete_history_manager_.get() == NULL)
2342 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2343 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332344}
2345
[email protected]21674df2009-10-28 19:51:212346RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342347 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212348}
2349
[email protected]1f18184a2010-07-21 19:34:492350RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2351 return GetSSLHelper();
2352}
2353
[email protected]b5977a0c2010-08-24 19:46:262354RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2355 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492356 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262357 return file_select_helper_.get();
2358}
2359
[email protected]fd571bb2010-03-19 01:23:542360AutomationResourceRoutingDelegate*
2361TabContents::GetAutomationResourceRoutingDelegate() {
2362 return delegate();
2363}
2364
[email protected]ced90ae12010-02-20 02:06:162365RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2366 return bookmark_drag_;
2367}
2368
2369void TabContents::SetBookmarkDragDelegate(
2370 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2371 bookmark_drag_ = bookmark_drag;
2372}
2373
[email protected]9fb83e82010-07-02 18:24:552374TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2375 return content_settings_delegate_.get();
2376}
2377
[email protected]93623c5d2009-12-10 21:40:322378RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462379 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512380}
2381
[email protected]57c6a652009-05-04 07:58:342382TabContents* TabContents::GetAsTabContents() {
2383 return this;
2384}
2385
[email protected]7b291f92009-08-14 05:43:532386ViewType::Type TabContents::GetRenderViewType() const {
2387 return ViewType::TAB_CONTENTS;
2388}
2389
2390int TabContents::GetBrowserWindowID() const {
2391 return controller().window_id().id();
2392}
2393
[email protected]420ae012009-04-24 05:16:322394void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062395 NotificationService::current()->Notify(
2396 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2397 Source<TabContents>(this),
2398 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322399 NavigationEntry* entry = controller_.GetActiveEntry();
2400 if (!entry)
2401 return;
2402
2403 // When we're creating views, we're still doing initial setup, so we always
2404 // use the pending DOM UI rather than any possibly existing committed one.
2405 if (render_manager_.pending_dom_ui()) {
2406 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2407 }
2408
2409 if (entry->IsViewSourceMode()) {
2410 // Put the renderer in view source mode.
2411 render_view_host->Send(
2412 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2413 }
[email protected]0666aef2009-05-13 19:48:082414
2415 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322416}
2417
2418void TabContents::RenderViewReady(RenderViewHost* rvh) {
2419 if (rvh != render_view_host()) {
2420 // Don't notify the world, since this came from a renderer in the
2421 // background.
2422 return;
2423 }
2424
2425 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302426 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232427 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302428
2429 // Restore the focus to the tab (otherwise the focus will be on the top
2430 // window).
[email protected]484ae5912010-09-29 19:16:142431 if (was_crashed && !FocusLocationBarByDefault() &&
2432 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302433 Focus();
[email protected]484ae5912010-09-29 19:16:142434 }
[email protected]420ae012009-04-24 05:16:322435}
2436
[email protected]443b80e2010-12-14 00:42:232437void TabContents::RenderViewGone(RenderViewHost* rvh,
2438 base::TerminationStatus status,
2439 int error_code) {
[email protected]420ae012009-04-24 05:16:322440 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092441 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322442 return;
2443 if (rvh != render_view_host()) {
2444 // The pending page's RenderViewHost is gone.
2445 return;
2446 }
2447
2448 SetIsLoading(false, NULL);
2449 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232450 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322451
[email protected]ff9efc62010-02-18 22:10:542452 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212453 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542454 RemoveInfoBar(GetInfoBarDelegateAt(i));
2455
[email protected]8e537302009-06-10 21:19:582456 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552457 // Only do this if we're not in browser shutdown, so that TabContents
2458 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2459 // visible do not flash a sad tab page.
2460 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2461 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322462
2463 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002464 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322465}
2466
[email protected]2e4633c2009-07-09 16:58:062467void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2468 NotificationService::current()->Notify(
2469 NotificationType::RENDER_VIEW_HOST_DELETED,
2470 Source<TabContents>(this),
2471 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482472 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062473}
2474
[email protected]420ae012009-04-24 05:16:322475void TabContents::DidNavigate(RenderViewHost* rvh,
2476 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372477 int extra_invalidate_flags = 0;
2478
2479 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]33f74972010-12-08 16:40:362480 PrerenderManager* pm = profile()->GetPrerenderManager();
2481 if (pm != NULL) {
2482 if (pm->MaybeUsePreloadedPage(this, params.url)) {
2483 // TODO(tburkard): If the preloaded page has not finished preloading
2484 // yet, we should not do this.
2485 DidStopLoading();
2486 return;
2487 }
2488 }
2489
[email protected]20ede072009-10-06 00:28:352490 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372491
[email protected]420ae012009-04-24 05:16:322492 render_manager_.DidNavigateMainFrame(rvh);
2493
[email protected]20ede072009-10-06 00:28:352494 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372495 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372496 }
2497
[email protected]420ae012009-04-24 05:16:322498 // Update the site of the SiteInstance if it doesn't have one yet.
2499 if (!GetSiteInstance()->has_site())
2500 GetSiteInstance()->SetSite(params.url);
2501
2502 // Need to update MIME type here because it's referred to in
2503 // UpdateNavigationCommands() called by RendererDidNavigate() to
2504 // determine whether or not to enable the encoding menu.
2505 // It's updated only for the main frame. For a subframe,
2506 // RenderView::UpdateURL does not set params.contents_mime_type.
2507 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2508 // TODO(jungshik): Add a test for the encoding menu to avoid
2509 // regressing it again.
2510 if (PageTransition::IsMainFrame(params.transition))
2511 contents_mime_type_ = params.contents_mime_type;
2512
2513 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372514 bool did_navigate = controller_.RendererDidNavigate(
2515 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392516
[email protected]a9c0bfe2010-09-17 08:35:222517 // Send notification about committed provisional loads. This notification is
2518 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2519 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2520 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072521 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2522 // that is not recorded in the navigation history. For the purpose of
2523 // tracking navigation events, we treat this event as a sub frame navigation
2524 // event.
2525 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2526 ProvisionalLoadDetails load_details(
2527 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412528 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222529 load_details.set_transition_type(params.transition);
2530 // Whether or not a page transition was triggered by going backward or
2531 // forward in the history is only stored in the navigation controller's
2532 // entry list.
2533 if (did_navigate &&
2534 (controller_.GetActiveEntry()->transition_type() &
2535 PageTransition::FORWARD_BACK)) {
2536 load_details.set_transition_type(
2537 params.transition | PageTransition::FORWARD_BACK);
2538 }
2539 NotificationService::current()->Notify(
2540 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2541 Source<NavigationController>(&controller_),
2542 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222543 }
2544
[email protected]3e90d4a2009-07-03 17:38:392545 // Update history. Note that this needs to happen after the entry is complete,
2546 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582547 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392548 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582549 // URLs, we use a data: URL as the real value. We actually want to save the
2550 // about: URL to the history db and keep the data: URL hidden. This is what
2551 // the TabContents' URL getter does.
2552 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2553 CreateHistoryAddPageArgs(GetURL(), details, params));
2554 if (!delegate() ||
2555 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2556 details.type)) {
2557 UpdateHistoryForNavigation(add_page_args);
2558 }
[email protected]3e90d4a2009-07-03 17:38:392559 }
2560
[email protected]76543b92009-08-31 17:27:452561 if (!did_navigate)
2562 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322563
2564 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2565 // for the appropriate notification (best) or you can add it to
2566 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2567 // necessary, please).
2568
2569 // Run post-commit tasks.
2570 if (details.is_main_frame)
2571 DidNavigateMainFramePostCommit(details, params);
2572 DidNavigateAnyFramePostCommit(rvh, details, params);
2573}
2574
2575void TabContents::UpdateState(RenderViewHost* rvh,
2576 int32 page_id,
2577 const std::string& state) {
2578 DCHECK(rvh == render_view_host());
2579
2580 // We must be prepared to handle state updates for any page, these occur
2581 // when the user is scrolling and entering form data, as well as when we're
2582 // leaving a page, in which case our state may have already been moved to
2583 // the next page. The navigation controller will look up the appropriate
2584 // NavigationEntry and update it when it is notified via the delegate.
2585
2586 int entry_index = controller_.GetEntryIndexWithPageID(
2587 GetSiteInstance(), page_id);
2588 if (entry_index < 0)
2589 return;
2590 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2591
2592 if (state == entry->content_state())
2593 return; // Nothing to update.
2594 entry->set_content_state(state);
2595 controller_.NotifyEntryChanged(entry, entry_index);
2596}
2597
2598void TabContents::UpdateTitle(RenderViewHost* rvh,
2599 int32 page_id, const std::wstring& title) {
2600 // If we have a title, that's a pretty good indication that we've started
2601 // getting useful data.
2602 SetNotWaitingForResponse();
2603
2604 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482605 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582606 page_id);
[email protected]420ae012009-04-24 05:16:322607 if (!entry || !UpdateTitleForEntry(entry, title))
2608 return;
2609
2610 // Broadcast notifications when the UI should be updated.
2611 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032612 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322613}
2614
[email protected]420ae012009-04-24 05:16:322615void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402616 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322617 set_encoding(encoding);
2618}
2619
2620void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2621 if (delegate())
2622 delegate()->UpdateTargetURL(this, url);
2623}
2624
2625void TabContents::UpdateThumbnail(const GURL& url,
2626 const SkBitmap& bitmap,
2627 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442628 if (profile()->IsOffTheRecord())
2629 return;
2630
[email protected]420ae012009-04-24 05:16:322631 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492632 if (history::TopSites::IsEnabled()) {
[email protected]e6baed562010-11-02 22:33:442633 history::TopSites* ts = profile()->GetTopSites();
2634 if (ts)
2635 ts->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282636 } else {
[email protected]e6baed562010-11-02 22:33:442637 HistoryService* hs =
2638 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2639 if (hs)
[email protected]449478302009-06-09 20:04:282640 hs->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322641 }
2642}
2643
[email protected]c4e98902010-06-01 10:20:142644void TabContents::UpdateInspectorSetting(const std::string& key,
2645 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052646 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082647}
2648
[email protected]45aafc92010-06-07 14:18:532649void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052650 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532651}
2652
[email protected]420ae012009-04-24 05:16:322653void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292654 // The UI may be in an event-tracking loop, such as between the
2655 // mouse-down and mouse-up in text selection or a button click.
2656 // Defer the close until after tracking is complete, so that we
2657 // don't free objects out from under the UI.
2658 // TODO(shess): This could probably be integrated with the
2659 // IsDoingDrag() test below. Punting for now because I need more
2660 // research to understand how this impacts platforms other than Mac.
2661 // TODO(shess): This could get more fine-grained. For instance,
2662 // closing a tab in another window while selecting text in the
2663 // current window's Omnibox should be just fine.
2664 if (view()->IsEventTracking()) {
2665 view()->CloseTabAfterEventTracking();
2666 return;
2667 }
2668
[email protected]24a4d1062009-07-10 23:10:422669 // If we close the tab while we're in the middle of a drag, we'll crash.
2670 // Instead, cancel the drag and close it as soon as the drag ends.
2671 if (view()->IsDoingDrag()) {
2672 view()->CancelDragAndCloseTab();
2673 return;
2674 }
2675
[email protected]420ae012009-04-24 05:16:322676 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2677 if (delegate() && rvh == render_view_host())
2678 delegate()->CloseContents(this);
2679}
2680
2681void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2682 if (delegate() && delegate()->IsPopup(this))
2683 delegate()->MoveContents(this, new_bounds);
2684}
2685
[email protected]7ab1e7d62009-10-14 23:32:012686void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322687 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492688
[email protected]de4761b2010-12-07 21:05:212689 if (delegate()) {
2690 bool is_print_preview_tab =
2691 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2692 if (content_restrictions_ || is_print_preview_tab) {
2693 content_restrictions_= is_print_preview_tab ?
2694 CONTENT_RESTRICTION_PRINT : 0;
2695 delegate()->ContentRestrictionsChanged(this);
2696 }
[email protected]9e823662010-10-13 23:36:002697 }
[email protected]3c9e1872010-11-18 16:17:492698
2699 // Notify observers about navigation.
2700 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2701 DidStartLoading());
[email protected]420ae012009-04-24 05:16:322702}
2703
[email protected]7ab1e7d62009-10-14 23:32:012704void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322705 scoped_ptr<LoadNotificationDetails> details;
2706
2707 NavigationEntry* entry = controller_.GetActiveEntry();
2708 // An entry may not exist for a stop when loading an initial blank page or
2709 // if an iframe injected by script into a blank page finishes loading.
2710 if (entry) {
[email protected]420ae012009-04-24 05:16:322711 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2712
2713 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542714 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322715 entry->transition_type(),
2716 elapsed,
2717 &controller_,
2718 controller_.GetCurrentEntryIndex()));
2719 }
2720
[email protected]420ae012009-04-24 05:16:322721 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492722
2723 // Notify observers about navigation.
2724 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2725 DidStopLoading());
[email protected]420ae012009-04-24 05:16:322726}
2727
[email protected]25497492010-09-11 15:15:082728void TabContents::DocumentOnLoadCompletedInMainFrame(
2729 RenderViewHost* render_view_host,
2730 int32 page_id) {
2731 NotificationService::current()->Notify(
2732 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2733 Source<TabContents>(this),
2734 Details<int>(&page_id));
2735}
2736
[email protected]420ae012009-04-24 05:16:322737void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2738 const GURL& source_url,
2739 const GURL& target_url) {
2740 NavigationEntry* entry;
2741 if (page_id == -1)
2742 entry = controller_.pending_entry();
2743 else
2744 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2745 if (!entry || entry->url() != source_url)
2746 return;
2747 entry->set_url(target_url);
2748}
2749
[email protected]420ae012009-04-24 05:16:322750void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2751 WindowOpenDisposition disposition) {
2752 if (render_manager_.dom_ui()) {
2753 // When we're a DOM UI, it will provide a page transition type for us (this
2754 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2755 // generated suggestions).
2756 //
2757 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162758 // want web sites to see a referrer of "chrome://blah" (and some
2759 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322760 // send to the site), so we send no referrer.
2761 OpenURL(url, GURL(), disposition,
2762 render_manager_.dom_ui()->link_transition_type());
2763 } else {
2764 OpenURL(url, referrer, disposition, PageTransition::LINK);
2765 }
2766}
2767
[email protected]1ee614862009-07-06 20:29:182768void TabContents::DomOperationResponse(const std::string& json_string,
2769 int automation_id) {
2770}
2771
[email protected]8b8e7c92010-08-19 18:05:562772void TabContents::ProcessDOMUIMessage(
2773 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322774 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442775 // This can happen if someone uses window.open() to open an extension URL
2776 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562777 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322778 return;
2779 }
[email protected]8b8e7c92010-08-19 18:05:562780 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322781}
2782
2783void TabContents::ProcessExternalHostMessage(const std::string& message,
2784 const std::string& origin,
2785 const std::string& target) {
2786 if (delegate())
2787 delegate()->ForwardMessageToExternalHost(message, origin, target);
2788}
2789
[email protected]420ae012009-04-24 05:16:322790void TabContents::RunJavaScriptMessage(
2791 const std::wstring& message,
2792 const std::wstring& default_prompt,
2793 const GURL& frame_url,
2794 const int flags,
2795 IPC::Message* reply_msg,
2796 bool* did_suppress_message) {
2797 // Suppress javascript messages when requested and when inside a constrained
2798 // popup window (because that activates them and breaks them out of the
2799 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552800 // Also suppress messages when showing an interstitial. The interstitial is
2801 // shown over the previous page, we don't want the hidden page dialogs to
2802 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502803 bool suppress_this_message =
2804 suppress_javascript_messages_ ||
2805 showing_interstitial_page() ||
2806 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322807 if (delegate())
2808 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312809 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322810
2811 *did_suppress_message = suppress_this_message;
2812
2813 if (!suppress_this_message) {
2814 base::TimeDelta time_since_last_message(
2815 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2816 bool show_suppress_checkbox = false;
2817 // Show a checkbox offering to suppress further messages if this message is
2818 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2819 if (time_since_last_message <
2820 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2821 show_suppress_checkbox = true;
2822
[email protected]d6ad7442010-09-05 19:06:522823 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2824 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322825 } else {
2826 // If we are suppressing messages, just reply as is if the user immediately
2827 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542828 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322829 }
2830}
2831
2832void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2833 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292834 if (delegate())
2835 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502836 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2837 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2838 std::wstring());
2839 return;
2840 }
[email protected]7ab1e7d62009-10-14 23:32:012841 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222842 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322843}
2844
2845void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2846 const std::string& json_arguments,
2847 IPC::Message* reply_msg) {
2848 if (delegate()) {
2849 HtmlDialogUIDelegate* dialog_delegate =
2850 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222851 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322852 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2853 }
2854}
2855
[email protected]c4aa86962010-11-24 23:08:042856void TabContents::PasswordFormsFound(
2857 const std::vector<webkit_glue::PasswordForm>& forms) {
2858 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2859 PasswordFormsFound(forms));
2860}
2861
2862void TabContents::PasswordFormsVisible(
2863 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2864 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2865 PasswordFormsVisible(visible_forms));
2866}
2867
[email protected]420ae012009-04-24 05:16:322868// Checks to see if we should generate a keyword based on the OSDD, and if
2869// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202870void TabContents::PageHasOSDD(
2871 RenderViewHost* render_view_host,
2872 int32 page_id,
2873 const GURL& url,
2874 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122875 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322876 DCHECK(url.is_valid());
2877 if (!IsActiveEntry(page_id))
2878 return;
[email protected]420ae012009-04-24 05:16:322879 if (!profile()->GetTemplateURLFetcher())
2880 return;
[email protected]420ae012009-04-24 05:16:322881 if (profile()->IsOffTheRecord())
2882 return;
2883
[email protected]2de7e002010-10-11 22:58:202884 TemplateURLFetcher::ProviderType provider_type;
2885 switch (msg_provider_type.type) {
2886 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2887 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2888 break;
2889
2890 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2891 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2892 break;
2893
2894 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2895 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2896 break;
2897
2898 default:
2899 NOTREACHED();
2900 return;
2901 }
2902
[email protected]420ae012009-04-24 05:16:322903 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2904 DCHECK(entry);
2905
2906 const NavigationEntry* base_entry = entry;
2907 if (IsFormSubmit(base_entry)) {
2908 // If the current page is a form submit, find the last page that was not
2909 // a form submit and use its url to generate the keyword from.
2910 int index = controller_.last_committed_entry_index() - 1;
2911 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2912 index--;
2913 if (index >= 0)
2914 base_entry = controller_.GetEntryAtIndex(index);
2915 else
2916 base_entry = NULL;
2917 }
2918
2919 // We want to use the user typed URL if available since that represents what
2920 // the user typed to get here, and fall back on the regular URL if not.
2921 if (!base_entry)
2922 return;
2923 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2924 base_entry->user_typed_url() : base_entry->url();
2925 if (!keyword_url.is_valid())
2926 return;
[email protected]2de7e002010-10-11 22:58:202927
[email protected]0b5b85c2010-10-11 23:00:122928 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2929 keyword_url,
2930 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532931
[email protected]0b5b85c2010-10-11 23:00:122932 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322933 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322934 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2935 keyword,
2936 url,
2937 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122938 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202939 provider_type);
[email protected]420ae012009-04-24 05:16:322940}
2941
[email protected]420ae012009-04-24 05:16:322942GURL TabContents::GetAlternateErrorPageURL() const {
2943 GURL url;
2944 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2945 if (profile()->IsOffTheRecord())
2946 return url;
2947
2948 PrefService* prefs = profile()->GetPrefs();
2949 DCHECK(prefs);
2950 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152951 url = google_util::AppendGoogleLocaleParam(
2952 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322953 url = google_util::AppendGoogleTLDParam(url);
2954 }
2955 return url;
2956}
2957
2958WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062959 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552960 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082961 WebPreferences web_prefs =
2962 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
2963
[email protected]9beff752010-09-22 19:35:432964 // Force accelerated compositing and 2d canvas off for chrome: and
2965 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432966 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2967 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082968 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432969 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082970 }
2971
[email protected]39553442010-09-09 00:01:552972#if defined(OS_MACOSX)
2973 // Disable accelerated compositing if IOSurface's are not supported,
2974 // as is the case in 10.5.
2975 if (!IOSurfaceSupport::Initialize())
2976 web_prefs.accelerated_compositing_enabled = false;
2977#endif
2978
[email protected]447021c2010-09-08 21:29:082979 return web_prefs;
[email protected]420ae012009-04-24 05:16:322980}
2981
[email protected]fa1cf0b82010-01-15 21:49:442982void TabContents::OnIgnoredUIEvent() {
2983 if (constrained_window_count()) {
2984 ConstrainedWindow* window = *constrained_window_begin();
2985 window->FocusConstrainedWindow();
2986 }
2987}
2988
[email protected]420ae012009-04-24 05:16:322989void TabContents::OnJSOutOfMemory() {
2990 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582991 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2992 NULL, true));
[email protected]420ae012009-04-24 05:16:322993}
2994
[email protected]420ae012009-04-24 05:16:322995void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2996 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342997 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322998 // delivered to a pending RenderViewHost. We must first run the onunload
2999 // handler of the old RenderViewHost before we can allow it to proceed.
3000 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
3001 new_request_id);
3002}
3003
[email protected]420ae012009-04-24 05:16:323004void TabContents::RendererUnresponsive(RenderViewHost* rvh,
3005 bool is_during_unload) {
3006 if (is_during_unload) {
3007 // Hang occurred while firing the beforeunload/unload handler.
3008 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:113009 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323010
3011 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3012 return;
3013
3014 // If the tab hangs in the beforeunload/unload handler there's really
3015 // nothing we can do to recover. Pretend the unload listeners have
3016 // all fired and close the tab. If the hang is in the beforeunload handler
3017 // then the user will not have the option of cancelling the close.
3018 Close(rvh);
3019 return;
3020 }
3021
3022 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:003023 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:323024}
3025
3026void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:003027 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:323028}
3029
3030void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:563031 net::LoadState load_state,
3032 uint64 upload_position,
3033 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323034 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563035 upload_position_ = upload_position;
3036 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:293037 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:193038 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:293039 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:533040 load_state_host_ =
3041 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:323042 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
3043 SetNotWaitingForResponse();
3044 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:503045 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:323046}
3047
[email protected]1ee614862009-07-06 20:29:183048bool TabContents::IsExternalTabContainer() const {
3049 if (!delegate())
3050 return false;
3051
3052 return delegate()->IsExternalTabContainer();
3053}
3054
[email protected]1ee614862009-07-06 20:29:183055void TabContents::DidInsertCSS() {
3056 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:323057}
3058
[email protected]546ae4e02010-12-08 14:57:193059void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:353060 NotificationService::current()->Notify(
3061 NotificationType::FOCUS_CHANGED_IN_PAGE,
3062 Source<RenderViewHost>(render_view_host()),
[email protected]546ae4e02010-12-08 14:57:193063 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:353064}
3065
[email protected]b75b8292010-10-01 07:28:253066void TabContents::UpdateZoomLimits(int minimum_percent,
3067 int maximum_percent,
3068 bool remember) {
3069 minimum_zoom_percent_ = minimum_percent;
3070 maximum_zoom_percent_ = maximum_percent;
3071 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383072}
3073
[email protected]9e823662010-10-13 23:36:003074void TabContents::UpdateContentRestrictions(int restrictions) {
3075 content_restrictions_ = restrictions;
3076 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:323077}
3078
[email protected]420ae012009-04-24 05:16:323079void TabContents::BeforeUnloadFiredFromRenderManager(
3080 bool proceed,
3081 bool* proceed_to_fire_unload) {
3082 if (delegate())
3083 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3084}
3085
[email protected]3a3d47472010-07-15 21:03:543086void TabContents::DidStartLoadingFromRenderManager(
3087 RenderViewHost* render_view_host) {
3088 DidStartLoading();
3089}
3090
3091void TabContents::RenderViewGoneFromRenderManager(
3092 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233093 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3094 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543095}
3096
[email protected]420ae012009-04-24 05:16:323097void TabContents::UpdateRenderViewSizeForRenderManager() {
3098 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263099 gfx::Size size = view_->GetContainerSize();
3100 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3101 // here during container initialization and normal window size will be set
3102 // later. In case of tab duplication this resizing to 0x0 prevents setting
3103 // normal size later so just ignore it.
3104 if (!size.IsEmpty())
3105 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323106}
3107
[email protected]3a3d47472010-07-15 21:03:543108void TabContents::NotifySwappedFromRenderManager() {
3109 NotifySwapped();
3110}
3111
3112NavigationController& TabContents::GetControllerForRenderManager() {
3113 return controller();
3114}
3115
[email protected]420ae012009-04-24 05:16:323116DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223117 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323118}
3119
3120NavigationEntry*
3121TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3122 return controller_.GetLastCommittedEntry();
3123}
3124
3125bool TabContents::CreateRenderViewForRenderManager(
3126 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323127 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523128
[email protected]674b3822010-08-04 04:02:513129 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323130 return false;
3131
3132 // Now that the RenderView has been created, we need to tell it its size.
3133 rwh_view->SetSize(view_->GetContainerSize());
3134
3135 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3136 render_view_host);
3137 return true;
3138}
3139
3140void TabContents::Observe(NotificationType type,
3141 const NotificationSource& source,
3142 const NotificationDetails& details) {
3143 switch (type.value) {
3144 case NotificationType::BOOKMARK_MODEL_LOADED:
3145 // BookmarkModel finished loading, fall through to update starred state.
3146 case NotificationType::URLS_STARRED: {
3147 // Somewhere, a URL has been starred.
3148 // Ignore notifications for profiles other than our current one.
3149 Profile* source_profile = Source<Profile>(source).ptr();
3150 if (!source_profile || !source_profile->IsSameProfile(profile()))
3151 return;
3152
3153 UpdateStarredStateForCurrentURL();
3154 break;
3155 }
3156 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513157 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323158 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3159 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3160 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533161 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3162 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323163 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173164 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3165 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323166 } else {
3167 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3168 }
3169 break;
3170 }
3171 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3172 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3173 break;
3174
3175 case NotificationType::NAV_ENTRY_COMMITTED: {
3176 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3177
3178 NavigationController::LoadCommittedDetails& committed_details =
3179 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3180 ExpireInfoBars(committed_details);
3181 break;
3182 }
3183
[email protected]d3ba77272009-09-03 00:06:093184#if defined(OS_LINUX)
3185 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543186 renderer_preferences_util::UpdateFromSystemSettings(
3187 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093188 render_view_host()->SyncRendererPrefs();
3189 break;
3190 }
3191#endif
3192
[email protected]6c32ce72010-03-08 05:18:063193 case NotificationType::USER_STYLE_SHEET_UPDATED:
3194 UpdateWebPreferences();
3195 break;
3196
[email protected]79580c62010-02-02 02:36:253197 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:453198 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:253199 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493200 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293201 if (entry)
[email protected]da0c8e92010-02-09 23:25:493202 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293203 if (settings_details.ptr()->update_all() ||
3204 settings_details.ptr()->pattern().Matches(entry_url)) {
3205 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233206 profile()->GetHostContentSettingsMap()->
3207 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253208 }
3209 break;
3210 }
3211
[email protected]e5adff72010-06-14 18:13:063212 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573213 break;
[email protected]a888b29e62010-04-01 13:38:573214
3215 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063216 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573217 break;
[email protected]a888b29e62010-04-01 13:38:573218
[email protected]88152052010-10-01 04:05:183219 case NotificationType::GOOGLE_URL_UPDATED:
3220 UpdateAlternateErrorPageURL();
3221 break;
3222
[email protected]420ae012009-04-24 05:16:323223 default:
3224 NOTREACHED();
3225 }
3226}
[email protected]aacd7cc2009-09-02 14:51:103227
[email protected]9adb9692010-10-29 23:14:023228void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083229 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433230
[email protected]a888b29e62010-04-01 13:38:573231 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083232 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3233 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573234 extension,
[email protected]807871f2010-09-16 01:04:483235 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3236 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573237 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3238 Extension::EXTENSION_ICON_SMALLISH),
3239 ImageLoadingTracker::CACHE);
3240 } else {
[email protected]98aa0b52010-05-06 17:03:083241 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573242 }
3243}
3244
[email protected]9adb9692010-10-29 23:14:023245const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:003246 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:573247 if (!extensions_service)
3248 return NULL;
3249
[email protected]9adb9692010-10-29 23:14:023250 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573251 return extension ?
3252 extension : extensions_service->GetExtensionByWebExtent(url);
3253}
3254
[email protected]a888b29e62010-04-01 13:38:573255void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3256 int index) {
3257 if (image) {
[email protected]98aa0b52010-05-06 17:03:083258 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573259 NotifyNavigationStateChanged(INVALIDATE_TAB);
3260 }
3261}
3262
[email protected]beb440c2009-11-06 04:08:543263gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3264 return view_->GetTopLevelNativeWindow();
3265}
3266
3267void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3268 bool success,
3269 const std::wstring& prompt) {
3270 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3271 if (is_showing_before_unload_dialog_ && !success) {
3272 // If a beforeunload dialog is canceled, we need to stop the throbber from
3273 // spinning, since we forced it to start spinning in Navigate.
3274 DidStopLoading();
3275
3276 tab_close_start_time_ = base::TimeTicks();
3277 }
3278 is_showing_before_unload_dialog_ = false;
3279 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3280}
3281
3282void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3283 set_suppress_javascript_messages(suppress_message_boxes);
3284}
3285
[email protected]3a3d47472010-07-15 21:03:543286TabContents* TabContents::AsTabContents() {
3287 return this;
3288}
3289
3290ExtensionHost* TabContents::AsExtensionHost() {
3291 return NULL;
3292}
3293
[email protected]41fc0322009-09-04 22:23:403294void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103295 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3296}
[email protected]f45d2a72010-03-08 23:28:353297
3298void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3299 app_icon_ = app_icon;
3300 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3301}
[email protected]33f74972010-12-08 16:40:363302
3303void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
3304 render_manager_.SwapInRenderViewHost(rvh);
3305}
3306
3307void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
3308 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
3309 rwh_view->SetSize(view()->GetContainerSize());
3310}