blob: f95634f987a4a56b5e345d1ae49049cdc27f80f2 [file] [log] [blame]
[email protected]7e7414ae2010-01-26 20:19:291// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]a92b8642009-05-05 23:38:569#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1110#include "app/resource_bundle.h"
[email protected]39553442010-09-09 00:01:5511#if defined(OS_MACOSX)
12#include "app/surface/io_surface_support_mac.h"
13#endif
[email protected]614519812010-03-19 08:20:5614#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4915#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3216#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0117#include "base/i18n/rtl.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]420ae012009-04-24 05:16:3219#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5420#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3721#include "base/string_util.h"
[email protected]440b37b22010-08-30 05:31:4022#include "base/utf_string_conversions.h"
[email protected]96d185d2009-04-24 03:28:5423#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4524#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2125#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4026#include "chrome/browser/blocked_content_container.h"
[email protected]420ae012009-04-24 05:16:3227#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5428#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5529#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1031#include "chrome/browser/character_encoding.h"
[email protected]5f24f212010-12-02 14:47:4532#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3333#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5434#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1435#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3236#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5437#include "chrome/browser/dom_ui/dom_ui.h"
38#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0239#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3240#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0141#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4942#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0843#include "chrome/browser/extensions/extensions_service.h"
[email protected]ec0b6c42010-08-26 03:16:5844#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4245#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2546#include "chrome/browser/host_zoom_map.h"
[email protected]0189bc722009-08-28 21:56:4847#include "chrome/browser/favicon_service.h"
[email protected]ba70d082010-09-10 16:54:4948#include "chrome/browser/file_select_helper.h"
[email protected]f7578f52010-08-30 22:22:4949#include "chrome/browser/google/google_util.h"
[email protected]8897c382009-05-06 17:53:2650#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0751#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3252#include "chrome/browser/load_from_memory_cache_details.h"
53#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4454#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0555#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1056#include "chrome/browser/omnibox_search_hint.h"
[email protected]14a000d2010-04-29 21:44:2457#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5758#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0259#include "chrome/browser/prefs/pref_service.h"
[email protected]33f74972010-12-08 16:40:3660#include "chrome/browser/prerender/prerender_manager.h"
[email protected]dbeebd52010-11-16 20:34:1661#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0962#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3363#include "chrome/browser/profiles/profile.h"
[email protected]1db6ff152009-10-12 15:32:0764#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1665#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5466#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3767#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0768#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5469#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3270#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1171#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1672#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1273#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1674#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1775#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1776#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5477#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1678#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4379#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1680#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4981#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5782#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]3c9e1872010-11-18 16:17:4983#include "chrome/browser/tab_contents/web_navigation_observer.h"
[email protected]152b8ba32010-03-29 19:40:1684#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3585#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]45300ad42010-12-02 15:51:1486#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]54ec6472010-04-09 19:39:5887#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2788#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2189#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4990#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5791#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4892#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1493#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0994#include "chrome/common/extensions/url_pattern.h"
95#include "chrome/common/navigation_types.h"
96#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5697#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2998#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3299#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:02100#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:18101#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:54102#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:37103#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:26104#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32105#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06106#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37107#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32108#include "net/base/mime_util.h"
109#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29110#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32111#include "net/base/registry_controlled_domain.h"
[email protected]b75b8292010-10-01 07:28:25112#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]1ee614862009-07-06 20:29:18113#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03114#include "webkit/glue/password_form.h"
[email protected]45446a52010-11-04 17:41:00115#include "webkit/glue/plugins/plugin_list.h"
[email protected]3e45ba92009-02-20 21:09:00116
[email protected]420ae012009-04-24 05:16:32117// Cross-Site Navigations
118//
119// If a TabContents is told to navigate to a different web site (as determined
120// by SiteInstance), it will replace its current RenderViewHost with a new
121// RenderViewHost dedicated to the new SiteInstance. This works as follows:
122//
123// - Navigate determines whether the destination is cross-site, and if so,
124// it creates a pending_render_view_host_ and moves into the PENDING
125// RendererState.
126// - The pending RVH is "suspended," so that no navigation messages are sent to
127// its renderer until the onbeforeunload JavaScript handler has a chance to
128// run in the current RVH.
129// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
130// that it has a pending cross-site request. ResourceDispatcherHost will
131// check for this when the response arrives.
132// - The current RVH runs its onbeforeunload handler. If it returns false, we
133// cancel all the pending logic and go back to NORMAL. Otherwise we allow
134// the pending RVH to send the navigation request to its renderer.
135// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
136// checks CrossSiteRequestManager to see that the RVH responsible has a
137// pending cross-site request, and then installs a CrossSiteEventHandler.
138// - When RDH receives a response, the BufferedEventHandler determines whether
139// it is a download. If so, it sends a message to the new renderer causing
140// it to cancel the request, and the download proceeds in the download
141// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34142// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32143// doesn't affect any functionality.
144// - After RDH receives a response and determines that it is safe and not a
145// download, it pauses the response to first run the old page's onunload
146// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34147// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32148// to the current RVH.
149// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
150// the ResourceDispatcherHost, who unpauses the response. Data is then sent
151// to the pending RVH.
152// - The pending renderer sends a FrameNavigate message that invokes the
153// DidNavigate method. This replaces the current RVH with the
154// pending RVH and goes back to the NORMAL RendererState.
155
156namespace {
157
158// Amount of time we wait between when a key event is received and the renderer
159// is queried for its state and pushed to the NavigationEntry.
160const int kQueryStateDelay = 5000;
161
[email protected]6ebdc9b2010-09-27 16:55:57162const int kSyncWaitDelay = 40;
163
[email protected]420ae012009-04-24 05:16:32164// If another javascript message box is displayed within
165// kJavascriptMessageExpectedDelay of a previous javascript message box being
166// dismissed, display an option to suppress future message boxes from this
167// contents.
168const int kJavascriptMessageExpectedDelay = 1000;
169
[email protected]420ae012009-04-24 05:16:32170// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51171const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32172 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17173 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32174 prefs::kWebKitJavaEnabled,
175 prefs::kWebKitJavascriptEnabled,
176 prefs::kWebKitLoadsImagesAutomatically,
177 prefs::kWebKitPluginsEnabled,
178 prefs::kWebKitUsesUniversalDetector,
179 prefs::kWebKitSerifFontFamily,
180 prefs::kWebKitSansSerifFontFamily,
181 prefs::kWebKitFixedFontFamily,
182 prefs::kWebKitDefaultFontSize,
183 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13184 prefs::kWebKitMinimumFontSize,
185 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36186 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32187 prefs::kDefaultCharset
188 // kWebKitStandardFontIsSerif needs to be added
189 // if we let users pick which font to use, serif or sans-serif when
190 // no font is specified or a CSS generic family (serif or sans-serif)
191 // is not specified.
192};
193
194const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
195
[email protected]420ae012009-04-24 05:16:32196// Returns true if the entry's transition type is FORM_SUBMIT.
197bool IsFormSubmit(const NavigationEntry* entry) {
198 return (PageTransition::StripQualifier(entry->transition_type()) ==
199 PageTransition::FORM_SUBMIT);
200}
201
202#if defined(OS_WIN)
203
204BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
205 // Note: erase is required to properly paint some widgets borders. This can
206 // be seen with textfields.
207 InvalidateRect(hwnd, NULL, TRUE);
208 return TRUE;
209}
210#endif
211
[email protected]5e369672009-11-03 23:48:30212ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16213 Profile* profile, const NavigationEntry& entry,
214 NavigationController::ReloadType reload_type) {
215 switch (reload_type) {
216 case NavigationController::RELOAD:
217 return ViewMsg_Navigate_Params::RELOAD;
218 case NavigationController::RELOAD_IGNORING_CACHE:
219 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
220 case NavigationController::NO_RELOAD:
221 break; // Fall through to rest of function.
222 }
[email protected]5e369672009-11-03 23:48:30223
224 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
225 profile->DidLastSessionExitCleanly())
226 return ViewMsg_Navigate_Params::RESTORE;
227
228 return ViewMsg_Navigate_Params::NORMAL;
229}
230
[email protected]876bc832010-09-07 16:29:54231void MakeNavigateParams(const NavigationEntry& entry,
232 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16233 NavigationController::ReloadType reload_type,
234 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34235 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54236 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00237 params->current_history_list_offset = controller.last_committed_entry_index();
238 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34239 params->url = entry.url();
240 params->referrer = entry.referrer();
241 params->transition = entry.transition_type();
242 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00243 params->navigation_type =
244 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34245 params->request_time = base::Time::Now();
246}
247
[email protected]851b1eb2010-08-09 13:32:29248class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
249 public:
250 DisabledPluginInfoBar(TabContents* tab_contents,
251 const string16& name,
252 const GURL& update_url)
253 : ConfirmInfoBarDelegate(tab_contents),
254 tab_contents_(tab_contents),
255 name_(name),
256 update_url_(update_url) {
257 tab_contents->AddInfoBar(this);
258 }
259
260 virtual int GetButtons() const {
261 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
262 }
263
[email protected]e23d3a32010-08-13 19:39:58264 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29265 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58266 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29267 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58268 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29269 return ConfirmInfoBarDelegate::GetButtonLabel(button);
270 }
271
[email protected]e23d3a32010-08-13 19:39:58272 virtual string16 GetMessageText() const {
273 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29274 }
275
[email protected]e23d3a32010-08-13 19:39:58276 virtual string16 GetLinkText() {
277 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29278 }
279
280 virtual SkBitmap* GetIcon() const {
281 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
282 IDR_INFOBAR_PLUGIN_INSTALL);
283 }
284
285 virtual bool Accept() {
286 tab_contents_->OpenURL(update_url_, GURL(),
[email protected]57b66d02010-09-30 11:24:51287 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29288 return false;
289 }
290
291 virtual bool Cancel() {
292 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
[email protected]57b66d02010-09-30 11:24:51293 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29294 return false;
295 }
296
297 virtual bool LinkClicked(WindowOpenDisposition disposition) {
298 // TODO(bauerb): Navigate to a help page explaining why we disabled
299 // the plugin, once we have one.
300 return false;
301 }
302
303 private:
304 TabContents* tab_contents_;
305 string16 name_;
306 GURL update_url_;
307};
308
[email protected]420ae012009-04-24 05:16:32309} // namespace
310
311// -----------------------------------------------------------------------------
312
[email protected]fdd61c62009-04-22 19:22:57313// static
314int TabContents::find_request_id_counter_ = -1;
315
[email protected]420ae012009-04-24 05:16:32316
[email protected]420ae012009-04-24 05:16:32317TabContents::TabContents(Profile* profile,
318 SiteInstance* site_instance,
319 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07320 const TabContents* base_tab_contents,
321 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42322 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07323 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
324 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13325 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22326 TabContentsView::Create(this))),
327 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57328 property_bag_(),
329 registrar_(),
[email protected]12802702010-07-09 19:43:09330 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
331 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57332 save_package_(),
[email protected]6db0def92010-03-02 19:55:45333 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21334 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57335 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06336 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22337 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34338 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23339 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
340 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34341 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34342 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57343 current_load_start_(),
344 load_state_(net::LOAD_STATE_IDLE),
345 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56346 upload_size_(0),
347 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57348 received_page_title_(false),
349 is_starred_(false),
350 contents_mime_type_(),
351 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40352 blocked_contents_(NULL),
353 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49354 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47355 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57356 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57357 find_ui_active_(false),
358 find_op_aborted_(false),
359 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12360 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12361 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08362 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57363 capturing_contents_(false),
364 is_being_destroyed_(false),
365 notify_disconnection_(false),
366 history_requests_(),
367#if defined(OS_WIN)
368 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
369#endif
370 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44371 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01372 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54373 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54374 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16375 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38376 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25377 minimum_zoom_percent_(
378 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
379 maximum_zoom_percent_(
380 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00381 temporary_zoom_settings_(false),
382 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54383 renderer_preferences_util::UpdateFromSystemSettings(
384 &renderer_preferences_, profile);
385
[email protected]9fb83e82010-07-02 18:24:55386 content_settings_delegate_.reset(
387 new TabSpecificContentSettings(this, profile));
388
[email protected]12636df2009-09-28 22:32:21389 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32390
[email protected]34ac70502009-09-25 17:07:23391 // We have the initial size of the view be based on the size of the passed in
392 // tab contents (normally a tab from the same window).
393 view_->CreateView(base_tab_contents ?
394 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32395
396 // Register for notifications about all interested prefs change.
397 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28398 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32399 if (prefs) {
400 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28401 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32402 }
403
404 // Register for notifications about URL starredness changing on any profile.
405 registrar_.Add(this, NotificationType::URLS_STARRED,
406 NotificationService::AllSources());
407 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
408 NotificationService::AllSources());
409 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
410 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09411#if defined(OS_LINUX)
412 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
413 NotificationService::AllSources());
414#endif
[email protected]420ae012009-04-24 05:16:32415
[email protected]6c32ce72010-03-08 05:18:06416 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
417 NotificationService::AllSources());
418
[email protected]79580c62010-02-02 02:36:25419 // Register for notifications about content setting changes.
420 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
421 NotificationService::AllSources());
422
[email protected]a888b29e62010-04-01 13:38:57423 // Listen for extension changes so we can update extension_for_current_page_.
424 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
425 NotificationService::AllSources());
426 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
427 NotificationService::AllSources());
428 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
429 NotificationService::AllSources());
430
[email protected]88152052010-10-01 04:05:18431 // Listen for Google URL changes
432 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
433 NotificationService::AllSources());
434
[email protected]c8865482009-07-23 20:40:10435 // Set-up the showing of the omnibox search infobar if applicable.
436 if (OmniboxSearchHint::IsEnabled(profile))
437 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35438}
initial.commit09911bf2008-07-26 23:55:29439
440TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32441 is_being_destroyed_ = true;
442
[email protected]bfe4c1582009-10-02 18:11:09443 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32444 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28445 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32446
[email protected]420ae012009-04-24 05:16:32447 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00448 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32449
[email protected]420ae012009-04-24 05:16:32450 // First cleanly close all child windows.
451 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
452 // some of these to close. CloseWindows is async, so it might get called
453 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49454 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32455
[email protected]c65e2f152010-10-14 15:30:40456 // Close all blocked contents.
457 if (blocked_contents_)
458 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13459
[email protected]420ae012009-04-24 05:16:32460 // Notify any observer that have a reference on this tab contents.
461 NotificationService::current()->Notify(
462 NotificationType::TAB_CONTENTS_DESTROYED,
463 Source<TabContents>(this),
464 NotificationService::NoDetails());
465
[email protected]1e5e74f2009-05-27 20:55:12466 // Notify any lasting InfobarDelegates that have not yet been removed that
467 // whatever infobar they were handling in this TabContents has closed,
468 // because the TabContents is going away entirely.
469 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
470 // notification may trigger infobars calls that access their delegate. (and
471 // some implementations of InfoBarDelegate do delete themselves on
472 // InfoBarClosed()).
473 for (int i = 0; i < infobar_delegate_count(); ++i) {
474 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
475 delegate->InfoBarClosed();
476 }
477 infobar_delegates_.clear();
478
[email protected]420ae012009-04-24 05:16:32479 // TODO(brettw) this should be moved to the view.
480#if defined(OS_WIN)
481 // If we still have a window handle, destroy it. GetNativeView can return
482 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42483 if (GetNativeView()) {
484 RenderViewHost* host = render_view_host();
485 if (host && host->view()) {
486 host->view()->WillWmDestroy();
487 }
[email protected]420ae012009-04-24 05:16:32488 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42489 }
[email protected]420ae012009-04-24 05:16:32490#endif
[email protected]7ab1e7d62009-10-14 23:32:01491
492 // OnCloseStarted isn't called in unit tests.
493 if (!tab_close_start_time_.is_null()) {
494 UMA_HISTOGRAM_TIMES("Tab.Close",
495 base::TimeTicks::Now() - tab_close_start_time_);
496 }
initial.commit09911bf2008-07-26 23:55:29497}
498
[email protected]d5f942ba2008-09-26 19:30:34499// static
500void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32501 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
502
503 WebPreferences pref_defaults;
504 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
505 pref_defaults.javascript_enabled);
506 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
507 pref_defaults.web_security_enabled);
508 prefs->RegisterBooleanPref(
509 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
510 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
511 pref_defaults.loads_images_automatically);
512 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
513 pref_defaults.plugins_enabled);
514 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
515 pref_defaults.dom_paste_enabled);
516 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
517 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14518 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32519 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
520 pref_defaults.text_areas_are_resizable);
521 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
522 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36523 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
524 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32525
526 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
527 IDS_ACCEPT_LANGUAGES);
528 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
529 IDS_DEFAULT_ENCODING);
530 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
531 IDS_STANDARD_FONT_IS_SERIF);
532 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
533 IDS_FIXED_FONT_FAMILY);
534 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
535 IDS_SERIF_FONT_FAMILY);
536 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
537 IDS_SANS_SERIF_FONT_FAMILY);
538 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
539 IDS_CURSIVE_FONT_FAMILY);
540 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
541 IDS_FANTASY_FONT_FAMILY);
542 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
543 IDS_DEFAULT_FONT_SIZE);
544 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
545 IDS_DEFAULT_FIXED_FONT_SIZE);
546 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
547 IDS_MINIMUM_FONT_SIZE);
548 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
549 IDS_MINIMUM_LOGICAL_FONT_SIZE);
550 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
551 IDS_USES_UNIVERSAL_DETECTOR);
552 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
553 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29554}
555
[email protected]13367f72009-07-08 16:39:02556// Returns true if contains content rendered by an extension.
557bool TabContents::HostsExtension() const {
558 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34559}
560
[email protected]cf28ec52010-04-09 22:56:34561AutoFillManager* TabContents::GetAutoFillManager() {
562 if (autofill_manager_.get() == NULL)
563 autofill_manager_.reset(new AutoFillManager(this));
564 return autofill_manager_.get();
565}
566
[email protected]6e95706d2009-04-23 22:55:01567PluginInstaller* TabContents::GetPluginInstaller() {
568 if (plugin_installer_.get() == NULL)
569 plugin_installer_.reset(new PluginInstaller(this));
570 return plugin_installer_.get();
571}
572
[email protected]1f18184a2010-07-21 19:34:49573TabContentsSSLHelper* TabContents::GetSSLHelper() {
574 if (ssl_helper_.get() == NULL)
575 ssl_helper_.reset(new TabContentsSSLHelper(this));
576 return ssl_helper_.get();
577}
578
[email protected]8cb5d5b2010-02-09 11:36:16579RenderProcessHost* TabContents::GetRenderProcessHost() const {
580 return render_manager_.current_host()->process();
581}
582
[email protected]9adb9692010-10-29 23:14:02583void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46584 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08585 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10586
[email protected]98aa0b52010-05-06 17:03:08587 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57588
[email protected]fca656c2010-02-10 20:30:10589 NotificationService::current()->Notify(
590 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
591 Source<TabContents>(this),
592 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49593}
594
[email protected]98aa0b52010-05-06 17:03:08595void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
596 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40597 return;
598
599 ExtensionsService* extension_service = profile()->GetExtensionsService();
[email protected]fa6a9102010-11-22 15:38:50600 if (!extension_service || !extension_service->is_ready())
601 return;
602
603 const Extension* extension =
604 extension_service->GetExtensionById(extension_app_id, false);
605 if (extension)
606 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40607}
608
[email protected]98aa0b52010-05-06 17:03:08609SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08610 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51611 return NULL;
612
[email protected]98aa0b52010-05-06 17:03:08613 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51614}
615
[email protected]d5f942ba2008-09-26 19:30:34616const GURL& TabContents::GetURL() const {
617 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57618 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54619 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34620}
621
[email protected]96d185d2009-04-24 03:28:54622const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55623 // Transient entries take precedence. They are used for interstitial pages
624 // that are shown on top of existing pages.
625 NavigationEntry* entry = controller_.GetTransientEntry();
626 if (entry)
627 return entry->GetTitleForDisplay(&controller_);
628
[email protected]96d185d2009-04-24 03:28:54629 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
630 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
631 if (our_dom_ui) {
632 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55633 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54634 if (!(entry && entry->IsViewSourceMode())) {
635 // Give the DOM UI the chance to override our title.
636 const string16& title = our_dom_ui->overridden_title();
637 if (!title.empty())
638 return title;
639 }
640 }
641
642 // We use the title for the last committed entry rather than a pending
643 // navigation entry. For example, when the user types in a URL, we want to
644 // keep the old page's title until the new load has committed and we get a new
645 // title.
[email protected]96d185d2009-04-24 03:28:54646 entry = controller_.GetLastCommittedEntry();
647 if (entry)
648 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54649 return EmptyString16();
650}
651
[email protected]bbbc1ef2010-02-12 18:03:41652// static
653string16 TabContents::GetDefaultTitle() {
654 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
655}
656
[email protected]d5f942ba2008-09-26 19:30:34657int32 TabContents::GetMaxPageID() {
658 if (GetSiteInstance())
659 return GetSiteInstance()->max_page_id();
660 else
661 return max_page_id_;
662}
663
664void TabContents::UpdateMaxPageID(int32 page_id) {
665 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34666 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34667 // testing.
668 if (GetSiteInstance())
669 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16670 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34671}
672
[email protected]96d185d2009-04-24 03:28:54673SiteInstance* TabContents::GetSiteInstance() const {
674 return render_manager_.current_host()->site_instance();
675}
676
[email protected]96d185d2009-04-24 03:28:54677bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15678 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54679 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15680 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01681 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54682 return true;
[email protected]8ab24cc2009-11-13 20:56:15683 }
[email protected]83e3895b2009-06-11 00:07:16684
[email protected]96d185d2009-04-24 03:28:54685 DOMUI* dom_ui = GetDOMUIForCurrentState();
686 if (dom_ui)
687 return !dom_ui->should_hide_url();
688 return true;
689}
690
[email protected]d5f942ba2008-09-26 19:30:34691SkBitmap TabContents::GetFavIcon() const {
692 // Like GetTitle(), we also want to use the favicon for the last committed
693 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57694 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47695 if (entry)
696 return entry->favicon().bitmap();
697
[email protected]ce3fa3c2009-04-20 19:55:57698 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34699 if (entry)
700 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34701 return SkBitmap();
702}
703
[email protected]0b303cc2009-09-28 22:35:15704bool TabContents::FavIconIsValid() const {
705 NavigationEntry* entry = controller_.GetTransientEntry();
706 if (entry)
707 return entry->favicon().is_valid();
708
709 entry = controller_.GetLastCommittedEntry();
710 if (entry)
711 return entry->favicon().is_valid();
712
713 return false;
714}
715
[email protected]96d185d2009-04-24 03:28:54716bool TabContents::ShouldDisplayFavIcon() {
717 // Always display a throbber during pending loads.
718 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
719 return true;
720
721 DOMUI* dom_ui = GetDOMUIForCurrentState();
722 if (dom_ui)
723 return !dom_ui->hide_favicon();
724 return true;
725}
726
[email protected]96d185d2009-04-24 03:28:54727std::wstring TabContents::GetStatusText() const {
728 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
729 return std::wstring();
730
731 switch (load_state_) {
732 case net::LOAD_STATE_WAITING_FOR_CACHE:
733 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04734 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
735 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54736 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
737 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
738 case net::LOAD_STATE_RESOLVING_HOST:
739 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
740 case net::LOAD_STATE_CONNECTING:
741 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06742 case net::LOAD_STATE_SSL_HANDSHAKE:
743 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54744 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56745 if (upload_size_)
746 return l10n_util::GetStringF(
747 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
748 static_cast<int>((100 * upload_position_) / upload_size_));
749 else
750 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54751 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
752 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
753 load_state_host_);
754 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
755 case net::LOAD_STATE_IDLE:
756 case net::LOAD_STATE_READING_RESPONSE:
757 break;
758 }
759
760 return std::wstring();
761}
762
[email protected]3c9e1872010-11-18 16:17:49763void TabContents::AddNavigationObserver(WebNavigationObserver* observer) {
764 web_navigation_observers_.AddObserver(observer);
765}
766
767void TabContents::RemoveNavigationObserver(WebNavigationObserver* observer) {
768 web_navigation_observers_.RemoveObserver(observer);
769}
770
[email protected]443b80e2010-12-14 00:42:23771void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
772 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34773 return;
774
[email protected]443b80e2010-12-14 00:42:23775 crashed_status_ = status;
776 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50777 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34778}
779
[email protected]744ef172009-10-16 21:53:46780void TabContents::PageActionStateChanged() {
781 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00782}
[email protected]ce5c4502009-05-06 16:46:11783
[email protected]d5f942ba2008-09-26 19:30:34784void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
785 if (delegate_)
786 delegate_->NavigationStateChanged(this, changed_flags);
787}
788
[email protected]96d185d2009-04-24 03:28:54789void TabContents::DidBecomeSelected() {
790 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16791 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
792 if (rwhv) {
793 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43794#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16795 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43796#endif
797 }
[email protected]96d185d2009-04-24 03:28:54798
[email protected]8cb5d5b2010-02-09 11:36:16799 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11800 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54801}
802
[email protected]1b072562010-12-13 19:37:45803void TabContents::FadeForInstant() {
804 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
805 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
806 if (rwhv)
807 rwhv->SetVisuallyDeemphasized(&whitish, true);
808}
809
810void TabContents::CancelInstantFade() {
811 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
812 if (rwhv)
813 rwhv->SetVisuallyDeemphasized(NULL, false);
814}
815
[email protected]96d185d2009-04-24 03:28:54816void TabContents::WasHidden() {
817 if (!capturing_contents()) {
818 // |render_view_host()| can be NULL if the user middle clicks a link to open
819 // a tab in then background, then closes the tab before selecting it. This
820 // is because closing the tab calls TabContents::Destroy(), which removes
821 // the |render_view_host()|; then when we actually destroy the window,
822 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16823 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
824 if (rwhv)
825 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54826 }
827
828 NotificationService::current()->Notify(
829 NotificationType::TAB_CONTENTS_HIDDEN,
830 Source<TabContents>(this),
831 NotificationService::NoDetails());
832}
833
[email protected]d5f942ba2008-09-26 19:30:34834void TabContents::Activate() {
835 if (delegate_)
836 delegate_->ActivateContents(this);
837}
838
[email protected]ea42e7782010-08-23 23:58:12839void TabContents::Deactivate() {
840 if (delegate_)
841 delegate_->DeactivateContents(this);
842}
843
[email protected]96d185d2009-04-24 03:28:54844void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16845 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
846 if (rwhv)
847 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54848}
849
850void TabContents::HideContents() {
851 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
852 // our superclass HideContents(), because some callers want to be very picky
853 // about the order in which these get called. In addition to making the code
854 // here practically impossible to understand, this also means we end up
855 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34856 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54857 WasHidden();
858}
859
[email protected]5aab5e22010-12-08 22:13:29860bool TabContents::NeedToFireBeforeUnload() {
861 // TODO(creis): Should we fire even for interstitial pages?
862 return notify_disconnection() &&
863 !showing_interstitial_page() &&
864 !render_view_host()->SuddenTerminationAllowed();
865}
866
[email protected]c0588052008-10-27 23:01:50867void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34868 WindowOpenDisposition disposition,
869 PageTransition::Type transition) {
870 if (delegate_)
[email protected]c0588052008-10-27 23:01:50871 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34872}
873
[email protected]1ccb3568d2010-02-19 10:51:16874bool TabContents::NavigateToPendingEntry(
875 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54876 return NavigateToEntry(*controller_.pending_entry(), reload_type);
877}
[email protected]96d185d2009-04-24 03:28:54878
[email protected]876bc832010-09-07 16:29:54879bool TabContents::NavigateToEntry(
880 const NavigationEntry& entry,
881 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54882 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
883 if (!dest_render_view_host)
884 return false; // Unable to create the desired render view host.
885
[email protected]770dd8b2010-05-24 18:11:39886 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
887 dest_render_view_host->EnablePreferredSizeChangedMode(
888 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
889 }
[email protected]9fb325e2010-05-06 18:23:24890
[email protected]05fdd492010-11-15 17:52:07891 // For security, we should never send non-DOM-UI URLs to a DOM UI renderer.
892 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58893 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40894 bool is_allowed_in_dom_ui_renderer =
[email protected]05fdd492010-11-15 17:52:07895 DOMUIFactory::IsURLAcceptableForDOMUI(profile(), entry.url());
[email protected]54ec6472010-04-09 19:39:58896 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40897 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58898
[email protected]96d185d2009-04-24 03:28:54899 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12900 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32901 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00902 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
903 dest_render_view_host,
904 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32905 }
[email protected]96d185d2009-04-24 03:28:54906
907 // Used for page load time metrics.
908 current_load_start_ = base::TimeTicks::Now();
909
910 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34911 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54912 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04913 if (delegate_) {
914 navigate_params.extra_headers =
915 delegate_->GetNavigationHeaders(navigate_params.url);
916 }
[email protected]056de2d2009-06-26 16:41:34917 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54918
919 if (entry.page_id() == -1) {
920 // HACK!! This code suppresses javascript: URLs from being added to
921 // session history, which is what we want to do for javascript: URLs that
922 // do not generate content. What we really need is a message from the
923 // renderer telling us that a new page was not created. The same message
924 // could be used for mailto: URLs and the like.
925 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
926 return false;
927 }
928
[email protected]3c9e1872010-11-18 16:17:49929 // Notify observers about navigation.
930 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
931 NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54932
[email protected]1ccb3568d2010-02-19 10:51:16933 if (reload_type != NavigationController::NO_RELOAD &&
934 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48935 FaviconService* favicon_service =
936 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
937 if (favicon_service)
938 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54939 }
940
[email protected]d5f942ba2008-09-26 19:30:34941 return true;
942}
943
[email protected]96d185d2009-04-24 03:28:54944void TabContents::Stop() {
945 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09946 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54947}
948
[email protected]96d185d2009-04-24 03:28:54949void TabContents::DisassociateFromPopupCount() {
950 render_view_host()->DisassociateFromPopupCount();
951}
952
953TabContents* TabContents::Clone() {
954 // We create a new SiteInstance so that the new tab won't share processes
955 // with the old one. This can be changed in the future if we need it to share
956 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32957 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54958 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07959 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54960 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08961 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08962 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54963 return tc;
964}
965
[email protected]4d677202009-07-19 07:37:12966void TabContents::ShowPageInfo(const GURL& url,
967 const NavigationEntry::SSLStatus& ssl,
968 bool show_history) {
969 if (!delegate_)
970 return;
971
[email protected]bb678332009-07-21 00:15:50972 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12973}
974
initial.commit09911bf2008-07-26 23:55:29975ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28976 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29977 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28978 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29979 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44980
981 if (child_windows_.size() == 1) {
982 window->ShowConstrainedWindow();
983 BlockTabContent(true);
984 }
985
initial.commit09911bf2008-07-26 23:55:29986 return window;
987}
988
[email protected]fa1cf0b82010-01-15 21:49:44989void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55990 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45991 // 70% opaque grey.
992 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55993 if (rwhv)
[email protected]1b072562010-12-13 19:37:45994 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44995 render_view_host()->set_ignore_input_events(blocked);
996 if (delegate_)
997 delegate_->SetTabContentBlocked(this, blocked);
998}
999
initial.commit09911bf2008-07-26 23:55:291000void TabContents::AddNewContents(TabContents* new_contents,
1001 WindowOpenDisposition disposition,
1002 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:291003 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:401004 if (all_contents_blocked_) {
1005 if (!blocked_contents_)
1006 blocked_contents_ = new BlockedContentContainer(this);
1007 blocked_contents_->AddTabContents(
1008 new_contents, disposition, initial_pos, user_gesture);
1009 return;
1010 }
1011
initial.commit09911bf2008-07-26 23:55:291012 if (!delegate_)
1013 return;
1014
[email protected]35f7d212009-04-29 21:19:271015 if ((disposition == NEW_POPUP) && !user_gesture &&
1016 !CommandLine::ForCurrentProcess()->HasSwitch(
1017 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:221018 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:311019 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:291020 delegate_->GetConstrainingContents(this)->AddPopup(
1021 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:311022 } else {
[email protected]0aa55312008-10-17 21:53:081023 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:291024 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1025 user_gesture);
[email protected]7f37dd92009-09-15 16:35:491026 NotificationService::current()->Notify(
1027 NotificationType::TAB_ADDED,
1028 Source<TabContentsDelegate>(delegate_),
1029 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291030 }
initial.commit09911bf2008-07-26 23:55:291031
[email protected]8cc8d492010-02-02 10:40:491032 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401033 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291034}
1035
[email protected]bcd9dc42010-01-23 16:38:181036bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201037 bool is_js_code, const std::string& code_string,
1038 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511039 RenderViewHost* host = render_view_host();
1040 if (!host)
1041 return false;
1042
1043 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171044 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511045 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351046}
1047
[email protected]96d185d2009-04-24 03:28:541048void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491049 if (is_being_destroyed_)
1050 return;
[email protected]9fb83e82010-07-02 18:24:551051 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491052 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401053 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541054}
1055
[email protected]5c9e97a2009-09-09 23:48:301056gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541057 return view_->GetContentNativeView();
1058}
1059
1060gfx::NativeView TabContents::GetNativeView() const {
1061 return view_->GetNativeView();
1062}
1063
1064void TabContents::GetContainerBounds(gfx::Rect *out) const {
1065 view_->GetContainerBounds(out);
1066}
1067
1068void TabContents::Focus() {
1069 view_->Focus();
1070}
1071
[email protected]90daadb42009-06-08 21:27:281072void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541073 if (showing_interstitial_page()) {
1074 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1075 return;
1076 }
[email protected]96d185d2009-04-24 03:28:541077 render_view_host()->SetInitialFocus(reverse);
1078}
1079
1080bool TabContents::FocusLocationBarByDefault() {
1081 DOMUI* dom_ui = GetDOMUIForCurrentState();
1082 if (dom_ui)
1083 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431084 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251085 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431086 return true;
[email protected]96d185d2009-04-24 03:28:541087 return false;
1088}
1089
[email protected]a26dc362010-04-23 01:48:581090void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381091 if (delegate())
[email protected]a26dc362010-04-23 01:48:581092 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381093}
1094
[email protected]616ed5a2008-11-21 22:27:241095void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321096 if (delegate_ && !delegate_->infobars_enabled()) {
1097 delegate->InfoBarClosed();
1098 return;
1099 }
1100
[email protected]616ed5a2008-11-21 22:27:241101 // Look through the existing InfoBarDelegates we have for a match. If we've
1102 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051103 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451104 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1105 // Tell the new infobar to close so that it can clean itself up.
1106 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241107 return;
[email protected]6d27a7b2009-12-18 23:25:451108 }
[email protected]616ed5a2008-11-21 22:27:241109 }
1110
1111 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561112 NotificationService::current()->Notify(
1113 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1114 Source<TabContents>(this),
1115 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241116
1117 // Add ourselves as an observer for navigations the first time a delegate is
1118 // added. We use this notification to expire InfoBars that need to expire on
1119 // page transitions.
1120 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561121 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571122 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241123 }
1124}
1125
1126void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321127 if (delegate_ && !delegate_->infobars_enabled()) {
1128 return;
1129 }
1130
[email protected]616ed5a2008-11-21 22:27:241131 std::vector<InfoBarDelegate*>::iterator it =
1132 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1133 if (it != infobar_delegates_.end()) {
1134 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561135 NotificationService::current()->Notify(
1136 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1137 Source<TabContents>(this),
1138 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241139
[email protected]cdadf6f2010-08-20 16:36:081140 // Just to be safe, make sure the delegate was not removed by an observer.
1141 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1142 if (it != infobar_delegates_.end()) {
1143 infobar_delegates_.erase(it);
1144 // Remove ourselves as an observer if we are tracking no more InfoBars.
1145 if (infobar_delegates_.empty()) {
1146 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1147 Source<NavigationController>(&controller_));
1148 }
1149 } else {
1150 // If you hit this NOTREACHED, please comment in bug
1151 // http://crbug.com/50428 how you got there.
1152 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031153 }
[email protected]616ed5a2008-11-21 22:27:241154 }
1155}
[email protected]3edd9522009-03-04 22:19:411156
[email protected]f81821c2009-08-07 01:29:471157void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1158 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321159 if (delegate_ && !delegate_->infobars_enabled()) {
1160 new_delegate->InfoBarClosed();
1161 return;
1162 }
1163
[email protected]f81821c2009-08-07 01:29:471164 std::vector<InfoBarDelegate*>::iterator it =
1165 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1166 DCHECK(it != infobar_delegates_.end());
1167
1168 // Notify the container about the change of plans.
1169 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1170 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1171 old_delegate, new_delegate));
1172 NotificationService::current()->Notify(
1173 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1174 Source<TabContents>(this),
1175 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1176
[email protected]cdadf6f2010-08-20 16:36:081177 // Just to be safe, make sure the delegate was not removed by an observer.
1178 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1179 if (it != infobar_delegates_.end()) {
1180 // Remove the old one.
1181 infobar_delegates_.erase(it);
1182 } else {
1183 // If you hit this NOTREACHED, please comment in bug
1184 // http://crbug.com/50428 how you got there.
1185 NOTREACHED();
1186 }
[email protected]f81821c2009-08-07 01:29:471187
1188 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081189 DCHECK(find(infobar_delegates_.begin(),
1190 infobar_delegates_.end(), new_delegate) ==
1191 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471192 infobar_delegates_.push_back(new_delegate);
1193}
1194
[email protected]20ede072009-10-06 00:28:351195bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271196 if (showing_interstitial_page())
1197 return false;
1198
[email protected]c8f74942010-09-03 10:04:141199 // Do not show bookmarks bar if bookmarks aren't enabled.
1200 if (!browser_defaults::bookmarks_enabled)
1201 return false;
1202
[email protected]96d185d2009-04-24 03:28:541203 // See GetDOMUIForCurrentState() comment for more info. This case is very
1204 // similar, but for non-first loads, we want to use the committed entry. This
1205 // is so the bookmarks bar disappears at the same time the page does.
1206 if (controller_.GetLastCommittedEntry()) {
1207 // Not the first load, always use the committed DOM UI.
[email protected]d6219912010-11-17 19:47:371208 return (render_manager_.dom_ui() == NULL) ?
1209 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541210 }
1211
1212 // When it's the first load, we know either the pending one or the committed
1213 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1214 // of them will be valid, so we can just check both.
1215 if (render_manager_.pending_dom_ui())
1216 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
[email protected]d6219912010-11-17 19:47:371217 return (render_manager_.dom_ui() == NULL) ?
1218 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541219}
1220
[email protected]3edd9522009-03-04 22:19:411221void TabContents::ToolbarSizeChanged(bool is_animating) {
1222 TabContentsDelegate* d = delegate();
1223 if (d)
1224 d->ToolbarSizeChanged(this, is_animating);
1225}
[email protected]616ed5a2008-11-21 22:27:241226
[email protected]fc6fb7fb2009-11-07 02:35:041227bool TabContents::CanDownload(int request_id) {
1228 TabContentsDelegate* d = delegate();
1229 if (d)
1230 return d->CanDownload(request_id);
1231 return true;
1232}
1233
[email protected]d5f942ba2008-09-26 19:30:341234void TabContents::OnStartDownload(DownloadItem* download) {
1235 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341236
1237 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311238 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341239
[email protected]5b928b62010-08-03 11:46:511240 if (tab_contents && tab_contents->delegate())
1241 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411242}
[email protected]3edd9522009-03-04 22:19:411243
[email protected]d5f942ba2008-09-26 19:30:341244void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371245 ConstrainedWindowList::iterator i(
1246 std::find(child_windows_.begin(), child_windows_.end(), window));
1247 bool removed_topmost_window = i == child_windows_.begin();
1248 if (i != child_windows_.end())
1249 child_windows_.erase(i);
1250 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441251 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371252 } else {
1253 if (removed_topmost_window)
1254 child_windows_[0]->ShowConstrainedWindow();
1255 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441256 }
[email protected]66ba4932009-06-04 19:22:131257}
[email protected]d5f942ba2008-09-26 19:30:341258
[email protected]c65e2f152010-10-14 15:30:401259void TabContents::WillCloseBlockedContentContainer(
1260 BlockedContentContainer* container) {
1261 DCHECK(blocked_contents_ == container);
1262 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491263 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341264}
1265
[email protected]d5f942ba2008-09-26 19:30:341266void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351267#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061268 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351269#endif
[email protected]d5f942ba2008-09-26 19:30:341270}
1271
[email protected]c1dc9f132009-11-20 23:13:211272void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121273 bool forward_direction,
1274 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211275 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011276 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211277 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531278 string16 last_search_prepopulate_text =
1279 FindBarState::GetLastPrepopulateText(profile());
1280
[email protected]87fae512009-12-11 02:20:211281 // Try the last thing we searched for on this tab, then the last thing
1282 // searched for on any tab.
1283 if (!previous_find_text_.empty())
1284 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531285 else if (!last_search_prepopulate_text.empty())
1286 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211287 else
[email protected]e491f1c2009-05-22 20:28:121288 return;
[email protected]e491f1c2009-05-22 20:28:121289 }
[email protected]6e95706d2009-04-23 22:55:011290
[email protected]101c90e2009-10-26 21:14:441291 // Keep track of the previous search.
1292 previous_find_text_ = find_text_;
1293
[email protected]6e95706d2009-04-23 22:55:011294 // This is a FindNext operation if we are searching for the same text again,
1295 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1296 // exception to this is if the Find was aborted (then we don't want FindNext
1297 // because the highlighting has been cleared and we need it to reappear). We
1298 // therefore treat FindNext after an aborted Find operation as a full fledged
1299 // Find.
[email protected]c1dc9f132009-11-20 23:13:211300 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121301 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011302 !find_op_aborted_;
1303 if (!find_next)
1304 current_find_request_id_ = find_request_id_counter_++;
1305
[email protected]c1dc9f132009-11-20 23:13:211306 if (!search_string.empty())
1307 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121308 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011309
1310 find_op_aborted_ = false;
1311
1312 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531313 FindBarState* find_bar_state = profile()->GetFindBarState();
1314 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011315 render_view_host()->StartFinding(current_find_request_id_,
1316 find_text_,
1317 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121318 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011319 find_next);
1320}
1321
[email protected]5bc8fe92010-03-11 18:19:001322void TabContents::StopFinding(
1323 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011324 if (selection_action == FindBarController::kClearSelection) {
1325 // kClearSelection means the find string has been cleared by the user, but
1326 // the UI has not been dismissed. In that case we want to clear the
1327 // previously remembered search (http://crbug.com/42639).
1328 previous_find_text_ = string16();
1329 } else {
[email protected]2d2dffc2009-06-09 21:41:001330 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011331 if (!find_text_.empty())
1332 previous_find_text_ = find_text_;
1333 }
[email protected]101c90e2009-10-26 21:14:441334 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011335 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121336 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001337 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011338}
1339
[email protected]420ae012009-04-24 05:16:321340void TabContents::OnSavePage() {
1341 // If we can not save the page, try to download it.
1342 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1343 DownloadManager* dlm = profile()->GetDownloadManager();
1344 const GURL& current_page_url = GetURL();
1345 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221346 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321347 return;
1348 }
1349
1350 Stop();
1351
1352 // Create the save package and possibly prompt the user for the name to save
1353 // the page as. The user prompt is an asynchronous operation that runs on
1354 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221355 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321356 save_package_->GetSaveInfo();
1357}
1358
1359// Used in automated testing to bypass prompting the user for file names.
1360// Instead, the names and paths are hard coded rather than running them through
1361// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111362bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321363 SavePackage::SavePackageType save_type) {
1364 // Stop the page from navigating.
1365 Stop();
1366
[email protected]828cabe2009-09-26 22:47:111367 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591368 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321369}
1370
[email protected]89d6e6e2009-12-03 23:06:511371void TabContents::EmailPageLocation() {
1372 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1373 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1374 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1375 title + "&body=%0A%0A" + page_url;
1376 platform_util::OpenExternal(GURL(mailto));
1377}
1378
[email protected]420ae012009-04-24 05:16:321379void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161380 if (CommandLine::ForCurrentProcess()->HasSwitch(
1381 switches::kEnablePrintPreview)) {
1382 if (showing_interstitial_page())
1383 return;
1384 render_view_host()->PrintPreview();
1385 } else {
1386 PrintNow();
1387 }
[email protected]420ae012009-04-24 05:16:321388}
1389
1390bool TabContents::PrintNow() {
1391 // We can't print interstitial page for now.
1392 if (showing_interstitial_page())
1393 return false;
1394
1395 return render_view_host()->PrintPages();
1396}
1397
[email protected]82270452009-06-19 15:58:011398void TabContents::PrintingDone(int document_cookie, bool success) {
1399 render_view_host()->PrintingDone(document_cookie, success);
1400}
1401
[email protected]420ae012009-04-24 05:16:321402bool TabContents::IsActiveEntry(int32 page_id) {
1403 NavigationEntry* active_entry = controller_.GetActiveEntry();
1404 return (active_entry != NULL &&
1405 active_entry->site_instance() == GetSiteInstance() &&
1406 active_entry->page_id() == page_id);
1407}
1408
[email protected]b2fe07d12010-02-09 14:38:081409void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161410 set_encoding(encoding);
1411 render_view_host()->SetPageEncoding(encoding);
1412}
1413
[email protected]b2fe07d12010-02-09 14:38:081414void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161415 reset_encoding();
1416 render_view_host()->ResetPageEncodingToDefault();
1417}
1418
1419void TabContents::WindowMoveOrResizeStarted() {
1420 render_view_host()->WindowMoveOrResizeStarted();
1421}
1422
[email protected]c65e2f152010-10-14 15:30:401423void TabContents::SetAllContentsBlocked(bool value) {
1424 if (all_contents_blocked_ == value)
1425 return;
1426
1427 all_contents_blocked_ = value;
1428 if (!all_contents_blocked_ && blocked_contents_) {
1429 std::vector<TabContents*> blocked;
1430 blocked_contents_->GetBlockedContents(&blocked);
1431 for (size_t i = 0; i < blocked.size(); ++i)
1432 blocked_contents_->LaunchForContents(blocked[i]);
1433 }
1434}
1435
[email protected]3f8eb7f2009-10-02 23:58:051436void TabContents::LogNewTabTime(const std::string& event_name) {
1437 // Not all new tab pages get timed. In those cases, we don't have a
1438 // new_tab_start_time_.
1439 if (new_tab_start_time_.is_null())
1440 return;
1441
1442 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441443 MetricEventDurationDetails details(event_name,
1444 static_cast<int>(duration.InMilliseconds()));
1445
[email protected]7ab1e7d62009-10-14 23:32:011446 if (event_name == "Tab.NewTabScriptStart") {
1447 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1448 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1449 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1450 } else if (event_name == "Tab.NewTabOnload") {
1451 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051452 // The new tab page has finished loading; reset it.
1453 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441454 } else {
1455 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051456 }
[email protected]84abba62009-10-07 17:01:441457 NotificationService::current()->Notify(
1458 NotificationType::METRIC_EVENT_DURATION,
1459 Source<TabContents>(this),
1460 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051461}
1462
[email protected]7ab1e7d62009-10-14 23:32:011463void TabContents::OnCloseStarted() {
1464 if (tab_close_start_time_.is_null())
1465 tab_close_start_time_ = base::TimeTicks::Now();
1466}
1467
[email protected]46624bf2010-06-09 16:04:191468bool TabContents::ShouldAcceptDragAndDrop() const {
1469#if defined(OS_CHROMEOS)
1470 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1471 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201472 if (delegate() && delegate()->IsPopup(this))
1473 return false;
1474 return true;
[email protected]46624bf2010-06-09 16:04:191475#else
1476 return true;
1477#endif
1478}
1479
[email protected]ec0b6c42010-08-26 03:16:581480void TabContents::UpdateHistoryForNavigation(
1481 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1482 if (profile()->IsOffTheRecord())
1483 return;
1484
1485 // Add to history service.
1486 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1487 if (hs)
1488 hs->AddPage(*add_page_args);
1489}
1490
1491void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1492 if (profile()->IsOffTheRecord())
1493 return;
1494
1495 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1496 if (hs)
1497 hs->SetPageTitle(entry.virtual_url(), entry.title());
1498}
1499
[email protected]d0b8d092010-10-25 04:05:171500double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251501 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1502 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171503 return 0;
[email protected]b75b8292010-10-01 07:28:251504
1505 double zoom_level;
1506 if (temporary_zoom_settings_) {
1507 zoom_level = zoom_map->GetTemporaryZoomLevel(
1508 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1509 } else {
1510 zoom_level = zoom_map->GetZoomLevel(GetURL());
1511 }
[email protected]d0b8d092010-10-25 04:05:171512 return zoom_level;
1513}
[email protected]b75b8292010-10-01 07:28:251514
[email protected]d0b8d092010-10-25 04:05:171515int TabContents::GetZoomPercent(bool* enable_increment,
1516 bool* enable_decrement) {
1517 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251518 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171519 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251520 *enable_decrement = percent > minimum_zoom_percent_;
1521 *enable_increment = percent < maximum_zoom_percent_;
1522 return percent;
1523}
1524
[email protected]96d185d2009-04-24 03:28:541525// Notifies the RenderWidgetHost instance about the fact that the page is
1526// loading, or done loading and calls the base implementation.
1527void TabContents::SetIsLoading(bool is_loading,
1528 LoadNotificationDetails* details) {
1529 if (is_loading == is_loading_)
1530 return;
1531
1532 if (!is_loading) {
1533 load_state_ = net::LOAD_STATE_IDLE;
1534 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561535 upload_size_ = 0;
1536 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541537 }
1538
1539 render_manager_.SetIsLoading(is_loading);
1540
1541 is_loading_ = is_loading;
1542 waiting_for_response_ = is_loading;
1543
[email protected]6ebdc9b2010-09-27 16:55:571544 if (delegate_)
1545 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351546 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541547
1548 NotificationType type = is_loading ? NotificationType::LOAD_START :
1549 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111550 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541551 if (details)
1552 det = Details<LoadNotificationDetails>(details);
1553 NotificationService::current()->Notify(type,
1554 Source<NavigationController>(&controller_),
1555 det);
1556}
1557
[email protected]b6c874582009-05-08 19:38:311558void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291559 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061560 // A page can't spawn popups (or do anything else, either) until its load
1561 // commits, so when we reach here, the popup was spawned by the
1562 // NavigationController's last committed entry, not the active entry. For
1563 // example, if a page opens a popup in an onunload() handler, then the active
1564 // entry is the page to be loaded as we navigate away from the unloading
1565 // page. For this reason, we can't use GetURL() to get the opener URL,
1566 // because it returns the active entry.
1567 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1568 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1569
1570 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491571 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091572 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491573 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1574 } else {
[email protected]c65e2f152010-10-14 15:30:401575 if (!blocked_contents_)
1576 blocked_contents_ = new BlockedContentContainer(this);
1577 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1578 true);
[email protected]55126132010-08-19 14:53:281579 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1580 std::string());
[email protected]8cc8d492010-02-02 10:40:491581 }
[email protected]b9681312008-11-07 00:08:261582}
[email protected]616ed5a2008-11-21 22:27:241583
[email protected]616ed5a2008-11-21 22:27:241584void TabContents::ExpireInfoBars(
1585 const NavigationController::LoadCommittedDetails& details) {
1586 // Only hide InfoBars when the user has done something that makes the main
1587 // frame load. We don't want various automatic or subframe navigations making
1588 // it disappear.
1589 if (!details.is_user_initiated_main_frame_load())
1590 return;
1591
[email protected]f86a07022008-11-25 01:06:051592 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241593 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081594 if (!delegate) {
1595 // If you hit this NOTREACHED, please comment in bug
1596 // http://crbug.com/50428 how you got there.
1597 NOTREACHED();
1598 continue;
1599 }
1600
[email protected]f86a07022008-11-25 01:06:051601 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241602 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241603 }
1604}
[email protected]fdd61c62009-04-22 19:22:571605
[email protected]96d185d2009-04-24 03:28:541606DOMUI* TabContents::GetDOMUIForCurrentState() {
1607 // When there is a pending navigation entry, we want to use the pending DOMUI
1608 // that goes along with it to control the basic flags. For example, we want to
1609 // show the pending URL in the URL bar, so we want the display_url flag to
1610 // be from the pending entry.
1611 //
1612 // The confusion comes because there are multiple possibilities for the
1613 // initial load in a tab as a side effect of the way the RenderViewHostManager
1614 // works.
1615 //
1616 // - For the very first tab the load looks "normal". The new tab DOM UI is
1617 // the pending one, and we want it to apply here.
1618 //
1619 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1620 // get switched to the one previously associated with the new tab pages.
1621 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1622 // have a committed DOM UI in this case.
1623 //
1624 // This condition handles all of these cases:
1625 //
1626 // - First load in first tab: no committed nav entry + pending nav entry +
1627 // pending dom ui:
1628 // -> Use pending DOM UI if any.
1629 //
1630 // - First load in second tab: no committed nav entry + pending nav entry +
1631 // no pending DOM UI:
1632 // -> Use the committed DOM UI if any.
1633 //
1634 // - Second navigation in any tab: committed nav entry + pending nav entry:
1635 // -> Use pending DOM UI if any.
1636 //
1637 // - Normal state with no load: committed nav entry + no pending nav entry:
1638 // -> Use committed DOM UI.
1639 if (controller_.pending_entry() &&
1640 (controller_.GetLastCommittedEntry() ||
1641 render_manager_.pending_dom_ui()))
1642 return render_manager_.pending_dom_ui();
1643 return render_manager_.dom_ui();
1644}
[email protected]420ae012009-04-24 05:16:321645
1646void TabContents::DidNavigateMainFramePostCommit(
1647 const NavigationController::LoadCommittedDetails& details,
1648 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441649 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1650 // If this is a window.open navigation, use the same DOMUI as the renderer
1651 // that opened the window, as long as both renderers have the same
1652 // privileges.
[email protected]583d45c12010-08-31 02:48:121653 if (opener_dom_ui_type_ ==
1654 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441655 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1656 // dom_ui might be NULL if the URL refers to a non-existent extension.
1657 if (dom_ui) {
1658 render_manager_.SetDOMUIPostCommit(dom_ui);
1659 dom_ui->RenderViewCreated(render_view_host());
1660 }
1661 }
1662 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1663 }
1664
[email protected]420ae012009-04-24 05:16:321665 if (details.is_user_initiated_main_frame_load()) {
1666 // Clear the status bubble. This is a workaround for a bug where WebKit
1667 // doesn't let us know that the cursor left an element during a
1668 // transition (this is also why the mouse cursor remains as a hand after
1669 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1670 // clear the bubble when a user navigates to a named anchor in the same
1671 // page.
1672 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321673 }
1674
1675 // The keyword generator uses the navigation entries, so must be called after
1676 // the commit.
1677 GenerateKeywordIfNecessary(params);
1678
1679 // Allow the new page to set the title again.
1680 received_page_title_ = false;
1681
1682 // Get the favicon, either from history or request it from the net.
1683 fav_icon_helper_.FetchFavIcon(details.entry->url());
1684
[email protected]0de80162010-02-03 04:52:351685 // Clear all page actions, blocked content notifications and browser actions
1686 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141687 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081688 ExtensionsService* service = profile()->GetExtensionsService();
1689 if (service) {
1690 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571691 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081692 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521693 if (browser_action) {
1694 browser_action->ClearAllValuesForTab(controller().session_id().id());
1695 NotificationService::current()->Notify(
1696 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571697 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521698 NotificationService::NoDetails());
1699 }
[email protected]92c6f9b92009-10-24 04:35:081700
[email protected]5d246db22009-10-27 06:17:571701 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521702 service->extensions()->at(i)->page_action();
1703 if (page_action) {
1704 page_action->ClearAllValuesForTab(controller().session_id().id());
1705 PageActionStateChanged();
1706 }
[email protected]92c6f9b92009-10-24 04:35:081707 }
[email protected]aece2c7f2009-08-27 20:43:171708 }
[email protected]0de80162010-02-03 04:52:351709
1710 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401711 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341712 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401713 blocked_contents_->Destroy();
1714 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351715 }
1716
1717 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411718 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551719 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471720
1721 // Once the main frame is navigated, we're no longer considered to have
1722 // displayed insecure content.
1723 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171724 }
[email protected]ce5c4502009-05-06 16:46:111725
[email protected]8cc8d492010-02-02 10:40:491726 // Close constrained windows if necessary.
1727 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1728 details.previous_url, details.entry->url()))
1729 CloseConstrainedWindows();
1730
[email protected]420ae012009-04-24 05:16:321731 // Update the starred state.
1732 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531733
[email protected]3c9e1872010-11-18 16:17:491734 // Notify observers about navigation.
1735 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1736 DidNavigateMainFramePostCommit(details, params));
1737
[email protected]c07c9752010-03-12 05:57:531738 // Clear the cache of forms in AutoFill.
1739 if (autofill_manager_.get())
1740 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321741}
1742
1743void TabContents::DidNavigateAnyFramePostCommit(
1744 RenderViewHost* render_view_host,
1745 const NavigationController::LoadCommittedDetails& details,
1746 const ViewHostMsg_FrameNavigate_Params& params) {
1747 // If we navigate, start showing messages again. This does nothing to prevent
1748 // a malicious script from spamming messages, since the script could just
1749 // reload the page to stop blocking.
1750 suppress_javascript_messages_ = false;
1751
[email protected]3c9e1872010-11-18 16:17:491752 // Notify observers about navigation.
1753 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1754 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551755
1756 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581757 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321758}
1759
[email protected]8cc8d492010-02-02 10:40:491760void TabContents::CloseConstrainedWindows() {
1761 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321762 // We use indices instead of iterators in case CloseWindow does something
1763 // that may invalidate an iterator.
1764 int size = static_cast<int>(child_windows_.size());
1765 for (int i = size - 1; i >= 0; --i) {
1766 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441767 if (window) {
[email protected]420ae012009-04-24 05:16:321768 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441769 BlockTabContent(false);
1770 }
[email protected]420ae012009-04-24 05:16:321771 }
1772}
1773
1774void TabContents::UpdateStarredStateForCurrentURL() {
1775 BookmarkModel* model = profile()->GetBookmarkModel();
1776 const bool old_state = is_starred_;
1777 is_starred_ = (model && model->IsBookmarked(GetURL()));
1778
1779 if (is_starred_ != old_state && delegate())
1780 delegate()->URLStarredChanged(this, is_starred_);
1781}
1782
1783void TabContents::UpdateAlternateErrorPageURL() {
1784 GURL url = GetAlternateErrorPageURL();
1785 render_view_host()->SetAlternateErrorPageURL(url);
1786}
1787
1788void TabContents::UpdateWebPreferences() {
1789 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1790}
1791
[email protected]d0b8d092010-10-25 04:05:171792void TabContents::UpdateZoomLevel() {
1793 render_view_host()->SetZoomLevel(GetZoomLevel());
1794}
1795
[email protected]420ae012009-04-24 05:16:321796void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1797 RenderViewHost* rvh) {
1798 // If we are creating a RVH for a restored controller, then we might
1799 // have more page IDs than the SiteInstance's current max page ID. We must
1800 // make sure that the max page ID is larger than any restored page ID.
1801 // Note that it is ok for conflicting page IDs to exist in another tab
1802 // (i.e., NavigationController), but if any page ID is larger than the max,
1803 // the back/forward list will get confused.
1804 int max_restored_page_id = controller_.max_restored_page_id();
1805 if (max_restored_page_id > 0) {
1806 int curr_max_page_id = site_instance->max_page_id();
1807 if (max_restored_page_id > curr_max_page_id) {
1808 // Need to update the site instance immediately.
1809 site_instance->UpdateMaxPageID(max_restored_page_id);
1810
1811 // Also tell the renderer to update its internal representation. We
1812 // need to reserve enough IDs to make all restored page IDs less than
1813 // the max.
1814 if (curr_max_page_id < 0)
1815 curr_max_page_id = 0;
1816 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1817 }
1818 }
1819}
1820
[email protected]ec0b6c42010-08-26 03:16:581821scoped_refptr<history::HistoryAddPageArgs>
1822TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541823 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471824 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321825 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581826 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1827 new history::HistoryAddPageArgs(
1828 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1829 params.redirects, params.transition, history::SOURCE_BROWSED,
1830 details.did_replace_entry));
1831 if (PageTransition::IsMainFrame(params.transition) &&
1832 virtual_url != params.url) {
1833 // Hack on the "virtual" URL so that it will appear in history. For some
1834 // types of URLs, we will display a magic URL that is different from where
1835 // the page is actually navigated. We want the user to see in history what
1836 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1837 // only applies to the main frame, as the virtual URL doesn't apply to
1838 // sub-frames.
1839 add_page_args->url = virtual_url;
1840 if (!add_page_args->redirects.empty())
1841 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321842 }
[email protected]ec0b6c42010-08-26 03:16:581843 return add_page_args;
[email protected]420ae012009-04-24 05:16:321844}
1845
1846bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1847 const std::wstring& title) {
1848 // For file URLs without a title, use the pathname instead. In the case of a
1849 // synthesized title, we don't want the update to count toward the "one set
1850 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251851 string16 final_title;
[email protected]420ae012009-04-24 05:16:321852 bool explicit_set;
1853 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251854 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321855 explicit_set = false; // Don't count synthetic titles toward the set limit.
1856 } else {
[email protected]e53668962010-06-23 15:35:251857 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321858 explicit_set = true;
1859 }
1860
[email protected]e53668962010-06-23 15:35:251861 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321862 return false; // Nothing changed, don't bother.
1863
[email protected]e53668962010-06-23 15:35:251864 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321865
[email protected]ec0b6c42010-08-26 03:16:581866 if (!received_page_title_) {
1867 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321868 received_page_title_ = explicit_set;
1869 }
1870
1871 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251872 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321873
[email protected]cbc0e1b2010-04-12 18:33:041874 NotificationService::current()->Notify(
1875 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1876 Source<TabContents>(this),
1877 NotificationService::NoDetails());
1878
[email protected]420ae012009-04-24 05:16:321879 return true;
1880}
1881
1882void TabContents::NotifySwapped() {
1883 // After sending out a swap notification, we need to send a disconnect
1884 // notification so that clients that pick up a pointer to |this| can NULL the
1885 // pointer. See Bug 1230284.
1886 notify_disconnection_ = true;
1887 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341888 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221889 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321890 NotificationService::NoDetails());
1891}
1892
1893void TabContents::NotifyConnected() {
1894 notify_disconnection_ = true;
1895 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341896 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221897 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321898 NotificationService::NoDetails());
1899}
1900
1901void TabContents::NotifyDisconnected() {
1902 if (!notify_disconnection_)
1903 return;
1904
1905 notify_disconnection_ = false;
1906 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341907 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221908 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321909 NotificationService::NoDetails());
1910}
1911
1912void TabContents::GenerateKeywordIfNecessary(
1913 const ViewHostMsg_FrameNavigate_Params& params) {
1914 if (!params.searchable_form_url.is_valid())
1915 return;
1916
1917 if (profile()->IsOffTheRecord())
1918 return;
1919
1920 int last_index = controller_.last_committed_entry_index();
1921 // When there was no previous page, the last index will be 0. This is
1922 // normally due to a form submit that opened in a new tab.
1923 // TODO(brettw) bug 916126: we should support keywords when form submits
1924 // happen in new tabs.
1925 if (last_index <= 0)
1926 return;
1927 const NavigationEntry* previous_entry =
1928 controller_.GetEntryAtIndex(last_index - 1);
1929 if (IsFormSubmit(previous_entry)) {
1930 // Only generate a keyword if the previous page wasn't itself a form
1931 // submit.
1932 return;
1933 }
1934
1935 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1936 previous_entry->user_typed_url() : previous_entry->url();
1937 std::wstring keyword =
1938 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1939 if (keyword.empty())
1940 return;
1941
1942 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1943 if (!url_model)
1944 return;
1945
1946 if (!url_model->loaded()) {
1947 url_model->Load();
1948 return;
1949 }
1950
1951 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191952 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321953 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1954 return;
1955
1956 if (current_url) {
1957 if (current_url->originating_url().is_valid()) {
1958 // The existing keyword was generated from an OpenSearch description
1959 // document, don't regenerate.
1960 return;
1961 }
1962 url_model->Remove(current_url);
1963 }
1964 TemplateURL* new_url = new TemplateURL();
1965 new_url->set_keyword(keyword);
1966 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191967 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321968 new_url->add_input_encoding(params.searchable_form_encoding);
1969 DCHECK(controller_.GetLastCommittedEntry());
1970 const GURL& favicon_url =
1971 controller_.GetLastCommittedEntry()->favicon().url();
1972 if (favicon_url.is_valid()) {
1973 new_url->SetFavIconURL(favicon_url);
1974 } else {
1975 // The favicon url isn't valid. This means there really isn't a favicon,
1976 // or the favicon url wasn't obtained before the load started. This assumes
1977 // the later.
1978 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1979 // its url.
1980 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1981 }
1982 new_url->set_safe_for_autoreplace(true);
1983 url_model->Add(new_url);
1984}
1985
[email protected]bf5c2ff392009-07-08 16:24:331986void TabContents::OnUserGesture() {
1987 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011988 DownloadRequestLimiter* limiter =
1989 g_browser_process->download_request_limiter();
1990 if (limiter)
1991 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261992 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331993}
1994
1995void TabContents::OnFindReply(int request_id,
1996 int number_of_matches,
1997 const gfx::Rect& selection_rect,
1998 int active_match_ordinal,
1999 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:422000 // Ignore responses for requests that have been aborted.
2001 if (find_op_aborted_)
2002 return;
2003
[email protected]bf5c2ff392009-07-08 16:24:332004 // Ignore responses for requests other than the one we have most recently
2005 // issued. That way we won't act on stale results when the user has
2006 // already typed in another query.
2007 if (request_id != current_find_request_id_)
2008 return;
2009
2010 if (number_of_matches == -1)
2011 number_of_matches = last_search_result_.number_of_matches();
2012 if (active_match_ordinal == -1)
2013 active_match_ordinal = last_search_result_.active_match_ordinal();
2014
2015 gfx::Rect selection = selection_rect;
2016 if (selection.IsEmpty())
2017 selection = last_search_result_.selection_rect();
2018
2019 // Notify the UI, automation and any other observers that a find result was
2020 // found.
2021 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
2022 selection, active_match_ordinal,
2023 final_update);
2024 NotificationService::current()->Notify(
2025 NotificationType::FIND_RESULT_AVAILABLE,
2026 Source<TabContents>(this),
2027 Details<FindNotificationDetails>(&last_search_result_));
2028}
2029
2030void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542031 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2032 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2033 if (!entry)
2034 return;
2035 // Note that we don't call NavigationController::GotToOffset() as we don't
2036 // want to create a pending navigation entry (it might end up lingering
2037 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522038 entry->set_transition_type(entry->transition_type() |
2039 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542040 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2041 }
[email protected]bf5c2ff392009-07-08 16:24:332042}
2043
[email protected]bf5c2ff392009-07-08 16:24:332044void TabContents::OnMissingPluginStatus(int status) {
2045#if defined(OS_WIN)
2046// TODO(PORT): pull in when plug-ins work
2047 GetPluginInstaller()->OnMissingPluginStatus(status);
2048#endif
2049}
2050
2051void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332052 DCHECK(!plugin_path.value().empty());
2053
2054 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]45446a52010-11-04 17:41:002055 WebPluginInfo plugin_info;
2056 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
2057 plugin_path, &plugin_info) &&
2058 !plugin_info.name.empty()) {
2059 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372060#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002061 // Many plugins on the Mac have .plugin in the actual name, which looks
2062 // terrible, so look for that and strip it off if present.
2063 const std::wstring plugin_extension(L".plugin");
2064 if (EndsWith(plugin_name, plugin_extension, true))
2065 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372066#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332067 }
[email protected]2ae8a922010-06-28 20:27:532068 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2069 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332070 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582071 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2072 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532073 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332074}
2075
2076void TabContents::OnCrashedWorker() {
2077 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582078 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422079 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332080}
2081
[email protected]38789d82010-11-17 06:03:442082void TabContents::OnDidGetApplicationInfo(int32 page_id,
2083 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512084 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332085
[email protected]ed5431872009-11-17 08:39:512086 if (delegate())
2087 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332088}
2089
[email protected]bb461532010-11-26 21:50:232090void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
2091 if (delegate())
2092 delegate()->OnInstallApplication(this, info);
2093}
2094
[email protected]851b1eb2010-08-09 13:32:292095void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2096 const GURL& update_url) {
2097 new DisabledPluginInfoBar(this, name, update_url);
2098}
2099
[email protected]a2cf65eb2010-01-18 08:20:382100void TabContents::OnPageContents(const GURL& url,
2101 int renderer_process_id,
2102 int32 page_id,
[email protected]e5106202010-06-11 21:12:362103 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102104 const std::string& language,
2105 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382106 // Don't index any https pages. People generally don't want their bank
2107 // accounts, etc. indexed on their computer, especially since some of these
2108 // things are not marked cachable.
2109 // TODO(brettw) we may want to consider more elaborate heuristics such as
2110 // the cachability of the page. We may also want to consider subframes (this
2111 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272112 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2113 // content indexing for chromeos in some future releases.
2114#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382115 if (!url.SchemeIsSecure()) {
2116 Profile* p = profile();
2117 if (p && !p->IsOffTheRecord()) {
2118 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2119 if (hs)
2120 hs->SetPageContents(url, contents);
2121 }
2122 }
[email protected]ccd40a52010-05-11 16:15:272123#endif
[email protected]a8a81292010-01-21 00:32:452124
[email protected]1c57b7b2010-07-12 17:38:102125 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452126
2127 std::string lang = language;
2128 NotificationService::current()->Notify(
2129 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152130 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452131 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382132}
2133
[email protected]7e0831b2010-02-01 08:45:152134void TabContents::OnPageTranslated(int32 page_id,
2135 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162136 const std::string& translated_lang,
2137 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552138 language_state_.set_current_language(translated_lang);
2139 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162140 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152141 NotificationService::current()->Notify(
2142 NotificationType::PAGE_TRANSLATED,
2143 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162144 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152145}
2146
[email protected]ce833282010-11-04 15:48:392147void TabContents::OnSetSuggestions(
2148 int32 page_id,
2149 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262150 if (delegate())
[email protected]ce833282010-11-04 15:48:392151 delegate()->OnSetSuggestions(page_id, suggestions);
2152}
2153
2154void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2155 if (delegate())
2156 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262157}
2158
[email protected]bf5c2ff392009-07-08 16:24:332159void TabContents::DidStartProvisionalLoadForFrame(
2160 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182161 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332162 bool is_main_frame,
[email protected]ea51f1f2010-12-01 10:07:272163 bool is_error_page,
[email protected]bf5c2ff392009-07-08 16:24:332164 const GURL& url) {
2165 ProvisionalLoadDetails details(is_main_frame,
2166 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412167 url, std::string(), false,
2168 is_error_page, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332169 NotificationService::current()->Notify(
2170 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2171 Source<NavigationController>(&controller_),
2172 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142173 if (is_main_frame) {
[email protected]ea51f1f2010-12-01 10:07:272174 // If we're displaying a network error page do not reset the content
2175 // settings delegate's cookies so the user has a chance to modify cookie
2176 // settings.
2177 if (!is_error_page)
2178 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142179 content_settings_delegate_->ClearGeolocationContentSettings();
2180 }
[email protected]bf5c2ff392009-07-08 16:24:332181}
2182
2183void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202184 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332185 NotificationService::current()->Notify(
2186 NotificationType::RESOURCE_RESPONSE_STARTED,
2187 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202188 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332189}
2190
[email protected]3dbb80b2010-02-09 22:41:202191void TabContents::DidRedirectResource(
2192 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332193 NotificationService::current()->Notify(
2194 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2195 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202196 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332197}
2198
2199void TabContents::DidLoadResourceFromMemoryCache(
2200 const GURL& url,
2201 const std::string& frame_origin,
2202 const std::string& main_frame_origin,
2203 const std::string& security_info) {
2204 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442205 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332206 SSLManager::DeserializeSecurityInfo(security_info,
2207 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042208 &security_bits,
2209 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332210 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162211 GetRenderProcessHost()->id(), cert_id,
2212 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332213
2214 NotificationService::current()->Notify(
2215 NotificationType::LOAD_FROM_MEMORY_CACHE,
2216 Source<NavigationController>(&controller_),
2217 Details<LoadFromMemoryCacheDetails>(&details));
2218}
2219
[email protected]e3d60e5d2009-09-25 21:08:292220void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472221 displayed_insecure_content_ = true;
2222 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292223}
2224
2225void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592226 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292227}
2228
[email protected]bf5c2ff392009-07-08 16:24:332229void TabContents::DidFailProvisionalLoadWithError(
2230 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182231 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332232 bool is_main_frame,
2233 int error_code,
2234 const GURL& url,
2235 bool showing_repost_interstitial) {
2236 if (net::ERR_ABORTED == error_code) {
2237 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2238 // This means that the interstitial won't be torn down properly, which is
2239 // bad. But if we have an interstitial, go back to another tab type, and
2240 // then load the same interstitial again, we could end up getting the first
2241 // interstitial's "failed" message (as a result of the cancel) when we're on
2242 // the second one.
2243 //
2244 // We can't tell this apart, so we think we're tearing down the current page
2245 // which will cause a crash later one. There is also some code in
2246 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2247 // out because of this problem.
2248 //
2249 // http://code.google.com/p/chromium/issues/detail?id=2855
2250 // Because this will not tear down the interstitial properly, if "back" is
2251 // back to another tab type, the interstitial will still be somewhat alive
2252 // in the previous tab type. If you navigate somewhere that activates the
2253 // tab with the interstitial again, you'll see a flash before the new load
2254 // commits of the interstitial page.
2255 if (showing_interstitial_page()) {
2256 LOG(WARNING) << "Discarding message during interstitial.";
2257 return;
2258 }
2259
2260 // This will discard our pending entry if we cancelled the load (e.g., if we
2261 // decided to download the file instead of load it). Only discard the
2262 // pending entry if the URLs match, otherwise the user initiated a navigate
2263 // before the page loaded so that the discard would discard the wrong entry.
2264 NavigationEntry* pending_entry = controller_.pending_entry();
2265 if (pending_entry && pending_entry->url() == url) {
2266 controller_.DiscardNonCommittedEntries();
2267 // Update the URL display.
2268 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2269 }
2270
2271 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2272 }
2273
2274 // Send out a notification that we failed a provisional load with an error.
2275 ProvisionalLoadDetails details(is_main_frame,
2276 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412277 url, std::string(), false, false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332278 details.set_error_code(error_code);
2279
2280 NotificationService::current()->Notify(
2281 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2282 Source<NavigationController>(&controller_),
2283 Details<ProvisionalLoadDetails>(&details));
2284}
2285
[email protected]4b8e2b02010-11-30 09:15:182286void TabContents::DocumentLoadedInFrame(int64 frame_id) {
[email protected]bf5c2ff392009-07-08 16:24:332287 controller_.DocumentLoadedInFrame();
[email protected]622474d2010-11-04 09:21:082288 NotificationService::current()->Notify(
2289 NotificationType::FRAME_DOM_CONTENT_LOADED,
2290 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182291 Details<int64>(&frame_id));
[email protected]bf5c2ff392009-07-08 16:24:332292}
2293
[email protected]4b8e2b02010-11-30 09:15:182294void TabContents::DidFinishLoad(int64 frame_id) {
[email protected]fdd94a02010-11-05 08:07:172295 NotificationService::current()->Notify(
2296 NotificationType::FRAME_DID_FINISH_LOAD,
2297 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182298 Details<int64>(&frame_id));
[email protected]fdd94a02010-11-05 08:07:172299}
2300
[email protected]dcd5b332010-08-11 08:55:182301void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562302 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242303 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562304}
2305
[email protected]8d3347f2009-07-09 22:00:212306RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322307 return view_.get();
2308}
2309
[email protected]8d3347f2009-07-09 22:00:212310RenderViewHostDelegate::RendererManagement*
2311TabContents::GetRendererManagementDelegate() {
2312 return &render_manager_;
2313}
2314
[email protected]bf5c2ff392009-07-08 16:24:332315RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212316 TabContents::GetBrowserIntegrationDelegate() {
2317 return this;
[email protected]bf5c2ff392009-07-08 16:24:332318}
2319
[email protected]8d3347f2009-07-09 22:00:212320RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2321 return this;
[email protected]bf5c2ff392009-07-08 16:24:332322}
2323
[email protected]46ba9082010-06-22 10:00:582324RenderViewHostDelegate::ContentSettings*
2325TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552326 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582327}
2328
[email protected]8d3347f2009-07-09 22:00:212329RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322330 return save_package_.get(); // May be NULL, but we can return NULL.
2331}
2332
[email protected]8d3347f2009-07-09 22:00:212333RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092334 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212335}
2336
2337RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2338 return &fav_icon_helper_;
2339}
2340
[email protected]e8dbd674b2010-03-11 18:34:402341RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452342 if (autocomplete_history_manager_.get() == NULL)
2343 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2344 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332345}
2346
[email protected]21674df2009-10-28 19:51:212347RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342348 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212349}
2350
[email protected]1f18184a2010-07-21 19:34:492351RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2352 return GetSSLHelper();
2353}
2354
[email protected]b5977a0c2010-08-24 19:46:262355RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2356 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492357 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262358 return file_select_helper_.get();
2359}
2360
[email protected]fd571bb2010-03-19 01:23:542361AutomationResourceRoutingDelegate*
2362TabContents::GetAutomationResourceRoutingDelegate() {
2363 return delegate();
2364}
2365
[email protected]ced90ae12010-02-20 02:06:162366RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2367 return bookmark_drag_;
2368}
2369
2370void TabContents::SetBookmarkDragDelegate(
2371 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2372 bookmark_drag_ = bookmark_drag;
2373}
2374
[email protected]9fb83e82010-07-02 18:24:552375TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2376 return content_settings_delegate_.get();
2377}
2378
[email protected]93623c5d2009-12-10 21:40:322379RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462380 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512381}
2382
[email protected]57c6a652009-05-04 07:58:342383TabContents* TabContents::GetAsTabContents() {
2384 return this;
2385}
2386
[email protected]7b291f92009-08-14 05:43:532387ViewType::Type TabContents::GetRenderViewType() const {
2388 return ViewType::TAB_CONTENTS;
2389}
2390
2391int TabContents::GetBrowserWindowID() const {
2392 return controller().window_id().id();
2393}
2394
[email protected]420ae012009-04-24 05:16:322395void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062396 NotificationService::current()->Notify(
2397 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2398 Source<TabContents>(this),
2399 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322400 NavigationEntry* entry = controller_.GetActiveEntry();
2401 if (!entry)
2402 return;
2403
2404 // When we're creating views, we're still doing initial setup, so we always
2405 // use the pending DOM UI rather than any possibly existing committed one.
2406 if (render_manager_.pending_dom_ui()) {
2407 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2408 }
2409
2410 if (entry->IsViewSourceMode()) {
2411 // Put the renderer in view source mode.
2412 render_view_host->Send(
2413 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2414 }
[email protected]0666aef2009-05-13 19:48:082415
2416 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322417}
2418
2419void TabContents::RenderViewReady(RenderViewHost* rvh) {
2420 if (rvh != render_view_host()) {
2421 // Don't notify the world, since this came from a renderer in the
2422 // background.
2423 return;
2424 }
2425
2426 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302427 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232428 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302429
2430 // Restore the focus to the tab (otherwise the focus will be on the top
2431 // window).
[email protected]484ae5912010-09-29 19:16:142432 if (was_crashed && !FocusLocationBarByDefault() &&
2433 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302434 Focus();
[email protected]484ae5912010-09-29 19:16:142435 }
[email protected]420ae012009-04-24 05:16:322436}
2437
[email protected]443b80e2010-12-14 00:42:232438void TabContents::RenderViewGone(RenderViewHost* rvh,
2439 base::TerminationStatus status,
2440 int error_code) {
[email protected]420ae012009-04-24 05:16:322441 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092442 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322443 return;
2444 if (rvh != render_view_host()) {
2445 // The pending page's RenderViewHost is gone.
2446 return;
2447 }
2448
2449 SetIsLoading(false, NULL);
2450 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232451 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322452
[email protected]ff9efc62010-02-18 22:10:542453 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212454 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542455 RemoveInfoBar(GetInfoBarDelegateAt(i));
2456
[email protected]8e537302009-06-10 21:19:582457 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552458 // Only do this if we're not in browser shutdown, so that TabContents
2459 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2460 // visible do not flash a sad tab page.
2461 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2462 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322463
2464 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002465 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322466}
2467
[email protected]2e4633c2009-07-09 16:58:062468void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2469 NotificationService::current()->Notify(
2470 NotificationType::RENDER_VIEW_HOST_DELETED,
2471 Source<TabContents>(this),
2472 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482473 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062474}
2475
[email protected]420ae012009-04-24 05:16:322476void TabContents::DidNavigate(RenderViewHost* rvh,
2477 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372478 int extra_invalidate_flags = 0;
2479
2480 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]33f74972010-12-08 16:40:362481 PrerenderManager* pm = profile()->GetPrerenderManager();
2482 if (pm != NULL) {
2483 if (pm->MaybeUsePreloadedPage(this, params.url)) {
2484 // TODO(tburkard): If the preloaded page has not finished preloading
2485 // yet, we should not do this.
2486 DidStopLoading();
2487 return;
2488 }
2489 }
2490
[email protected]20ede072009-10-06 00:28:352491 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372492
[email protected]420ae012009-04-24 05:16:322493 render_manager_.DidNavigateMainFrame(rvh);
2494
[email protected]20ede072009-10-06 00:28:352495 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372496 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372497 }
2498
[email protected]420ae012009-04-24 05:16:322499 // Update the site of the SiteInstance if it doesn't have one yet.
2500 if (!GetSiteInstance()->has_site())
2501 GetSiteInstance()->SetSite(params.url);
2502
2503 // Need to update MIME type here because it's referred to in
2504 // UpdateNavigationCommands() called by RendererDidNavigate() to
2505 // determine whether or not to enable the encoding menu.
2506 // It's updated only for the main frame. For a subframe,
2507 // RenderView::UpdateURL does not set params.contents_mime_type.
2508 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2509 // TODO(jungshik): Add a test for the encoding menu to avoid
2510 // regressing it again.
2511 if (PageTransition::IsMainFrame(params.transition))
2512 contents_mime_type_ = params.contents_mime_type;
2513
2514 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372515 bool did_navigate = controller_.RendererDidNavigate(
2516 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392517
[email protected]a9c0bfe2010-09-17 08:35:222518 // Send notification about committed provisional loads. This notification is
2519 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2520 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2521 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072522 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2523 // that is not recorded in the navigation history. For the purpose of
2524 // tracking navigation events, we treat this event as a sub frame navigation
2525 // event.
2526 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2527 ProvisionalLoadDetails load_details(
2528 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412529 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222530 load_details.set_transition_type(params.transition);
2531 // Whether or not a page transition was triggered by going backward or
2532 // forward in the history is only stored in the navigation controller's
2533 // entry list.
2534 if (did_navigate &&
2535 (controller_.GetActiveEntry()->transition_type() &
2536 PageTransition::FORWARD_BACK)) {
2537 load_details.set_transition_type(
2538 params.transition | PageTransition::FORWARD_BACK);
2539 }
2540 NotificationService::current()->Notify(
2541 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2542 Source<NavigationController>(&controller_),
2543 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222544 }
2545
[email protected]3e90d4a2009-07-03 17:38:392546 // Update history. Note that this needs to happen after the entry is complete,
2547 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582548 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392549 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582550 // URLs, we use a data: URL as the real value. We actually want to save the
2551 // about: URL to the history db and keep the data: URL hidden. This is what
2552 // the TabContents' URL getter does.
2553 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2554 CreateHistoryAddPageArgs(GetURL(), details, params));
2555 if (!delegate() ||
2556 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2557 details.type)) {
2558 UpdateHistoryForNavigation(add_page_args);
2559 }
[email protected]3e90d4a2009-07-03 17:38:392560 }
2561
[email protected]76543b92009-08-31 17:27:452562 if (!did_navigate)
2563 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322564
2565 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2566 // for the appropriate notification (best) or you can add it to
2567 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2568 // necessary, please).
2569
2570 // Run post-commit tasks.
2571 if (details.is_main_frame)
2572 DidNavigateMainFramePostCommit(details, params);
2573 DidNavigateAnyFramePostCommit(rvh, details, params);
2574}
2575
2576void TabContents::UpdateState(RenderViewHost* rvh,
2577 int32 page_id,
2578 const std::string& state) {
2579 DCHECK(rvh == render_view_host());
2580
2581 // We must be prepared to handle state updates for any page, these occur
2582 // when the user is scrolling and entering form data, as well as when we're
2583 // leaving a page, in which case our state may have already been moved to
2584 // the next page. The navigation controller will look up the appropriate
2585 // NavigationEntry and update it when it is notified via the delegate.
2586
2587 int entry_index = controller_.GetEntryIndexWithPageID(
2588 GetSiteInstance(), page_id);
2589 if (entry_index < 0)
2590 return;
2591 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2592
2593 if (state == entry->content_state())
2594 return; // Nothing to update.
2595 entry->set_content_state(state);
2596 controller_.NotifyEntryChanged(entry, entry_index);
2597}
2598
2599void TabContents::UpdateTitle(RenderViewHost* rvh,
2600 int32 page_id, const std::wstring& title) {
2601 // If we have a title, that's a pretty good indication that we've started
2602 // getting useful data.
2603 SetNotWaitingForResponse();
2604
2605 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482606 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582607 page_id);
[email protected]420ae012009-04-24 05:16:322608 if (!entry || !UpdateTitleForEntry(entry, title))
2609 return;
2610
2611 // Broadcast notifications when the UI should be updated.
2612 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032613 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322614}
2615
[email protected]420ae012009-04-24 05:16:322616void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402617 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322618 set_encoding(encoding);
2619}
2620
2621void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2622 if (delegate())
2623 delegate()->UpdateTargetURL(this, url);
2624}
2625
2626void TabContents::UpdateThumbnail(const GURL& url,
2627 const SkBitmap& bitmap,
2628 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442629 if (profile()->IsOffTheRecord())
2630 return;
2631
[email protected]420ae012009-04-24 05:16:322632 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492633 if (history::TopSites::IsEnabled()) {
[email protected]e6baed562010-11-02 22:33:442634 history::TopSites* ts = profile()->GetTopSites();
2635 if (ts)
2636 ts->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282637 } else {
[email protected]e6baed562010-11-02 22:33:442638 HistoryService* hs =
2639 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2640 if (hs)
[email protected]449478302009-06-09 20:04:282641 hs->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322642 }
2643}
2644
[email protected]c4e98902010-06-01 10:20:142645void TabContents::UpdateInspectorSetting(const std::string& key,
2646 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052647 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082648}
2649
[email protected]45aafc92010-06-07 14:18:532650void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052651 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532652}
2653
[email protected]420ae012009-04-24 05:16:322654void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292655 // The UI may be in an event-tracking loop, such as between the
2656 // mouse-down and mouse-up in text selection or a button click.
2657 // Defer the close until after tracking is complete, so that we
2658 // don't free objects out from under the UI.
2659 // TODO(shess): This could probably be integrated with the
2660 // IsDoingDrag() test below. Punting for now because I need more
2661 // research to understand how this impacts platforms other than Mac.
2662 // TODO(shess): This could get more fine-grained. For instance,
2663 // closing a tab in another window while selecting text in the
2664 // current window's Omnibox should be just fine.
2665 if (view()->IsEventTracking()) {
2666 view()->CloseTabAfterEventTracking();
2667 return;
2668 }
2669
[email protected]24a4d1062009-07-10 23:10:422670 // If we close the tab while we're in the middle of a drag, we'll crash.
2671 // Instead, cancel the drag and close it as soon as the drag ends.
2672 if (view()->IsDoingDrag()) {
2673 view()->CancelDragAndCloseTab();
2674 return;
2675 }
2676
[email protected]420ae012009-04-24 05:16:322677 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2678 if (delegate() && rvh == render_view_host())
2679 delegate()->CloseContents(this);
2680}
2681
2682void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2683 if (delegate() && delegate()->IsPopup(this))
2684 delegate()->MoveContents(this, new_bounds);
2685}
2686
[email protected]7ab1e7d62009-10-14 23:32:012687void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322688 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492689
[email protected]de4761b2010-12-07 21:05:212690 if (delegate()) {
2691 bool is_print_preview_tab =
2692 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2693 if (content_restrictions_ || is_print_preview_tab) {
2694 content_restrictions_= is_print_preview_tab ?
2695 CONTENT_RESTRICTION_PRINT : 0;
2696 delegate()->ContentRestrictionsChanged(this);
2697 }
[email protected]9e823662010-10-13 23:36:002698 }
[email protected]3c9e1872010-11-18 16:17:492699
2700 // Notify observers about navigation.
2701 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2702 DidStartLoading());
[email protected]420ae012009-04-24 05:16:322703}
2704
[email protected]7ab1e7d62009-10-14 23:32:012705void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322706 scoped_ptr<LoadNotificationDetails> details;
2707
2708 NavigationEntry* entry = controller_.GetActiveEntry();
2709 // An entry may not exist for a stop when loading an initial blank page or
2710 // if an iframe injected by script into a blank page finishes loading.
2711 if (entry) {
[email protected]420ae012009-04-24 05:16:322712 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2713
2714 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542715 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322716 entry->transition_type(),
2717 elapsed,
2718 &controller_,
2719 controller_.GetCurrentEntryIndex()));
2720 }
2721
[email protected]420ae012009-04-24 05:16:322722 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492723
2724 // Notify observers about navigation.
2725 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2726 DidStopLoading());
[email protected]420ae012009-04-24 05:16:322727}
2728
[email protected]25497492010-09-11 15:15:082729void TabContents::DocumentOnLoadCompletedInMainFrame(
2730 RenderViewHost* render_view_host,
2731 int32 page_id) {
2732 NotificationService::current()->Notify(
2733 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2734 Source<TabContents>(this),
2735 Details<int>(&page_id));
2736}
2737
[email protected]420ae012009-04-24 05:16:322738void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2739 const GURL& source_url,
2740 const GURL& target_url) {
2741 NavigationEntry* entry;
2742 if (page_id == -1)
2743 entry = controller_.pending_entry();
2744 else
2745 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2746 if (!entry || entry->url() != source_url)
2747 return;
2748 entry->set_url(target_url);
2749}
2750
[email protected]420ae012009-04-24 05:16:322751void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2752 WindowOpenDisposition disposition) {
2753 if (render_manager_.dom_ui()) {
2754 // When we're a DOM UI, it will provide a page transition type for us (this
2755 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2756 // generated suggestions).
2757 //
2758 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162759 // want web sites to see a referrer of "chrome://blah" (and some
2760 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322761 // send to the site), so we send no referrer.
2762 OpenURL(url, GURL(), disposition,
2763 render_manager_.dom_ui()->link_transition_type());
2764 } else {
2765 OpenURL(url, referrer, disposition, PageTransition::LINK);
2766 }
2767}
2768
[email protected]1ee614862009-07-06 20:29:182769void TabContents::DomOperationResponse(const std::string& json_string,
2770 int automation_id) {
2771}
2772
[email protected]8b8e7c92010-08-19 18:05:562773void TabContents::ProcessDOMUIMessage(
2774 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322775 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442776 // This can happen if someone uses window.open() to open an extension URL
2777 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562778 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322779 return;
2780 }
[email protected]8b8e7c92010-08-19 18:05:562781 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322782}
2783
2784void TabContents::ProcessExternalHostMessage(const std::string& message,
2785 const std::string& origin,
2786 const std::string& target) {
2787 if (delegate())
2788 delegate()->ForwardMessageToExternalHost(message, origin, target);
2789}
2790
[email protected]420ae012009-04-24 05:16:322791void TabContents::RunJavaScriptMessage(
2792 const std::wstring& message,
2793 const std::wstring& default_prompt,
2794 const GURL& frame_url,
2795 const int flags,
2796 IPC::Message* reply_msg,
2797 bool* did_suppress_message) {
2798 // Suppress javascript messages when requested and when inside a constrained
2799 // popup window (because that activates them and breaks them out of the
2800 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552801 // Also suppress messages when showing an interstitial. The interstitial is
2802 // shown over the previous page, we don't want the hidden page dialogs to
2803 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502804 bool suppress_this_message =
2805 suppress_javascript_messages_ ||
2806 showing_interstitial_page() ||
2807 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322808 if (delegate())
2809 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312810 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322811
2812 *did_suppress_message = suppress_this_message;
2813
2814 if (!suppress_this_message) {
2815 base::TimeDelta time_since_last_message(
2816 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2817 bool show_suppress_checkbox = false;
2818 // Show a checkbox offering to suppress further messages if this message is
2819 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2820 if (time_since_last_message <
2821 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2822 show_suppress_checkbox = true;
2823
[email protected]d6ad7442010-09-05 19:06:522824 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2825 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322826 } else {
2827 // If we are suppressing messages, just reply as is if the user immediately
2828 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542829 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322830 }
2831}
2832
2833void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2834 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292835 if (delegate())
2836 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502837 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2838 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2839 std::wstring());
2840 return;
2841 }
[email protected]7ab1e7d62009-10-14 23:32:012842 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222843 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322844}
2845
2846void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2847 const std::string& json_arguments,
2848 IPC::Message* reply_msg) {
2849 if (delegate()) {
2850 HtmlDialogUIDelegate* dialog_delegate =
2851 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222852 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322853 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2854 }
2855}
2856
[email protected]c4aa86962010-11-24 23:08:042857void TabContents::PasswordFormsFound(
2858 const std::vector<webkit_glue::PasswordForm>& forms) {
2859 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2860 PasswordFormsFound(forms));
2861}
2862
2863void TabContents::PasswordFormsVisible(
2864 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2865 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2866 PasswordFormsVisible(visible_forms));
2867}
2868
[email protected]420ae012009-04-24 05:16:322869// Checks to see if we should generate a keyword based on the OSDD, and if
2870// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202871void TabContents::PageHasOSDD(
2872 RenderViewHost* render_view_host,
2873 int32 page_id,
2874 const GURL& url,
2875 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122876 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322877 DCHECK(url.is_valid());
2878 if (!IsActiveEntry(page_id))
2879 return;
[email protected]420ae012009-04-24 05:16:322880 if (!profile()->GetTemplateURLFetcher())
2881 return;
[email protected]420ae012009-04-24 05:16:322882 if (profile()->IsOffTheRecord())
2883 return;
2884
[email protected]2de7e002010-10-11 22:58:202885 TemplateURLFetcher::ProviderType provider_type;
2886 switch (msg_provider_type.type) {
2887 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2888 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2889 break;
2890
2891 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2892 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2893 break;
2894
2895 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2896 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2897 break;
2898
2899 default:
2900 NOTREACHED();
2901 return;
2902 }
2903
[email protected]420ae012009-04-24 05:16:322904 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2905 DCHECK(entry);
2906
2907 const NavigationEntry* base_entry = entry;
2908 if (IsFormSubmit(base_entry)) {
2909 // If the current page is a form submit, find the last page that was not
2910 // a form submit and use its url to generate the keyword from.
2911 int index = controller_.last_committed_entry_index() - 1;
2912 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2913 index--;
2914 if (index >= 0)
2915 base_entry = controller_.GetEntryAtIndex(index);
2916 else
2917 base_entry = NULL;
2918 }
2919
2920 // We want to use the user typed URL if available since that represents what
2921 // the user typed to get here, and fall back on the regular URL if not.
2922 if (!base_entry)
2923 return;
2924 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2925 base_entry->user_typed_url() : base_entry->url();
2926 if (!keyword_url.is_valid())
2927 return;
[email protected]2de7e002010-10-11 22:58:202928
[email protected]0b5b85c2010-10-11 23:00:122929 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2930 keyword_url,
2931 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532932
[email protected]0b5b85c2010-10-11 23:00:122933 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322934 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322935 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2936 keyword,
2937 url,
2938 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122939 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202940 provider_type);
[email protected]420ae012009-04-24 05:16:322941}
2942
[email protected]420ae012009-04-24 05:16:322943GURL TabContents::GetAlternateErrorPageURL() const {
2944 GURL url;
2945 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2946 if (profile()->IsOffTheRecord())
2947 return url;
2948
2949 PrefService* prefs = profile()->GetPrefs();
2950 DCHECK(prefs);
2951 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152952 url = google_util::AppendGoogleLocaleParam(
2953 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322954 url = google_util::AppendGoogleTLDParam(url);
2955 }
2956 return url;
2957}
2958
2959WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062960 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552961 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082962 WebPreferences web_prefs =
2963 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
2964
[email protected]9beff752010-09-22 19:35:432965 // Force accelerated compositing and 2d canvas off for chrome: and
2966 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432967 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2968 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082969 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432970 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082971 }
2972
[email protected]39553442010-09-09 00:01:552973#if defined(OS_MACOSX)
2974 // Disable accelerated compositing if IOSurface's are not supported,
2975 // as is the case in 10.5.
2976 if (!IOSurfaceSupport::Initialize())
2977 web_prefs.accelerated_compositing_enabled = false;
2978#endif
2979
[email protected]447021c2010-09-08 21:29:082980 return web_prefs;
[email protected]420ae012009-04-24 05:16:322981}
2982
[email protected]fa1cf0b82010-01-15 21:49:442983void TabContents::OnIgnoredUIEvent() {
2984 if (constrained_window_count()) {
2985 ConstrainedWindow* window = *constrained_window_begin();
2986 window->FocusConstrainedWindow();
2987 }
2988}
2989
[email protected]420ae012009-04-24 05:16:322990void TabContents::OnJSOutOfMemory() {
2991 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582992 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2993 NULL, true));
[email protected]420ae012009-04-24 05:16:322994}
2995
[email protected]420ae012009-04-24 05:16:322996void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2997 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342998 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322999 // delivered to a pending RenderViewHost. We must first run the onunload
3000 // handler of the old RenderViewHost before we can allow it to proceed.
3001 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
3002 new_request_id);
3003}
3004
[email protected]420ae012009-04-24 05:16:323005void TabContents::RendererUnresponsive(RenderViewHost* rvh,
3006 bool is_during_unload) {
3007 if (is_during_unload) {
3008 // Hang occurred while firing the beforeunload/unload handler.
3009 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:113010 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323011
3012 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3013 return;
3014
3015 // If the tab hangs in the beforeunload/unload handler there's really
3016 // nothing we can do to recover. Pretend the unload listeners have
3017 // all fired and close the tab. If the hang is in the beforeunload handler
3018 // then the user will not have the option of cancelling the close.
3019 Close(rvh);
3020 return;
3021 }
3022
3023 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:003024 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:323025}
3026
3027void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:003028 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:323029}
3030
3031void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:563032 net::LoadState load_state,
3033 uint64 upload_position,
3034 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323035 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563036 upload_position_ = upload_position;
3037 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:293038 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:193039 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:293040 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:533041 load_state_host_ =
3042 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:323043 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
3044 SetNotWaitingForResponse();
3045 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:503046 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:323047}
3048
[email protected]1ee614862009-07-06 20:29:183049bool TabContents::IsExternalTabContainer() const {
3050 if (!delegate())
3051 return false;
3052
3053 return delegate()->IsExternalTabContainer();
3054}
3055
[email protected]1ee614862009-07-06 20:29:183056void TabContents::DidInsertCSS() {
3057 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:323058}
3059
[email protected]546ae4e02010-12-08 14:57:193060void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:353061 NotificationService::current()->Notify(
3062 NotificationType::FOCUS_CHANGED_IN_PAGE,
3063 Source<RenderViewHost>(render_view_host()),
[email protected]546ae4e02010-12-08 14:57:193064 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:353065}
3066
[email protected]b75b8292010-10-01 07:28:253067void TabContents::UpdateZoomLimits(int minimum_percent,
3068 int maximum_percent,
3069 bool remember) {
3070 minimum_zoom_percent_ = minimum_percent;
3071 maximum_zoom_percent_ = maximum_percent;
3072 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383073}
3074
[email protected]9e823662010-10-13 23:36:003075void TabContents::UpdateContentRestrictions(int restrictions) {
3076 content_restrictions_ = restrictions;
3077 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:323078}
3079
[email protected]420ae012009-04-24 05:16:323080void TabContents::BeforeUnloadFiredFromRenderManager(
3081 bool proceed,
3082 bool* proceed_to_fire_unload) {
3083 if (delegate())
3084 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3085}
3086
[email protected]3a3d47472010-07-15 21:03:543087void TabContents::DidStartLoadingFromRenderManager(
3088 RenderViewHost* render_view_host) {
3089 DidStartLoading();
3090}
3091
3092void TabContents::RenderViewGoneFromRenderManager(
3093 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233094 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3095 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543096}
3097
[email protected]420ae012009-04-24 05:16:323098void TabContents::UpdateRenderViewSizeForRenderManager() {
3099 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263100 gfx::Size size = view_->GetContainerSize();
3101 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3102 // here during container initialization and normal window size will be set
3103 // later. In case of tab duplication this resizing to 0x0 prevents setting
3104 // normal size later so just ignore it.
3105 if (!size.IsEmpty())
3106 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323107}
3108
[email protected]3a3d47472010-07-15 21:03:543109void TabContents::NotifySwappedFromRenderManager() {
3110 NotifySwapped();
3111}
3112
3113NavigationController& TabContents::GetControllerForRenderManager() {
3114 return controller();
3115}
3116
[email protected]420ae012009-04-24 05:16:323117DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223118 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323119}
3120
3121NavigationEntry*
3122TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3123 return controller_.GetLastCommittedEntry();
3124}
3125
3126bool TabContents::CreateRenderViewForRenderManager(
3127 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323128 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523129
[email protected]674b3822010-08-04 04:02:513130 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323131 return false;
3132
3133 // Now that the RenderView has been created, we need to tell it its size.
3134 rwh_view->SetSize(view_->GetContainerSize());
3135
3136 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3137 render_view_host);
3138 return true;
3139}
3140
3141void TabContents::Observe(NotificationType type,
3142 const NotificationSource& source,
3143 const NotificationDetails& details) {
3144 switch (type.value) {
3145 case NotificationType::BOOKMARK_MODEL_LOADED:
3146 // BookmarkModel finished loading, fall through to update starred state.
3147 case NotificationType::URLS_STARRED: {
3148 // Somewhere, a URL has been starred.
3149 // Ignore notifications for profiles other than our current one.
3150 Profile* source_profile = Source<Profile>(source).ptr();
3151 if (!source_profile || !source_profile->IsSameProfile(profile()))
3152 return;
3153
3154 UpdateStarredStateForCurrentURL();
3155 break;
3156 }
3157 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513158 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323159 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3160 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3161 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533162 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3163 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323164 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173165 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3166 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323167 } else {
3168 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3169 }
3170 break;
3171 }
3172 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3173 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3174 break;
3175
3176 case NotificationType::NAV_ENTRY_COMMITTED: {
3177 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3178
3179 NavigationController::LoadCommittedDetails& committed_details =
3180 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3181 ExpireInfoBars(committed_details);
3182 break;
3183 }
3184
[email protected]d3ba77272009-09-03 00:06:093185#if defined(OS_LINUX)
3186 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543187 renderer_preferences_util::UpdateFromSystemSettings(
3188 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093189 render_view_host()->SyncRendererPrefs();
3190 break;
3191 }
3192#endif
3193
[email protected]6c32ce72010-03-08 05:18:063194 case NotificationType::USER_STYLE_SHEET_UPDATED:
3195 UpdateWebPreferences();
3196 break;
3197
[email protected]79580c62010-02-02 02:36:253198 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:453199 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:253200 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493201 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293202 if (entry)
[email protected]da0c8e92010-02-09 23:25:493203 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293204 if (settings_details.ptr()->update_all() ||
3205 settings_details.ptr()->pattern().Matches(entry_url)) {
3206 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233207 profile()->GetHostContentSettingsMap()->
3208 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253209 }
3210 break;
3211 }
3212
[email protected]e5adff72010-06-14 18:13:063213 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573214 break;
[email protected]a888b29e62010-04-01 13:38:573215
3216 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063217 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573218 break;
[email protected]a888b29e62010-04-01 13:38:573219
[email protected]88152052010-10-01 04:05:183220 case NotificationType::GOOGLE_URL_UPDATED:
3221 UpdateAlternateErrorPageURL();
3222 break;
3223
[email protected]420ae012009-04-24 05:16:323224 default:
3225 NOTREACHED();
3226 }
3227}
[email protected]aacd7cc2009-09-02 14:51:103228
[email protected]9adb9692010-10-29 23:14:023229void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083230 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433231
[email protected]a888b29e62010-04-01 13:38:573232 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083233 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3234 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573235 extension,
[email protected]807871f2010-09-16 01:04:483236 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3237 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573238 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3239 Extension::EXTENSION_ICON_SMALLISH),
3240 ImageLoadingTracker::CACHE);
3241 } else {
[email protected]98aa0b52010-05-06 17:03:083242 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573243 }
3244}
3245
[email protected]9adb9692010-10-29 23:14:023246const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:573247 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3248 if (!extensions_service)
3249 return NULL;
3250
[email protected]9adb9692010-10-29 23:14:023251 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573252 return extension ?
3253 extension : extensions_service->GetExtensionByWebExtent(url);
3254}
3255
[email protected]a888b29e62010-04-01 13:38:573256void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3257 int index) {
3258 if (image) {
[email protected]98aa0b52010-05-06 17:03:083259 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573260 NotifyNavigationStateChanged(INVALIDATE_TAB);
3261 }
3262}
3263
[email protected]beb440c2009-11-06 04:08:543264gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3265 return view_->GetTopLevelNativeWindow();
3266}
3267
3268void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3269 bool success,
3270 const std::wstring& prompt) {
3271 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3272 if (is_showing_before_unload_dialog_ && !success) {
3273 // If a beforeunload dialog is canceled, we need to stop the throbber from
3274 // spinning, since we forced it to start spinning in Navigate.
3275 DidStopLoading();
3276
3277 tab_close_start_time_ = base::TimeTicks();
3278 }
3279 is_showing_before_unload_dialog_ = false;
3280 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3281}
3282
3283void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3284 set_suppress_javascript_messages(suppress_message_boxes);
3285}
3286
[email protected]3a3d47472010-07-15 21:03:543287TabContents* TabContents::AsTabContents() {
3288 return this;
3289}
3290
3291ExtensionHost* TabContents::AsExtensionHost() {
3292 return NULL;
3293}
3294
[email protected]41fc0322009-09-04 22:23:403295void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103296 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3297}
[email protected]f45d2a72010-03-08 23:28:353298
3299void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3300 app_icon_ = app_icon;
3301 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3302}
[email protected]33f74972010-12-08 16:40:363303
3304void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
3305 render_manager_.SwapInRenderViewHost(rvh);
3306}
3307
3308void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
3309 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
3310 rwh_view->SetSize(view()->GetContainerSize());
3311}