blob: 30b91e962f978d70306a6240e48d41a59d47d2b5 [file] [log] [blame]
[email protected]61d68ef12011-01-13 14:02:561// Copyright (c) 2011 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]0dd3a0ab2011-02-18 08:17:445#include "content/browser/tab_contents/tab_contents.h"
[email protected]39526562011-02-05 03:41:516
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]8cc8d492010-02-02 10:40:499#include "base/auto_reset.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3713#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5414#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3115#include "base/utf_string_conversions.h"
[email protected]6db0def92010-03-02 19:55:4516#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2117#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4018#include "chrome/browser/blocked_content_container.h"
[email protected]96d185d2009-04-24 03:28:5419#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5520#include "chrome/browser/browser_shutdown.h"
[email protected]aacd7cc2009-09-02 14:51:1021#include "chrome/browser/character_encoding.h"
[email protected]724159a2010-12-30 01:11:1822#include "chrome/browser/child_process_security_policy.h"
[email protected]5f24f212010-12-02 14:47:4523#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3324#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5425#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1426#include "chrome/browser/defaults.h"
[email protected]74da5bd2011-01-27 22:03:2727#include "chrome/browser/desktop_notification_handler.h"
[email protected]420ae012009-04-24 05:16:3228#include "chrome/browser/dom_operation_notification_details.h"
[email protected]bcef0dc02009-02-28 00:35:0229#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3230#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0131#include "chrome/browser/download/download_request_limiter.h"
[email protected]eaa7dd182010-12-14 11:09:0032#include "chrome/browser/extensions/extension_service.h"
[email protected]3c733bde2010-12-21 19:56:3133#include "chrome/browser/external_protocol_handler.h"
34#include "chrome/browser/favicon_service.h"
35#include "chrome/browser/file_select_helper.h"
36#include "chrome/browser/google/google_util.h"
[email protected]ef0d04c2010-12-15 23:34:2137#include "chrome/browser/history/history.h"
[email protected]ec0b6c42010-08-26 03:16:5838#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4239#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2540#include "chrome/browser/host_zoom_map.h"
[email protected]8897c382009-05-06 17:53:2641#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0742#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3243#include "chrome/browser/load_from_memory_cache_details.h"
44#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4445#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]724159a2010-12-30 01:11:1846#include "chrome/browser/metrics/user_metrics.h"
[email protected]ea0e80892009-08-22 00:36:0547#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1048#include "chrome/browser/omnibox_search_hint.h"
[email protected]c8f73ab2011-01-22 00:05:1749#include "chrome/browser/pdf_unsupported_feature.h"
[email protected]14a000d2010-04-29 21:44:2450#include "chrome/browser/platform_util.h"
[email protected]67c052e2011-01-31 16:33:5851#include "chrome/browser/plugin_observer.h"
[email protected]33f74972010-12-08 16:40:3652#include "chrome/browser/prerender/prerender_manager.h"
[email protected]973407b2011-01-26 23:18:2353#include "chrome/browser/prerender/prerender_plt_recorder.h"
[email protected]eb15e24e2011-02-03 22:34:3454#include "chrome/browser/printing/print_preview_message_handler.h"
[email protected]dbeebd52010-11-16 20:34:1655#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0956#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3357#include "chrome/browser/profiles/profile.h"
[email protected]1db6ff152009-10-12 15:32:0758#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1659#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5460#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3761#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0762#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5463#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3264#include "chrome/browser/renderer_preferences_util.h"
[email protected]fa685ff2011-02-17 19:47:1365#include "chrome/browser/safe_browsing/client_side_detection_host.h"
[email protected]c37e3b62010-01-22 00:15:1766#include "chrome/browser/sessions/session_types.h"
[email protected]1f18184a2010-07-21 19:34:4967#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]d54169e92011-01-21 09:19:5268#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1669#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3570#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]7e3abea42011-02-18 00:51:1071#include "chrome/browser/webui/web_ui.h"
[email protected]54ec6472010-04-09 19:39:5872#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2773#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2174#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4975#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5776#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4877#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1478#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0979#include "chrome/common/extensions/url_pattern.h"
80#include "chrome/common/navigation_types.h"
81#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5682#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2983#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3284#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0285#include "chrome/common/render_messages_params.h"
[email protected]96d185d2009-04-24 03:28:5486#include "chrome/common/url_constants.h"
[email protected]0dd3a0ab2011-02-18 08:17:4487#include "content/browser/tab_contents/infobar_delegate.h"
88#include "content/browser/tab_contents/interstitial_page.h"
89#include "content/browser/tab_contents/navigation_entry.h"
90#include "content/browser/tab_contents/provisional_load_details.h"
91#include "content/browser/tab_contents/tab_contents_delegate.h"
92#include "content/browser/tab_contents/tab_contents_observer.h"
93#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]d686e812009-06-03 19:10:2994#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3295#include "net/base/registry_controlled_domain.h"
[email protected]8bd0fe62011-01-17 06:44:3796#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]42ce29d2011-01-20 23:19:4697#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:3898#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0399#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:31100#include "webkit/glue/webpreferences.h"
101
102#if defined(OS_MACOSX)
103#include "app/surface/io_surface_support_mac.h"
104#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:00105
[email protected]61d68ef12011-01-13 14:02:56106#if defined(OS_CHROMEOS)
107#include "chrome/browser/chromeos/locale_change_guard.h"
108#endif // defined(OS_CHROMEOS)
109
[email protected]420ae012009-04-24 05:16:32110// Cross-Site Navigations
111//
112// If a TabContents is told to navigate to a different web site (as determined
113// by SiteInstance), it will replace its current RenderViewHost with a new
114// RenderViewHost dedicated to the new SiteInstance. This works as follows:
115//
116// - Navigate determines whether the destination is cross-site, and if so,
117// it creates a pending_render_view_host_ and moves into the PENDING
118// RendererState.
119// - The pending RVH is "suspended," so that no navigation messages are sent to
120// its renderer until the onbeforeunload JavaScript handler has a chance to
121// run in the current RVH.
122// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
123// that it has a pending cross-site request. ResourceDispatcherHost will
124// check for this when the response arrives.
125// - The current RVH runs its onbeforeunload handler. If it returns false, we
126// cancel all the pending logic and go back to NORMAL. Otherwise we allow
127// the pending RVH to send the navigation request to its renderer.
128// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
129// checks CrossSiteRequestManager to see that the RVH responsible has a
130// pending cross-site request, and then installs a CrossSiteEventHandler.
131// - When RDH receives a response, the BufferedEventHandler determines whether
132// it is a download. If so, it sends a message to the new renderer causing
133// it to cancel the request, and the download proceeds in the download
134// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34135// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32136// doesn't affect any functionality.
137// - After RDH receives a response and determines that it is safe and not a
138// download, it pauses the response to first run the old page's onunload
139// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34140// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32141// to the current RVH.
142// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
143// the ResourceDispatcherHost, who unpauses the response. Data is then sent
144// to the pending RVH.
145// - The pending renderer sends a FrameNavigate message that invokes the
146// DidNavigate method. This replaces the current RVH with the
147// pending RVH and goes back to the NORMAL RendererState.
148
149namespace {
150
151// Amount of time we wait between when a key event is received and the renderer
152// is queried for its state and pushed to the NavigationEntry.
153const int kQueryStateDelay = 5000;
154
[email protected]6ebdc9b2010-09-27 16:55:57155const int kSyncWaitDelay = 40;
156
[email protected]420ae012009-04-24 05:16:32157// If another javascript message box is displayed within
158// kJavascriptMessageExpectedDelay of a previous javascript message box being
159// dismissed, display an option to suppress future message boxes from this
160// contents.
161const int kJavascriptMessageExpectedDelay = 1000;
162
[email protected]420ae012009-04-24 05:16:32163// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51164const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32165 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17166 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32167 prefs::kWebKitJavaEnabled,
168 prefs::kWebKitJavascriptEnabled,
169 prefs::kWebKitLoadsImagesAutomatically,
170 prefs::kWebKitPluginsEnabled,
171 prefs::kWebKitUsesUniversalDetector,
172 prefs::kWebKitSerifFontFamily,
173 prefs::kWebKitSansSerifFontFamily,
174 prefs::kWebKitFixedFontFamily,
175 prefs::kWebKitDefaultFontSize,
176 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13177 prefs::kWebKitMinimumFontSize,
178 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36179 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32180 prefs::kDefaultCharset
181 // kWebKitStandardFontIsSerif needs to be added
182 // if we let users pick which font to use, serif or sans-serif when
183 // no font is specified or a CSS generic family (serif or sans-serif)
184 // is not specified.
185};
186
187const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
188
[email protected]420ae012009-04-24 05:16:32189#if defined(OS_WIN)
190
191BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
192 // Note: erase is required to properly paint some widgets borders. This can
193 // be seen with textfields.
194 InvalidateRect(hwnd, NULL, TRUE);
195 return TRUE;
196}
197#endif
198
[email protected]5e369672009-11-03 23:48:30199ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16200 Profile* profile, const NavigationEntry& entry,
201 NavigationController::ReloadType reload_type) {
202 switch (reload_type) {
203 case NavigationController::RELOAD:
204 return ViewMsg_Navigate_Params::RELOAD;
205 case NavigationController::RELOAD_IGNORING_CACHE:
206 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
207 case NavigationController::NO_RELOAD:
208 break; // Fall through to rest of function.
209 }
[email protected]5e369672009-11-03 23:48:30210
211 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
212 profile->DidLastSessionExitCleanly())
213 return ViewMsg_Navigate_Params::RESTORE;
214
215 return ViewMsg_Navigate_Params::NORMAL;
216}
217
[email protected]876bc832010-09-07 16:29:54218void MakeNavigateParams(const NavigationEntry& entry,
219 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16220 NavigationController::ReloadType reload_type,
221 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34222 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54223 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00224 params->current_history_list_offset = controller.last_committed_entry_index();
225 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34226 params->url = entry.url();
227 params->referrer = entry.referrer();
228 params->transition = entry.transition_type();
229 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00230 params->navigation_type =
231 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34232 params->request_time = base::Time::Now();
233}
234
[email protected]420ae012009-04-24 05:16:32235} // namespace
236
[email protected]f4f50ef2011-01-21 19:01:19237
238// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32239
[email protected]420ae012009-04-24 05:16:32240TabContents::TabContents(Profile* profile,
241 SiteInstance* site_instance,
242 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07243 const TabContents* base_tab_contents,
244 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42245 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07246 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
247 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13248 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22249 TabContentsView::Create(this))),
250 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06251 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34252 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23253 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
254 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34255 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34256 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57257 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56258 upload_size_(0),
259 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57260 received_page_title_(false),
[email protected]c65e2f152010-10-14 15:30:40261 blocked_contents_(NULL),
262 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49263 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47264 displayed_insecure_content_(false),
[email protected]98aa0b52010-05-06 17:03:08265 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57266 capturing_contents_(false),
267 is_being_destroyed_(false),
268 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57269#if defined(OS_WIN)
270 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
271#endif
[email protected]c2e74fe82009-09-03 17:57:44272 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01273 is_showing_before_unload_dialog_(false),
[email protected]80a8fad2011-01-29 04:02:38274 opener_web_ui_type_(WebUIFactory::kNoWebUI),
[email protected]777a7b62010-05-11 13:28:16275 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38276 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25277 minimum_zoom_percent_(
278 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
279 maximum_zoom_percent_(
280 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00281 temporary_zoom_settings_(false),
282 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54283 renderer_preferences_util::UpdateFromSystemSettings(
284 &renderer_preferences_, profile);
285
[email protected]9fb83e82010-07-02 18:24:55286 content_settings_delegate_.reset(
287 new TabSpecificContentSettings(this, profile));
288
[email protected]12636df2009-09-28 22:32:21289 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32290
[email protected]34ac70502009-09-25 17:07:23291 // We have the initial size of the view be based on the size of the passed in
292 // tab contents (normally a tab from the same window).
293 view_->CreateView(base_tab_contents ?
294 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32295
296 // Register for notifications about all interested prefs change.
297 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28298 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32299 if (prefs) {
300 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28301 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32302 }
303
[email protected]420ae012009-04-24 05:16:32304 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
305 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09306#if defined(OS_LINUX)
307 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
308 NotificationService::AllSources());
309#endif
[email protected]420ae012009-04-24 05:16:32310
[email protected]6c32ce72010-03-08 05:18:06311 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
312 NotificationService::AllSources());
313
[email protected]79580c62010-02-02 02:36:25314 // Register for notifications about content setting changes.
315 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
316 NotificationService::AllSources());
317
[email protected]a888b29e62010-04-01 13:38:57318 // Listen for extension changes so we can update extension_for_current_page_.
319 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
320 NotificationService::AllSources());
321 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
322 NotificationService::AllSources());
[email protected]a888b29e62010-04-01 13:38:57323
[email protected]88152052010-10-01 04:05:18324 // Listen for Google URL changes
325 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
326 NotificationService::AllSources());
327
[email protected]c8865482009-07-23 20:40:10328 // Set-up the showing of the omnibox search infobar if applicable.
329 if (OmniboxSearchHint::IsEnabled(profile))
330 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53331
[email protected]b5a1d11c2011-02-17 03:09:42332 // Can only add observers after render_manager_.Init() is called, since that's
333 // what sets up the render_view_host which TabContentObserver's constructor
334 // uses to get the routing_id.
335 AddObservers();
[email protected]332af7732009-03-11 13:21:35336}
initial.commit09911bf2008-07-26 23:55:29337
338TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32339 is_being_destroyed_ = true;
340
[email protected]bfe4c1582009-10-02 18:11:09341 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32342 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28343 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32344
[email protected]420ae012009-04-24 05:16:32345 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00346 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32347
[email protected]420ae012009-04-24 05:16:32348 // First cleanly close all child windows.
349 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
350 // some of these to close. CloseWindows is async, so it might get called
351 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49352 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32353
[email protected]c65e2f152010-10-14 15:30:40354 // Close all blocked contents.
355 if (blocked_contents_)
356 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13357
[email protected]420ae012009-04-24 05:16:32358 // Notify any observer that have a reference on this tab contents.
359 NotificationService::current()->Notify(
360 NotificationType::TAB_CONTENTS_DESTROYED,
361 Source<TabContents>(this),
362 NotificationService::NoDetails());
363
[email protected]1e5e74f2009-05-27 20:55:12364 // Notify any lasting InfobarDelegates that have not yet been removed that
365 // whatever infobar they were handling in this TabContents has closed,
366 // because the TabContents is going away entirely.
367 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
368 // notification may trigger infobars calls that access their delegate. (and
369 // some implementations of InfoBarDelegate do delete themselves on
370 // InfoBarClosed()).
[email protected]ec8f51162011-02-08 04:20:40371 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]1e5e74f2009-05-27 20:55:12372 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
373 delegate->InfoBarClosed();
374 }
375 infobar_delegates_.clear();
376
[email protected]420ae012009-04-24 05:16:32377 // TODO(brettw) this should be moved to the view.
378#if defined(OS_WIN)
379 // If we still have a window handle, destroy it. GetNativeView can return
380 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42381 if (GetNativeView()) {
382 RenderViewHost* host = render_view_host();
383 if (host && host->view()) {
384 host->view()->WillWmDestroy();
385 }
[email protected]420ae012009-04-24 05:16:32386 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42387 }
[email protected]420ae012009-04-24 05:16:32388#endif
[email protected]7ab1e7d62009-10-14 23:32:01389
390 // OnCloseStarted isn't called in unit tests.
391 if (!tab_close_start_time_.is_null()) {
392 UMA_HISTOGRAM_TIMES("Tab.Close",
393 base::TimeTicks::Now() - tab_close_start_time_);
394 }
[email protected]b5a1d11c2011-02-17 03:09:42395
396 FOR_EACH_OBSERVER(TabContentsObserver, observers_, set_tab_contents(NULL));
397}
398
399void TabContents::AddObservers() {
400 printing_.reset(new printing::PrintViewManager(this));
401 print_preview_.reset(new printing::PrintPreviewMessageHandler(this));
402 fav_icon_helper_.reset(new FavIconHelper(this));
403 autofill_manager_.reset(new AutoFillManager(this));
404 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
405 prerender_plt_recorder_.reset(new prerender::PrerenderPLTRecorder(this));
406 desktop_notification_handler_.reset(
407 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
408 plugin_observer_.reset(new PluginObserver(this));
[email protected]fa685ff2011-02-17 19:47:13409 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost(
410 this));
initial.commit09911bf2008-07-26 23:55:29411}
412
[email protected]724159a2010-12-30 01:11:18413bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]585b30362011-01-28 02:30:17414 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
415 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10416 while ((observer = it.GetNext()) != NULL)
417 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53418 return true;
[email protected]403415a2011-01-10 18:57:53419
[email protected]724159a2010-12-30 01:11:18420 bool handled = true;
421 bool message_is_ok = true;
422 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
423 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
424 OnDidStartProvisionalLoadForFrame)
425 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
426 OnDidRedirectProvisionalLoad)
427 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
428 OnDidFailProvisionalLoadWithError)
429 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
430 OnDidLoadResourceFromMemoryCache)
431 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
432 OnDidDisplayInsecureContent)
433 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
434 OnDidRunInsecureContent)
435 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
436 OnDocumentLoadedInFrame)
437 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17438 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
439 OnUpdateContentRestrictions)
440 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
441 OnPDFHasUnsupportedFeature)
[email protected]7d472472011-01-22 01:30:25442 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]7d472472011-01-22 01:30:25443 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo,
444 OnDidGetApplicationInfo)
445 IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication,
446 OnInstallApplication)
447 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
448 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated)
449 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions)
450 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined,
451 OnInstantSupportDetermined)
[email protected]34f128d2011-01-25 19:07:44452 IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser)
[email protected]724159a2010-12-30 01:11:18453 IPC_MESSAGE_UNHANDLED(handled = false)
454 IPC_END_MESSAGE_MAP_EX()
455
456 if (!message_is_ok) {
457 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
458 GetRenderProcessHost()->ReceivedBadMessage();
459 }
460
461 return handled;
462}
463
[email protected]13367f72009-07-08 16:39:02464// Returns true if contains content rendered by an extension.
465bool TabContents::HostsExtension() const {
466 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34467}
468
[email protected]1f18184a2010-07-21 19:34:49469TabContentsSSLHelper* TabContents::GetSSLHelper() {
470 if (ssl_helper_.get() == NULL)
471 ssl_helper_.reset(new TabContentsSSLHelper(this));
472 return ssl_helper_.get();
473}
474
[email protected]8cb5d5b2010-02-09 11:36:16475RenderProcessHost* TabContents::GetRenderProcessHost() const {
476 return render_manager_.current_host()->process();
477}
478
[email protected]9adb9692010-10-29 23:14:02479void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46480 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08481 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10482
[email protected]98aa0b52010-05-06 17:03:08483 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57484
[email protected]fca656c2010-02-10 20:30:10485 NotificationService::current()->Notify(
486 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
487 Source<TabContents>(this),
488 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49489}
490
[email protected]98aa0b52010-05-06 17:03:08491void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
492 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40493 return;
494
[email protected]eaa7dd182010-12-14 11:09:00495 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50496 if (!extension_service || !extension_service->is_ready())
497 return;
498
499 const Extension* extension =
500 extension_service->GetExtensionById(extension_app_id, false);
501 if (extension)
502 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40503}
504
[email protected]98aa0b52010-05-06 17:03:08505SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08506 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51507 return NULL;
508
[email protected]98aa0b52010-05-06 17:03:08509 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51510}
511
[email protected]d5f942ba2008-09-26 19:30:34512const GURL& TabContents::GetURL() const {
513 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57514 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54515 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34516}
517
[email protected]96d185d2009-04-24 03:28:54518const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55519 // Transient entries take precedence. They are used for interstitial pages
520 // that are shown on top of existing pages.
521 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23522 if (entry) {
523 return entry->GetTitleForDisplay(profile()->GetPrefs()->
524 GetString(prefs::kAcceptLanguages));
525 }
[email protected]7ade2732011-02-10 00:13:58526 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
527 render_manager_.pending_web_ui() : render_manager_.web_ui();
528 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54529 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55530 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54531 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35532 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58533 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54534 if (!title.empty())
535 return title;
536 }
537 }
538
539 // We use the title for the last committed entry rather than a pending
540 // navigation entry. For example, when the user types in a URL, we want to
541 // keep the old page's title until the new load has committed and we get a new
542 // title.
[email protected]96d185d2009-04-24 03:28:54543 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23544 if (entry) {
545 return entry->GetTitleForDisplay(profile()->GetPrefs()->
546 GetString(prefs::kAcceptLanguages));
547 }
[email protected]96d185d2009-04-24 03:28:54548 return EmptyString16();
549}
550
[email protected]d5f942ba2008-09-26 19:30:34551int32 TabContents::GetMaxPageID() {
552 if (GetSiteInstance())
553 return GetSiteInstance()->max_page_id();
554 else
555 return max_page_id_;
556}
557
558void TabContents::UpdateMaxPageID(int32 page_id) {
559 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34560 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34561 // testing.
562 if (GetSiteInstance())
563 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16564 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34565}
566
[email protected]96d185d2009-04-24 03:28:54567SiteInstance* TabContents::GetSiteInstance() const {
568 return render_manager_.current_host()->site_instance();
569}
570
[email protected]96d185d2009-04-24 03:28:54571bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15572 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54573 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15574 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01575 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54576 return true;
[email protected]8ab24cc2009-11-13 20:56:15577 }
[email protected]83e3895b2009-06-11 00:07:16578
[email protected]2b9a06402011-02-16 04:57:10579 // We always display the URL for non-WebUI URLs to prevent spoofing.
580 if (entry && !WebUIFactory::HasWebUIScheme(entry->url()))
581 return true;
582
[email protected]d0980792011-02-13 19:41:40583 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58584 if (web_ui)
585 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54586 return true;
587}
588
[email protected]d5f942ba2008-09-26 19:30:34589SkBitmap TabContents::GetFavIcon() const {
590 // Like GetTitle(), we also want to use the favicon for the last committed
591 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57592 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47593 if (entry)
594 return entry->favicon().bitmap();
595
[email protected]ce3fa3c2009-04-20 19:55:57596 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34597 if (entry)
598 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34599 return SkBitmap();
600}
601
[email protected]0b303cc2009-09-28 22:35:15602bool TabContents::FavIconIsValid() const {
603 NavigationEntry* entry = controller_.GetTransientEntry();
604 if (entry)
605 return entry->favicon().is_valid();
606
607 entry = controller_.GetLastCommittedEntry();
608 if (entry)
609 return entry->favicon().is_valid();
610
611 return false;
612}
613
[email protected]96d185d2009-04-24 03:28:54614bool TabContents::ShouldDisplayFavIcon() {
615 // Always display a throbber during pending loads.
616 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
617 return true;
618
[email protected]d0980792011-02-13 19:41:40619 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58620 if (web_ui)
621 return !web_ui->hide_favicon();
[email protected]96d185d2009-04-24 03:28:54622 return true;
623}
624
[email protected]585b30362011-01-28 02:30:17625void TabContents::AddObserver(TabContentsObserver* observer) {
626 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49627}
628
[email protected]585b30362011-01-28 02:30:17629void TabContents::RemoveObserver(TabContentsObserver* observer) {
630 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49631}
632
[email protected]443b80e2010-12-14 00:42:23633void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
634 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34635 return;
636
[email protected]443b80e2010-12-14 00:42:23637 crashed_status_ = status;
638 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50639 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34640}
641
[email protected]744ef172009-10-16 21:53:46642void TabContents::PageActionStateChanged() {
643 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00644}
[email protected]ce5c4502009-05-06 16:46:11645
[email protected]d5f942ba2008-09-26 19:30:34646void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
647 if (delegate_)
648 delegate_->NavigationStateChanged(this, changed_flags);
649}
650
[email protected]96d185d2009-04-24 03:28:54651void TabContents::DidBecomeSelected() {
652 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16653 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
654 if (rwhv) {
655 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43656#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16657 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43658#endif
659 }
[email protected]96d185d2009-04-24 03:28:54660
[email protected]8cb5d5b2010-02-09 11:36:16661 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11662 last_selected_time_ = base::TimeTicks::Now();
[email protected]61d68ef12011-01-13 14:02:56663#if defined(OS_CHROMEOS)
664 chromeos::LocaleChangeGuard::Check(this);
665#endif
[email protected]96d185d2009-04-24 03:28:54666}
667
[email protected]a94454b2010-12-16 04:16:03668void TabContents::FadeForInstant(bool animate) {
[email protected]1b072562010-12-13 19:37:45669 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
670 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
671 if (rwhv)
[email protected]a94454b2010-12-16 04:16:03672 rwhv->SetVisuallyDeemphasized(&whitish, animate);
[email protected]1b072562010-12-13 19:37:45673}
674
675void TabContents::CancelInstantFade() {
676 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
677 if (rwhv)
678 rwhv->SetVisuallyDeemphasized(NULL, false);
679}
680
[email protected]96d185d2009-04-24 03:28:54681void TabContents::WasHidden() {
682 if (!capturing_contents()) {
683 // |render_view_host()| can be NULL if the user middle clicks a link to open
684 // a tab in then background, then closes the tab before selecting it. This
685 // is because closing the tab calls TabContents::Destroy(), which removes
686 // the |render_view_host()|; then when we actually destroy the window,
687 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16688 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
689 if (rwhv)
690 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54691 }
692
693 NotificationService::current()->Notify(
694 NotificationType::TAB_CONTENTS_HIDDEN,
695 Source<TabContents>(this),
696 NotificationService::NoDetails());
697}
698
[email protected]d5f942ba2008-09-26 19:30:34699void TabContents::Activate() {
700 if (delegate_)
701 delegate_->ActivateContents(this);
702}
703
[email protected]ea42e7782010-08-23 23:58:12704void TabContents::Deactivate() {
705 if (delegate_)
706 delegate_->DeactivateContents(this);
707}
708
[email protected]96d185d2009-04-24 03:28:54709void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16710 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
711 if (rwhv)
712 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54713}
714
715void TabContents::HideContents() {
716 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
717 // our superclass HideContents(), because some callers want to be very picky
718 // about the order in which these get called. In addition to making the code
719 // here practically impossible to understand, this also means we end up
720 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34721 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54722 WasHidden();
723}
724
[email protected]5aab5e22010-12-08 22:13:29725bool TabContents::NeedToFireBeforeUnload() {
726 // TODO(creis): Should we fire even for interstitial pages?
727 return notify_disconnection() &&
728 !showing_interstitial_page() &&
729 !render_view_host()->SuddenTerminationAllowed();
730}
731
[email protected]c0588052008-10-27 23:01:50732void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34733 WindowOpenDisposition disposition,
734 PageTransition::Type transition) {
735 if (delegate_)
[email protected]c0588052008-10-27 23:01:50736 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34737}
738
[email protected]1ccb3568d2010-02-19 10:51:16739bool TabContents::NavigateToPendingEntry(
740 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54741 return NavigateToEntry(*controller_.pending_entry(), reload_type);
742}
[email protected]96d185d2009-04-24 03:28:54743
[email protected]876bc832010-09-07 16:29:54744bool TabContents::NavigateToEntry(
745 const NavigationEntry& entry,
746 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54747 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
748 if (!dest_render_view_host)
749 return false; // Unable to create the desired render view host.
750
[email protected]770dd8b2010-05-24 18:11:39751 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
752 dest_render_view_host->EnablePreferredSizeChangedMode(
753 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
754 }
[email protected]9fb325e2010-05-06 18:23:24755
[email protected]80a8fad2011-01-29 04:02:38756 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07757 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58758 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]c09163a2011-02-15 00:05:55759 bool is_allowed_in_web_ui_renderer =
[email protected]80a8fad2011-01-29 04:02:38760 WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url());
[email protected]c09163a2011-02-15 00:05:55761 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
762 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58763
[email protected]96d185d2009-04-24 03:28:54764 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12765 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32766 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00767 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
768 dest_render_view_host,
769 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32770 }
[email protected]96d185d2009-04-24 03:28:54771
772 // Used for page load time metrics.
773 current_load_start_ = base::TimeTicks::Now();
774
775 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34776 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54777 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04778 if (delegate_) {
779 navigate_params.extra_headers =
780 delegate_->GetNavigationHeaders(navigate_params.url);
781 }
[email protected]056de2d2009-06-26 16:41:34782 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54783
784 if (entry.page_id() == -1) {
785 // HACK!! This code suppresses javascript: URLs from being added to
786 // session history, which is what we want to do for javascript: URLs that
787 // do not generate content. What we really need is a message from the
788 // renderer telling us that a new page was not created. The same message
789 // could be used for mailto: URLs and the like.
790 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
791 return false;
792 }
793
[email protected]3c9e1872010-11-18 16:17:49794 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:17795 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54796
[email protected]1ccb3568d2010-02-19 10:51:16797 if (reload_type != NavigationController::NO_RELOAD &&
798 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48799 FaviconService* favicon_service =
800 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
801 if (favicon_service)
802 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54803 }
804
[email protected]d5f942ba2008-09-26 19:30:34805 return true;
806}
807
[email protected]96d185d2009-04-24 03:28:54808void TabContents::Stop() {
809 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09810 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54811}
812
[email protected]96d185d2009-04-24 03:28:54813void TabContents::DisassociateFromPopupCount() {
814 render_view_host()->DisassociateFromPopupCount();
815}
816
817TabContents* TabContents::Clone() {
818 // We create a new SiteInstance so that the new tab won't share processes
819 // with the old one. This can be changed in the future if we need it to share
820 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32821 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54822 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07823 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54824 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08825 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08826 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54827 return tc;
828}
829
[email protected]4d677202009-07-19 07:37:12830void TabContents::ShowPageInfo(const GURL& url,
831 const NavigationEntry::SSLStatus& ssl,
832 bool show_history) {
833 if (!delegate_)
834 return;
835
[email protected]bb678332009-07-21 00:15:50836 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12837}
838
[email protected]ef0d04c2010-12-15 23:34:21839void TabContents::SaveFavicon() {
840 NavigationEntry* entry = controller_.GetActiveEntry();
841 if (!entry || entry->url().is_empty())
842 return;
843
844 // Make sure the page is in history, otherwise adding the favicon does
845 // nothing.
846 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
847 Profile::IMPLICIT_ACCESS);
848 if (!history)
849 return;
850 history->AddPageNoVisitForBookmark(entry->url());
851
852 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
853 Profile::IMPLICIT_ACCESS);
854 if (!service)
855 return;
856 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
857 if (!favicon.is_valid() || favicon.url().is_empty() ||
858 favicon.bitmap().empty()) {
859 return;
860 }
861 std::vector<unsigned char> image_data;
862 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
863 service->SetFavicon(entry->url(), favicon.url(), image_data);
864}
865
initial.commit09911bf2008-07-26 23:55:29866ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28867 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29868 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28869 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29870 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44871
872 if (child_windows_.size() == 1) {
873 window->ShowConstrainedWindow();
874 BlockTabContent(true);
875 }
876
initial.commit09911bf2008-07-26 23:55:29877 return window;
878}
879
[email protected]fa1cf0b82010-01-15 21:49:44880void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55881 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45882 // 70% opaque grey.
883 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55884 if (rwhv)
[email protected]1b072562010-12-13 19:37:45885 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44886 render_view_host()->set_ignore_input_events(blocked);
887 if (delegate_)
888 delegate_->SetTabContentBlocked(this, blocked);
889}
890
initial.commit09911bf2008-07-26 23:55:29891void TabContents::AddNewContents(TabContents* new_contents,
892 WindowOpenDisposition disposition,
893 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29894 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40895 if (all_contents_blocked_) {
896 if (!blocked_contents_)
897 blocked_contents_ = new BlockedContentContainer(this);
898 blocked_contents_->AddTabContents(
899 new_contents, disposition, initial_pos, user_gesture);
900 return;
901 }
902
initial.commit09911bf2008-07-26 23:55:29903 if (!delegate_)
904 return;
905
[email protected]35f7d212009-04-29 21:19:27906 if ((disposition == NEW_POPUP) && !user_gesture &&
907 !CommandLine::ForCurrentProcess()->HasSwitch(
908 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22909 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31910 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29911 delegate_->GetConstrainingContents(this)->AddPopup(
912 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31913 } else {
[email protected]0aa55312008-10-17 21:53:08914 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29915 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
916 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49917 NotificationService::current()->Notify(
918 NotificationType::TAB_ADDED,
919 Source<TabContentsDelegate>(delegate_),
920 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29921 }
initial.commit09911bf2008-07-26 23:55:29922
[email protected]8cc8d492010-02-02 10:40:49923 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:40924 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:29925}
926
[email protected]bcd9dc42010-01-23 16:38:18927bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:20928 bool is_js_code, const std::string& code_string,
929 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51930 RenderViewHost* host = render_view_host();
931 if (!host)
932 return false;
933
934 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:17935 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:51936 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35937}
938
[email protected]96d185d2009-04-24 03:28:54939void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49940 if (is_being_destroyed_)
941 return;
[email protected]9fb83e82010-07-02 18:24:55942 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49943 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40944 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:54945}
946
[email protected]5c9e97a2009-09-09 23:48:30947gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54948 return view_->GetContentNativeView();
949}
950
951gfx::NativeView TabContents::GetNativeView() const {
952 return view_->GetNativeView();
953}
954
955void TabContents::GetContainerBounds(gfx::Rect *out) const {
956 view_->GetContainerBounds(out);
957}
958
959void TabContents::Focus() {
960 view_->Focus();
961}
962
[email protected]90daadb42009-06-08 21:27:28963void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54964 if (showing_interstitial_page()) {
965 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
966 return;
967 }
[email protected]96d185d2009-04-24 03:28:54968 render_view_host()->SetInitialFocus(reverse);
969}
970
971bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40972 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58973 if (web_ui)
974 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43975 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25976 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43977 return true;
[email protected]96d185d2009-04-24 03:28:54978 return false;
979}
980
[email protected]a26dc362010-04-23 01:48:58981void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38982 if (delegate())
[email protected]a26dc362010-04-23 01:48:58983 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38984}
985
[email protected]616ed5a2008-11-21 22:27:24986void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32987 if (delegate_ && !delegate_->infobars_enabled()) {
988 delegate->InfoBarClosed();
989 return;
990 }
991
[email protected]616ed5a2008-11-21 22:27:24992 // Look through the existing InfoBarDelegates we have for a match. If we've
993 // already got one that matches, then we don't add the new one.
[email protected]ec8f51162011-02-08 04:20:40994 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:45995 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
996 // Tell the new infobar to close so that it can clean itself up.
997 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:24998 return;
[email protected]6d27a7b2009-12-18 23:25:45999 }
[email protected]616ed5a2008-11-21 22:27:241000 }
1001
1002 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561003 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:191004 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:561005 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241006
1007 // Add ourselves as an observer for navigations the first time a delegate is
1008 // added. We use this notification to expire InfoBars that need to expire on
1009 // page transitions.
1010 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561011 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571012 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241013 }
1014}
1015
1016void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321017 if (delegate_ && !delegate_->infobars_enabled()) {
1018 return;
1019 }
1020
[email protected]616ed5a2008-11-21 22:27:241021 std::vector<InfoBarDelegate*>::iterator it =
1022 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1023 if (it != infobar_delegates_.end()) {
1024 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561025 NotificationService::current()->Notify(
1026 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1027 Source<TabContents>(this),
1028 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241029
[email protected]f4f50ef2011-01-21 19:01:191030 infobar_delegates_.erase(it);
1031 // Remove ourselves as an observer if we are tracking no more InfoBars.
1032 if (infobar_delegates_.empty()) {
1033 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1034 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031035 }
[email protected]616ed5a2008-11-21 22:27:241036 }
1037}
[email protected]3edd9522009-03-04 22:19:411038
[email protected]f81821c2009-08-07 01:29:471039void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1040 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321041 if (delegate_ && !delegate_->infobars_enabled()) {
1042 new_delegate->InfoBarClosed();
1043 return;
1044 }
1045
[email protected]f81821c2009-08-07 01:29:471046 std::vector<InfoBarDelegate*>::iterator it =
1047 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1048 DCHECK(it != infobar_delegates_.end());
1049
1050 // Notify the container about the change of plans.
1051 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1052 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1053 old_delegate, new_delegate));
1054 NotificationService::current()->Notify(
1055 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1056 Source<TabContents>(this),
1057 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1058
[email protected]f4f50ef2011-01-21 19:01:191059 // Remove the old one.
1060 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:471061
1062 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081063 DCHECK(find(infobar_delegates_.begin(),
1064 infobar_delegates_.end(), new_delegate) ==
1065 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471066 infobar_delegates_.push_back(new_delegate);
1067}
1068
[email protected]20ede072009-10-06 00:28:351069bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271070 if (showing_interstitial_page())
1071 return false;
1072
[email protected]c8f74942010-09-03 10:04:141073 // Do not show bookmarks bar if bookmarks aren't enabled.
1074 if (!browser_defaults::bookmarks_enabled)
1075 return false;
1076
[email protected]d0980792011-02-13 19:41:401077 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:541078 // similar, but for non-first loads, we want to use the committed entry. This
1079 // is so the bookmarks bar disappears at the same time the page does.
1080 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:351081 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:581082 return (render_manager_.web_ui() == NULL) ?
1083 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541084 }
1085
1086 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:401087 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:541088 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:581089 if (render_manager_.pending_web_ui())
1090 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
1091 return (render_manager_.web_ui() == NULL) ?
1092 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541093}
1094
[email protected]3edd9522009-03-04 22:19:411095void TabContents::ToolbarSizeChanged(bool is_animating) {
1096 TabContentsDelegate* d = delegate();
1097 if (d)
1098 d->ToolbarSizeChanged(this, is_animating);
1099}
[email protected]616ed5a2008-11-21 22:27:241100
[email protected]fc6fb7fb2009-11-07 02:35:041101bool TabContents::CanDownload(int request_id) {
1102 TabContentsDelegate* d = delegate();
1103 if (d)
1104 return d->CanDownload(request_id);
1105 return true;
1106}
1107
[email protected]d5f942ba2008-09-26 19:30:341108void TabContents::OnStartDownload(DownloadItem* download) {
1109 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341110
1111 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311112 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341113
[email protected]5b928b62010-08-03 11:46:511114 if (tab_contents && tab_contents->delegate())
1115 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411116}
[email protected]3edd9522009-03-04 22:19:411117
[email protected]d5f942ba2008-09-26 19:30:341118void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371119 ConstrainedWindowList::iterator i(
1120 std::find(child_windows_.begin(), child_windows_.end(), window));
1121 bool removed_topmost_window = i == child_windows_.begin();
1122 if (i != child_windows_.end())
1123 child_windows_.erase(i);
1124 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441125 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371126 } else {
1127 if (removed_topmost_window)
1128 child_windows_[0]->ShowConstrainedWindow();
1129 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441130 }
[email protected]66ba4932009-06-04 19:22:131131}
[email protected]d5f942ba2008-09-26 19:30:341132
[email protected]c65e2f152010-10-14 15:30:401133void TabContents::WillCloseBlockedContentContainer(
1134 BlockedContentContainer* container) {
1135 DCHECK(blocked_contents_ == container);
1136 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491137 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341138}
1139
[email protected]d5f942ba2008-09-26 19:30:341140void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351141#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061142 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351143#endif
[email protected]d5f942ba2008-09-26 19:30:341144}
1145
[email protected]420ae012009-04-24 05:16:321146void TabContents::OnSavePage() {
1147 // If we can not save the page, try to download it.
1148 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1149 DownloadManager* dlm = profile()->GetDownloadManager();
1150 const GURL& current_page_url = GetURL();
1151 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221152 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321153 return;
1154 }
1155
1156 Stop();
1157
1158 // Create the save package and possibly prompt the user for the name to save
1159 // the page as. The user prompt is an asynchronous operation that runs on
1160 // another thread.
[email protected]b5a1d11c2011-02-17 03:09:421161 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321162 save_package_->GetSaveInfo();
1163}
1164
1165// Used in automated testing to bypass prompting the user for file names.
1166// Instead, the names and paths are hard coded rather than running them through
1167// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111168bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321169 SavePackage::SavePackageType save_type) {
1170 // Stop the page from navigating.
1171 Stop();
1172
[email protected]b5a1d11c2011-02-17 03:09:421173 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591174 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321175}
1176
[email protected]89d6e6e2009-12-03 23:06:511177void TabContents::EmailPageLocation() {
1178 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1179 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1180 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1181 title + "&body=%0A%0A" + page_url;
1182 platform_util::OpenExternal(GURL(mailto));
1183}
1184
[email protected]420ae012009-04-24 05:16:321185void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161186 if (CommandLine::ForCurrentProcess()->HasSwitch(
1187 switches::kEnablePrintPreview)) {
1188 if (showing_interstitial_page())
1189 return;
[email protected]83a58a22011-02-05 03:44:481190
1191 printing::PrintPreviewTabController* tab_controller =
1192 printing::PrintPreviewTabController::GetInstance();
1193 if (!tab_controller)
1194 return;
1195 tab_controller->GetOrCreatePreviewTab(this, controller().window_id().id());
1196
[email protected]dbeebd52010-11-16 20:34:161197 render_view_host()->PrintPreview();
1198 } else {
1199 PrintNow();
1200 }
[email protected]420ae012009-04-24 05:16:321201}
1202
1203bool TabContents::PrintNow() {
1204 // We can't print interstitial page for now.
1205 if (showing_interstitial_page())
1206 return false;
1207
1208 return render_view_host()->PrintPages();
1209}
1210
[email protected]82270452009-06-19 15:58:011211void TabContents::PrintingDone(int document_cookie, bool success) {
1212 render_view_host()->PrintingDone(document_cookie, success);
1213}
1214
[email protected]420ae012009-04-24 05:16:321215bool TabContents::IsActiveEntry(int32 page_id) {
1216 NavigationEntry* active_entry = controller_.GetActiveEntry();
1217 return (active_entry != NULL &&
1218 active_entry->site_instance() == GetSiteInstance() &&
1219 active_entry->page_id() == page_id);
1220}
1221
[email protected]b2fe07d12010-02-09 14:38:081222void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161223 set_encoding(encoding);
1224 render_view_host()->SetPageEncoding(encoding);
1225}
1226
[email protected]b2fe07d12010-02-09 14:38:081227void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161228 reset_encoding();
1229 render_view_host()->ResetPageEncodingToDefault();
1230}
1231
1232void TabContents::WindowMoveOrResizeStarted() {
1233 render_view_host()->WindowMoveOrResizeStarted();
1234}
1235
[email protected]c65e2f152010-10-14 15:30:401236void TabContents::SetAllContentsBlocked(bool value) {
1237 if (all_contents_blocked_ == value)
1238 return;
1239
1240 all_contents_blocked_ = value;
1241 if (!all_contents_blocked_ && blocked_contents_) {
1242 std::vector<TabContents*> blocked;
1243 blocked_contents_->GetBlockedContents(&blocked);
1244 for (size_t i = 0; i < blocked.size(); ++i)
1245 blocked_contents_->LaunchForContents(blocked[i]);
1246 }
1247}
1248
[email protected]3f8eb7f2009-10-02 23:58:051249void TabContents::LogNewTabTime(const std::string& event_name) {
1250 // Not all new tab pages get timed. In those cases, we don't have a
1251 // new_tab_start_time_.
1252 if (new_tab_start_time_.is_null())
1253 return;
1254
1255 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441256 MetricEventDurationDetails details(event_name,
1257 static_cast<int>(duration.InMilliseconds()));
1258
[email protected]7ab1e7d62009-10-14 23:32:011259 if (event_name == "Tab.NewTabScriptStart") {
1260 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1261 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1262 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1263 } else if (event_name == "Tab.NewTabOnload") {
1264 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051265 // The new tab page has finished loading; reset it.
1266 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441267 } else {
1268 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051269 }
[email protected]84abba62009-10-07 17:01:441270 NotificationService::current()->Notify(
1271 NotificationType::METRIC_EVENT_DURATION,
1272 Source<TabContents>(this),
1273 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051274}
1275
[email protected]7ab1e7d62009-10-14 23:32:011276void TabContents::OnCloseStarted() {
1277 if (tab_close_start_time_.is_null())
1278 tab_close_start_time_ = base::TimeTicks::Now();
1279}
1280
[email protected]46624bf2010-06-09 16:04:191281bool TabContents::ShouldAcceptDragAndDrop() const {
1282#if defined(OS_CHROMEOS)
1283 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1284 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201285 if (delegate() && delegate()->IsPopup(this))
1286 return false;
1287 return true;
[email protected]46624bf2010-06-09 16:04:191288#else
1289 return true;
1290#endif
1291}
1292
[email protected]7813bd72011-02-05 02:19:341293void TabContents::SystemDragEnded() {
1294 if (render_view_host())
1295 render_view_host()->DragSourceSystemDragEnded();
1296 if (delegate())
1297 delegate()->DragEnded();
1298}
1299
[email protected]ec0b6c42010-08-26 03:16:581300void TabContents::UpdateHistoryForNavigation(
1301 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1302 if (profile()->IsOffTheRecord())
1303 return;
1304
1305 // Add to history service.
1306 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1307 if (hs)
1308 hs->AddPage(*add_page_args);
1309}
1310
1311void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1312 if (profile()->IsOffTheRecord())
1313 return;
1314
1315 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1316 if (hs)
1317 hs->SetPageTitle(entry.virtual_url(), entry.title());
1318}
1319
[email protected]d0b8d092010-10-25 04:05:171320double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251321 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1322 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171323 return 0;
[email protected]b75b8292010-10-01 07:28:251324
1325 double zoom_level;
1326 if (temporary_zoom_settings_) {
1327 zoom_level = zoom_map->GetTemporaryZoomLevel(
1328 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1329 } else {
1330 zoom_level = zoom_map->GetZoomLevel(GetURL());
1331 }
[email protected]d0b8d092010-10-25 04:05:171332 return zoom_level;
1333}
[email protected]b75b8292010-10-01 07:28:251334
[email protected]d0b8d092010-10-25 04:05:171335int TabContents::GetZoomPercent(bool* enable_increment,
1336 bool* enable_decrement) {
1337 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251338 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171339 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251340 *enable_decrement = percent > minimum_zoom_percent_;
1341 *enable_increment = percent < maximum_zoom_percent_;
1342 return percent;
1343}
1344
[email protected]3c733bde2010-12-21 19:56:311345void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501346 if (!delegate_)
1347 return;
1348
1349 NavigationEntry* active_entry = controller().GetActiveEntry();
1350 if (!active_entry)
1351 return;
1352
1353 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121354}
1355
[email protected]724159a2010-12-30 01:11:181356void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1357 bool is_main_frame,
1358 const GURL& url) {
1359 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1360 GURL validated_url(url);
1361 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1362 GetRenderProcessHost()->id(), &validated_url);
1363
1364 ProvisionalLoadDetails details(
1365 is_main_frame,
1366 controller_.IsURLInPageNavigation(validated_url),
1367 validated_url, std::string(), false, is_error_page, frame_id);
1368 NotificationService::current()->Notify(
1369 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1370 Source<NavigationController>(&controller_),
1371 Details<ProvisionalLoadDetails>(&details));
1372 if (is_main_frame) {
1373 // If we're displaying a network error page do not reset the content
1374 // settings delegate's cookies so the user has a chance to modify cookie
1375 // settings.
1376 if (!is_error_page)
1377 content_settings_delegate_->ClearCookieSpecificContentSettings();
1378 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]e7d50892011-01-19 21:47:381379
1380 // Check if the URL we are about to load has been prerendered by any chance,
1381 // and use it if possible.
1382 MaybeUsePreloadedPage(url);
[email protected]724159a2010-12-30 01:11:181383 }
1384}
1385
1386void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1387 const GURL& source_url,
1388 const GURL& target_url) {
1389 NavigationEntry* entry;
1390 if (page_id == -1)
1391 entry = controller_.pending_entry();
1392 else
1393 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1394 if (!entry || entry->url() != source_url)
1395 return;
1396 entry->set_url(target_url);
[email protected]e7d50892011-01-19 21:47:381397
1398 // Check if the URL we are about to load has been prerendered by any chance,
1399 // and use it if possible.
1400 MaybeUsePreloadedPage(target_url);
[email protected]724159a2010-12-30 01:11:181401}
1402
1403void TabContents::OnDidFailProvisionalLoadWithError(
1404 int64 frame_id,
1405 bool is_main_frame,
1406 int error_code,
1407 const GURL& url,
1408 bool showing_repost_interstitial) {
1409 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1410 << ", error_code: " << error_code
1411 << " is_main_frame: " << is_main_frame
1412 << " showing_repost_interstitial: " << showing_repost_interstitial
1413 << " frame_id: " << frame_id;
1414 GURL validated_url(url);
1415 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1416 GetRenderProcessHost()->id(), &validated_url);
1417
1418 if (net::ERR_ABORTED == error_code) {
1419 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1420 // This means that the interstitial won't be torn down properly, which is
1421 // bad. But if we have an interstitial, go back to another tab type, and
1422 // then load the same interstitial again, we could end up getting the first
1423 // interstitial's "failed" message (as a result of the cancel) when we're on
1424 // the second one.
1425 //
1426 // We can't tell this apart, so we think we're tearing down the current page
1427 // which will cause a crash later one. There is also some code in
1428 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1429 // out because of this problem.
1430 //
1431 // http://code.google.com/p/chromium/issues/detail?id=2855
1432 // Because this will not tear down the interstitial properly, if "back" is
1433 // back to another tab type, the interstitial will still be somewhat alive
1434 // in the previous tab type. If you navigate somewhere that activates the
1435 // tab with the interstitial again, you'll see a flash before the new load
1436 // commits of the interstitial page.
1437 if (showing_interstitial_page()) {
1438 LOG(WARNING) << "Discarding message during interstitial.";
1439 return;
1440 }
1441
1442 // This will discard our pending entry if we cancelled the load (e.g., if we
1443 // decided to download the file instead of load it). Only discard the
1444 // pending entry if the URLs match, otherwise the user initiated a navigate
1445 // before the page loaded so that the discard would discard the wrong entry.
1446 NavigationEntry* pending_entry = controller_.pending_entry();
1447 if (pending_entry && pending_entry->url() == validated_url) {
1448 controller_.DiscardNonCommittedEntries();
1449 // Update the URL display.
1450 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1451 }
1452
1453 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1454 }
1455
1456 // Send out a notification that we failed a provisional load with an error.
1457 ProvisionalLoadDetails details(
1458 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
1459 validated_url, std::string(), false, false, frame_id);
1460 details.set_error_code(error_code);
1461
1462 NotificationService::current()->Notify(
1463 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1464 Source<NavigationController>(&controller_),
1465 Details<ProvisionalLoadDetails>(&details));
1466}
1467
1468void TabContents::OnDidLoadResourceFromMemoryCache(
1469 const GURL& url,
[email protected]724159a2010-12-30 01:11:181470 const std::string& security_info) {
1471 static base::StatsCounter cache("WebKit.CacheHit");
1472 cache.Increment();
1473
1474 // Send out a notification that we loaded a resource from our memory cache.
1475 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1476 SSLManager::DeserializeSecurityInfo(security_info,
1477 &cert_id, &cert_status,
1478 &security_bits,
1479 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161480 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1481 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181482
1483 NotificationService::current()->Notify(
1484 NotificationType::LOAD_FROM_MEMORY_CACHE,
1485 Source<NavigationController>(&controller_),
1486 Details<LoadFromMemoryCacheDetails>(&details));
1487}
1488
1489void TabContents::OnDidDisplayInsecureContent() {
1490 displayed_insecure_content_ = true;
1491 SSLManager::NotifySSLInternalStateChanged();
1492}
1493
1494void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021495 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231496 LOG(INFO) << security_origin << " ran insecure content from "
1497 << target_url.possibly_invalid_spec();
[email protected]724159a2010-12-30 01:11:181498 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1499}
1500
1501void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1502 controller_.DocumentLoadedInFrame();
1503 NotificationService::current()->Notify(
1504 NotificationType::FRAME_DOM_CONTENT_LOADED,
1505 Source<NavigationController>(&controller_),
1506 Details<int64>(&frame_id));
1507}
1508
1509void TabContents::OnDidFinishLoad(int64 frame_id) {
1510 NotificationService::current()->Notify(
1511 NotificationType::FRAME_DID_FINISH_LOAD,
1512 Source<NavigationController>(&controller_),
1513 Details<int64>(&frame_id));
1514}
1515
[email protected]c8f73ab2011-01-22 00:05:171516void TabContents::OnUpdateContentRestrictions(int restrictions) {
1517 content_restrictions_ = restrictions;
1518 delegate()->ContentRestrictionsChanged(this);
1519}
1520
1521void TabContents::OnPDFHasUnsupportedFeature() {
1522 PDFHasUnsupportedFeature(this);
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]ec8f51162011-02-08 04:20:401592 // NOTE: It is not safe to change the following code to count upwards or use
1593 // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
1594 // list.
1595 for (size_t i = infobar_count(); i > 0; --i) {
1596 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
[email protected]f86a07022008-11-25 01:06:051597 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241598 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241599 }
1600}
[email protected]fdd61c62009-04-22 19:22:571601
[email protected]d0980792011-02-13 19:41:401602WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581603 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541604 // that goes along with it to control the basic flags. For example, we want to
1605 // show the pending URL in the URL bar, so we want the display_url flag to
1606 // be from the pending entry.
1607 //
1608 // The confusion comes because there are multiple possibilities for the
1609 // initial load in a tab as a side effect of the way the RenderViewHostManager
1610 // works.
1611 //
[email protected]e0112912011-02-02 22:54:351612 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541613 // the pending one, and we want it to apply here.
1614 //
1615 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1616 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581617 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351618 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541619 //
1620 // This condition handles all of these cases:
1621 //
1622 // - First load in first tab: no committed nav entry + pending nav entry +
1623 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351624 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541625 //
1626 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351627 // no pending Web UI:
1628 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541629 //
1630 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351631 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541632 //
1633 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351634 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541635 if (controller_.pending_entry() &&
1636 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581637 render_manager_.pending_web_ui()))
1638 return render_manager_.pending_web_ui();
1639 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541640}
[email protected]420ae012009-04-24 05:16:321641
1642void TabContents::DidNavigateMainFramePostCommit(
1643 const NavigationController::LoadCommittedDetails& details,
1644 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]80a8fad2011-01-29 04:02:381645 if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) {
1646 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441647 // that opened the window, as long as both renderers have the same
1648 // privileges.
[email protected]80a8fad2011-01-29 04:02:381649 if (opener_web_ui_type_ ==
1650 WebUIFactory::GetWebUIType(profile(), GetURL())) {
[email protected]7ade2732011-02-10 00:13:581651 WebUI* web_ui = WebUIFactory::CreateWebUIForURL(this, GetURL());
1652 // web_ui might be NULL if the URL refers to a non-existent extension.
1653 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401654 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581655 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441656 }
1657 }
[email protected]80a8fad2011-01-29 04:02:381658 opener_web_ui_type_ = WebUIFactory::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441659 }
1660
[email protected]420ae012009-04-24 05:16:321661 if (details.is_user_initiated_main_frame_load()) {
1662 // Clear the status bubble. This is a workaround for a bug where WebKit
1663 // doesn't let us know that the cursor left an element during a
1664 // transition (this is also why the mouse cursor remains as a hand after
1665 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1666 // clear the bubble when a user navigates to a named anchor in the same
1667 // page.
1668 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321669 }
1670
[email protected]420ae012009-04-24 05:16:321671 // Allow the new page to set the title again.
1672 received_page_title_ = false;
1673
1674 // Get the favicon, either from history or request it from the net.
[email protected]b5a1d11c2011-02-17 03:09:421675 fav_icon_helper_->FetchFavIcon(details.entry->url());
[email protected]420ae012009-04-24 05:16:321676
[email protected]0de80162010-02-03 04:52:351677 // Clear all page actions, blocked content notifications and browser actions
1678 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141679 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:001680 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:081681 if (service) {
1682 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571683 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081684 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521685 if (browser_action) {
1686 browser_action->ClearAllValuesForTab(controller().session_id().id());
1687 NotificationService::current()->Notify(
1688 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571689 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521690 NotificationService::NoDetails());
1691 }
[email protected]92c6f9b92009-10-24 04:35:081692
[email protected]5d246db22009-10-27 06:17:571693 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521694 service->extensions()->at(i)->page_action();
1695 if (page_action) {
1696 page_action->ClearAllValuesForTab(controller().session_id().id());
1697 PageActionStateChanged();
1698 }
[email protected]92c6f9b92009-10-24 04:35:081699 }
[email protected]aece2c7f2009-08-27 20:43:171700 }
[email protected]0de80162010-02-03 04:52:351701
1702 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401703 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341704 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401705 blocked_contents_->Destroy();
1706 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351707 }
1708
1709 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411710 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551711 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471712
1713 // Once the main frame is navigated, we're no longer considered to have
1714 // displayed insecure content.
1715 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171716 }
[email protected]ce5c4502009-05-06 16:46:111717
[email protected]8cc8d492010-02-02 10:40:491718 // Close constrained windows if necessary.
1719 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1720 details.previous_url, details.entry->url()))
1721 CloseConstrainedWindows();
1722
[email protected]3c9e1872010-11-18 16:17:491723 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171724 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491725 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321726}
1727
1728void TabContents::DidNavigateAnyFramePostCommit(
1729 RenderViewHost* render_view_host,
1730 const NavigationController::LoadCommittedDetails& details,
1731 const ViewHostMsg_FrameNavigate_Params& params) {
1732 // If we navigate, start showing messages again. This does nothing to prevent
1733 // a malicious script from spamming messages, since the script could just
1734 // reload the page to stop blocking.
1735 suppress_javascript_messages_ = false;
1736
[email protected]3c9e1872010-11-18 16:17:491737 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171738 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491739 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551740
1741 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581742 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321743}
1744
[email protected]8cc8d492010-02-02 10:40:491745void TabContents::CloseConstrainedWindows() {
1746 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321747 // We use indices instead of iterators in case CloseWindow does something
1748 // that may invalidate an iterator.
[email protected]61d68ef12011-01-13 14:02:561749 for (size_t i = 0; i < child_windows_.size(); ++i) {
1750 ConstrainedWindow* window = child_windows_[child_windows_.size() - 1 - i];
[email protected]fa1cf0b82010-01-15 21:49:441751 if (window) {
[email protected]420ae012009-04-24 05:16:321752 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441753 BlockTabContent(false);
1754 }
[email protected]420ae012009-04-24 05:16:321755 }
1756}
1757
[email protected]420ae012009-04-24 05:16:321758void TabContents::UpdateAlternateErrorPageURL() {
1759 GURL url = GetAlternateErrorPageURL();
1760 render_view_host()->SetAlternateErrorPageURL(url);
1761}
1762
1763void TabContents::UpdateWebPreferences() {
1764 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1765}
1766
[email protected]d0b8d092010-10-25 04:05:171767void TabContents::UpdateZoomLevel() {
1768 render_view_host()->SetZoomLevel(GetZoomLevel());
1769}
1770
[email protected]420ae012009-04-24 05:16:321771void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1772 RenderViewHost* rvh) {
1773 // If we are creating a RVH for a restored controller, then we might
1774 // have more page IDs than the SiteInstance's current max page ID. We must
1775 // make sure that the max page ID is larger than any restored page ID.
1776 // Note that it is ok for conflicting page IDs to exist in another tab
1777 // (i.e., NavigationController), but if any page ID is larger than the max,
1778 // the back/forward list will get confused.
1779 int max_restored_page_id = controller_.max_restored_page_id();
1780 if (max_restored_page_id > 0) {
1781 int curr_max_page_id = site_instance->max_page_id();
1782 if (max_restored_page_id > curr_max_page_id) {
1783 // Need to update the site instance immediately.
1784 site_instance->UpdateMaxPageID(max_restored_page_id);
1785
1786 // Also tell the renderer to update its internal representation. We
1787 // need to reserve enough IDs to make all restored page IDs less than
1788 // the max.
1789 if (curr_max_page_id < 0)
1790 curr_max_page_id = 0;
1791 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1792 }
1793 }
1794}
1795
[email protected]ec0b6c42010-08-26 03:16:581796scoped_refptr<history::HistoryAddPageArgs>
1797TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541798 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471799 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321800 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581801 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1802 new history::HistoryAddPageArgs(
1803 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1804 params.redirects, params.transition, history::SOURCE_BROWSED,
1805 details.did_replace_entry));
1806 if (PageTransition::IsMainFrame(params.transition) &&
1807 virtual_url != params.url) {
1808 // Hack on the "virtual" URL so that it will appear in history. For some
1809 // types of URLs, we will display a magic URL that is different from where
1810 // the page is actually navigated. We want the user to see in history what
1811 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1812 // only applies to the main frame, as the virtual URL doesn't apply to
1813 // sub-frames.
1814 add_page_args->url = virtual_url;
1815 if (!add_page_args->redirects.empty())
1816 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321817 }
[email protected]ec0b6c42010-08-26 03:16:581818 return add_page_args;
[email protected]420ae012009-04-24 05:16:321819}
1820
1821bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1822 const std::wstring& title) {
1823 // For file URLs without a title, use the pathname instead. In the case of a
1824 // synthesized title, we don't want the update to count toward the "one set
1825 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251826 string16 final_title;
[email protected]420ae012009-04-24 05:16:321827 bool explicit_set;
1828 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251829 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321830 explicit_set = false; // Don't count synthetic titles toward the set limit.
1831 } else {
[email protected]e53668962010-06-23 15:35:251832 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321833 explicit_set = true;
1834 }
1835
[email protected]e53668962010-06-23 15:35:251836 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321837 return false; // Nothing changed, don't bother.
1838
[email protected]e53668962010-06-23 15:35:251839 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321840
[email protected]ec0b6c42010-08-26 03:16:581841 if (!received_page_title_) {
1842 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321843 received_page_title_ = explicit_set;
1844 }
1845
1846 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251847 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321848
[email protected]cbc0e1b2010-04-12 18:33:041849 NotificationService::current()->Notify(
1850 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1851 Source<TabContents>(this),
1852 NotificationService::NoDetails());
1853
[email protected]420ae012009-04-24 05:16:321854 return true;
1855}
1856
1857void TabContents::NotifySwapped() {
1858 // After sending out a swap notification, we need to send a disconnect
1859 // notification so that clients that pick up a pointer to |this| can NULL the
1860 // pointer. See Bug 1230284.
1861 notify_disconnection_ = true;
1862 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341863 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221864 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321865 NotificationService::NoDetails());
1866}
1867
1868void TabContents::NotifyConnected() {
1869 notify_disconnection_ = true;
1870 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341871 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221872 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321873 NotificationService::NoDetails());
1874}
1875
1876void TabContents::NotifyDisconnected() {
1877 if (!notify_disconnection_)
1878 return;
1879
1880 notify_disconnection_ = false;
1881 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341882 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221883 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321884 NotificationService::NoDetails());
1885}
1886
[email protected]7d472472011-01-22 01:30:251887void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541888 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1889 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1890 if (!entry)
1891 return;
1892 // Note that we don't call NavigationController::GotToOffset() as we don't
1893 // want to create a pending navigation entry (it might end up lingering
1894 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:521895 entry->set_transition_type(entry->transition_type() |
1896 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:541897 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
1898 }
[email protected]bf5c2ff392009-07-08 16:24:331899}
1900
[email protected]38789d82010-11-17 06:03:441901void TabContents::OnDidGetApplicationInfo(int32 page_id,
1902 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511903 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331904
[email protected]ed5431872009-11-17 08:39:511905 if (delegate())
1906 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331907}
1908
[email protected]bb461532010-11-26 21:50:231909void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
1910 if (delegate())
1911 delegate()->OnInstallApplication(this, info);
1912}
1913
[email protected]a2cf65eb2010-01-18 08:20:381914void TabContents::OnPageContents(const GURL& url,
[email protected]a2cf65eb2010-01-18 08:20:381915 int32 page_id,
[email protected]e5106202010-06-11 21:12:361916 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:101917 const std::string& language,
1918 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:381919 // Don't index any https pages. People generally don't want their bank
1920 // accounts, etc. indexed on their computer, especially since some of these
1921 // things are not marked cachable.
1922 // TODO(brettw) we may want to consider more elaborate heuristics such as
1923 // the cachability of the page. We may also want to consider subframes (this
1924 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271925 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1926 // content indexing for chromeos in some future releases.
1927#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381928 if (!url.SchemeIsSecure()) {
1929 Profile* p = profile();
1930 if (p && !p->IsOffTheRecord()) {
1931 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1932 if (hs)
1933 hs->SetPageContents(url, contents);
1934 }
1935 }
[email protected]ccd40a52010-05-11 16:15:271936#endif
[email protected]a8a81292010-01-21 00:32:451937
[email protected]1c57b7b2010-07-12 17:38:101938 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:451939
1940 std::string lang = language;
1941 NotificationService::current()->Notify(
1942 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151943 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451944 Details<std::string>(&lang));
[email protected]d54169e92011-01-21 09:19:521945
1946 // Generate the thumbnail here if the in-browser thumbnailing is enabled.
1947 if (CommandLine::ForCurrentProcess()->HasSwitch(
1948 switches::kEnableInBrowserThumbnailing)) {
1949 ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url);
1950 }
[email protected]a2cf65eb2010-01-18 08:20:381951}
1952
[email protected]7e0831b2010-02-01 08:45:151953void TabContents::OnPageTranslated(int32 page_id,
1954 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:161955 const std::string& translated_lang,
1956 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:551957 language_state_.set_current_language(translated_lang);
1958 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:161959 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:151960 NotificationService::current()->Notify(
1961 NotificationType::PAGE_TRANSLATED,
1962 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:161963 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:151964}
1965
[email protected]ce833282010-11-04 15:48:391966void TabContents::OnSetSuggestions(
1967 int32 page_id,
1968 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:261969 if (delegate())
[email protected]ce833282010-11-04 15:48:391970 delegate()->OnSetSuggestions(page_id, suggestions);
1971}
1972
1973void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
1974 if (delegate())
1975 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:261976}
1977
[email protected]34f128d2011-01-25 19:07:441978void TabContents::OnRunFileChooser(
1979 const ViewHostMsg_RunFileChooser_Params& params) {
1980 if (file_select_helper_.get() == NULL)
1981 file_select_helper_.reset(new FileSelectHelper(profile()));
1982 file_select_helper_->RunFileChooser(render_view_host(), params);
1983}
1984
1985
[email protected]dcd5b332010-08-11 08:55:181986void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:561987 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241988 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:561989}
1990
[email protected]8d3347f2009-07-09 22:00:211991RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321992 return view_.get();
1993}
1994
[email protected]8d3347f2009-07-09 22:00:211995RenderViewHostDelegate::RendererManagement*
1996TabContents::GetRendererManagementDelegate() {
1997 return &render_manager_;
1998}
1999
[email protected]46ba9082010-06-22 10:00:582000RenderViewHostDelegate::ContentSettings*
2001TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552002 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582003}
2004
[email protected]1f18184a2010-07-21 19:34:492005RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2006 return GetSSLHelper();
2007}
2008
[email protected]fd571bb2010-03-19 01:23:542009AutomationResourceRoutingDelegate*
2010TabContents::GetAutomationResourceRoutingDelegate() {
2011 return delegate();
2012}
2013
[email protected]ced90ae12010-02-20 02:06:162014RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2015 return bookmark_drag_;
2016}
2017
2018void TabContents::SetBookmarkDragDelegate(
2019 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2020 bookmark_drag_ = bookmark_drag;
2021}
2022
[email protected]9fb83e82010-07-02 18:24:552023TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2024 return content_settings_delegate_.get();
2025}
2026
[email protected]93623c5d2009-12-10 21:40:322027RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462028 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512029}
2030
[email protected]57c6a652009-05-04 07:58:342031TabContents* TabContents::GetAsTabContents() {
2032 return this;
2033}
2034
[email protected]7b291f92009-08-14 05:43:532035ViewType::Type TabContents::GetRenderViewType() const {
2036 return ViewType::TAB_CONTENTS;
2037}
2038
2039int TabContents::GetBrowserWindowID() const {
2040 return controller().window_id().id();
2041}
2042
[email protected]420ae012009-04-24 05:16:322043void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062044 NotificationService::current()->Notify(
2045 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2046 Source<TabContents>(this),
2047 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322048 NavigationEntry* entry = controller_.GetActiveEntry();
2049 if (!entry)
2050 return;
2051
2052 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352053 // use the pending Web UI rather than any possibly existing committed one.
[email protected]7ade2732011-02-10 00:13:582054 if (render_manager_.pending_web_ui()) {
2055 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322056 }
2057
2058 if (entry->IsViewSourceMode()) {
2059 // Put the renderer in view source mode.
2060 render_view_host->Send(
2061 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2062 }
[email protected]0666aef2009-05-13 19:48:082063
2064 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322065}
2066
2067void TabContents::RenderViewReady(RenderViewHost* rvh) {
2068 if (rvh != render_view_host()) {
2069 // Don't notify the world, since this came from a renderer in the
2070 // background.
2071 return;
2072 }
2073
2074 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302075 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232076 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302077
2078 // Restore the focus to the tab (otherwise the focus will be on the top
2079 // window).
[email protected]484ae5912010-09-29 19:16:142080 if (was_crashed && !FocusLocationBarByDefault() &&
2081 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302082 Focus();
[email protected]484ae5912010-09-29 19:16:142083 }
[email protected]420ae012009-04-24 05:16:322084}
2085
[email protected]443b80e2010-12-14 00:42:232086void TabContents::RenderViewGone(RenderViewHost* rvh,
2087 base::TerminationStatus status,
2088 int error_code) {
[email protected]420ae012009-04-24 05:16:322089 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092090 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322091 return;
2092 if (rvh != render_view_host()) {
2093 // The pending page's RenderViewHost is gone.
2094 return;
2095 }
2096
2097 SetIsLoading(false, NULL);
2098 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232099 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322100
[email protected]ff9efc62010-02-18 22:10:542101 // Remove all infobars.
[email protected]ec8f51162011-02-08 04:20:402102 while (!infobar_delegates_.empty())
2103 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
[email protected]ff9efc62010-02-18 22:10:542104
[email protected]8e537302009-06-10 21:19:582105 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552106 // Only do this if we're not in browser shutdown, so that TabContents
2107 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2108 // visible do not flash a sad tab page.
2109 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:162110 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322111
2112 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002113 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322114}
2115
[email protected]2e4633c2009-07-09 16:58:062116void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2117 NotificationService::current()->Notify(
2118 NotificationType::RENDER_VIEW_HOST_DELETED,
2119 Source<TabContents>(this),
2120 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482121 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062122}
2123
[email protected]420ae012009-04-24 05:16:322124void TabContents::DidNavigate(RenderViewHost* rvh,
2125 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372126 int extra_invalidate_flags = 0;
2127
2128 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]e7d50892011-01-19 21:47:382129 if (MaybeUsePreloadedPage(params.url)) {
2130 return;
[email protected]33f74972010-12-08 16:40:362131 }
2132
[email protected]20ede072009-10-06 00:28:352133 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372134
[email protected]420ae012009-04-24 05:16:322135 render_manager_.DidNavigateMainFrame(rvh);
2136
[email protected]20ede072009-10-06 00:28:352137 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372138 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372139 }
2140
[email protected]420ae012009-04-24 05:16:322141 // Update the site of the SiteInstance if it doesn't have one yet.
2142 if (!GetSiteInstance()->has_site())
2143 GetSiteInstance()->SetSite(params.url);
2144
2145 // Need to update MIME type here because it's referred to in
2146 // UpdateNavigationCommands() called by RendererDidNavigate() to
2147 // determine whether or not to enable the encoding menu.
2148 // It's updated only for the main frame. For a subframe,
2149 // RenderView::UpdateURL does not set params.contents_mime_type.
2150 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2151 // TODO(jungshik): Add a test for the encoding menu to avoid
2152 // regressing it again.
2153 if (PageTransition::IsMainFrame(params.transition))
2154 contents_mime_type_ = params.contents_mime_type;
2155
2156 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372157 bool did_navigate = controller_.RendererDidNavigate(
2158 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392159
[email protected]a9c0bfe2010-09-17 08:35:222160 // Send notification about committed provisional loads. This notification is
2161 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2162 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2163 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072164 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2165 // that is not recorded in the navigation history. For the purpose of
2166 // tracking navigation events, we treat this event as a sub frame navigation
2167 // event.
2168 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2169 ProvisionalLoadDetails load_details(
2170 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412171 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222172 load_details.set_transition_type(params.transition);
2173 // Whether or not a page transition was triggered by going backward or
2174 // forward in the history is only stored in the navigation controller's
2175 // entry list.
2176 if (did_navigate &&
2177 (controller_.GetActiveEntry()->transition_type() &
2178 PageTransition::FORWARD_BACK)) {
2179 load_details.set_transition_type(
2180 params.transition | PageTransition::FORWARD_BACK);
2181 }
2182 NotificationService::current()->Notify(
2183 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2184 Source<NavigationController>(&controller_),
2185 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222186 }
2187
[email protected]3e90d4a2009-07-03 17:38:392188 // Update history. Note that this needs to happen after the entry is complete,
2189 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582190 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392191 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582192 // URLs, we use a data: URL as the real value. We actually want to save the
2193 // about: URL to the history db and keep the data: URL hidden. This is what
2194 // the TabContents' URL getter does.
2195 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2196 CreateHistoryAddPageArgs(GetURL(), details, params));
2197 if (!delegate() ||
2198 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2199 details.type)) {
2200 UpdateHistoryForNavigation(add_page_args);
2201 }
[email protected]3e90d4a2009-07-03 17:38:392202 }
2203
[email protected]76543b92009-08-31 17:27:452204 if (!did_navigate)
2205 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322206
2207 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2208 // for the appropriate notification (best) or you can add it to
2209 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2210 // necessary, please).
2211
2212 // Run post-commit tasks.
2213 if (details.is_main_frame)
2214 DidNavigateMainFramePostCommit(details, params);
2215 DidNavigateAnyFramePostCommit(rvh, details, params);
2216}
2217
2218void TabContents::UpdateState(RenderViewHost* rvh,
2219 int32 page_id,
2220 const std::string& state) {
2221 DCHECK(rvh == render_view_host());
2222
2223 // We must be prepared to handle state updates for any page, these occur
2224 // when the user is scrolling and entering form data, as well as when we're
2225 // leaving a page, in which case our state may have already been moved to
2226 // the next page. The navigation controller will look up the appropriate
2227 // NavigationEntry and update it when it is notified via the delegate.
2228
2229 int entry_index = controller_.GetEntryIndexWithPageID(
2230 GetSiteInstance(), page_id);
2231 if (entry_index < 0)
2232 return;
2233 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2234
2235 if (state == entry->content_state())
2236 return; // Nothing to update.
2237 entry->set_content_state(state);
2238 controller_.NotifyEntryChanged(entry, entry_index);
2239}
2240
2241void TabContents::UpdateTitle(RenderViewHost* rvh,
2242 int32 page_id, const std::wstring& title) {
2243 // If we have a title, that's a pretty good indication that we've started
2244 // getting useful data.
2245 SetNotWaitingForResponse();
2246
2247 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482248 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582249 page_id);
[email protected]420ae012009-04-24 05:16:322250 if (!entry || !UpdateTitleForEntry(entry, title))
2251 return;
2252
2253 // Broadcast notifications when the UI should be updated.
2254 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032255 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322256}
2257
[email protected]420ae012009-04-24 05:16:322258void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402259 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322260 set_encoding(encoding);
2261}
2262
2263void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2264 if (delegate())
2265 delegate()->UpdateTargetURL(this, url);
2266}
2267
2268void TabContents::UpdateThumbnail(const GURL& url,
2269 const SkBitmap& bitmap,
2270 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442271 if (profile()->IsOffTheRecord())
2272 return;
2273
[email protected]420ae012009-04-24 05:16:322274 // Tell History about this thumbnail
[email protected]54097492f2011-01-18 08:32:072275 history::TopSites* ts = profile()->GetTopSites();
2276 if (ts)
2277 ts->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322278}
2279
[email protected]c4e98902010-06-01 10:20:142280void TabContents::UpdateInspectorSetting(const std::string& key,
2281 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052282 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082283}
2284
[email protected]45aafc92010-06-07 14:18:532285void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052286 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532287}
2288
[email protected]420ae012009-04-24 05:16:322289void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292290 // The UI may be in an event-tracking loop, such as between the
2291 // mouse-down and mouse-up in text selection or a button click.
2292 // Defer the close until after tracking is complete, so that we
2293 // don't free objects out from under the UI.
2294 // TODO(shess): This could probably be integrated with the
2295 // IsDoingDrag() test below. Punting for now because I need more
2296 // research to understand how this impacts platforms other than Mac.
2297 // TODO(shess): This could get more fine-grained. For instance,
2298 // closing a tab in another window while selecting text in the
2299 // current window's Omnibox should be just fine.
2300 if (view()->IsEventTracking()) {
2301 view()->CloseTabAfterEventTracking();
2302 return;
2303 }
2304
[email protected]24a4d1062009-07-10 23:10:422305 // If we close the tab while we're in the middle of a drag, we'll crash.
2306 // Instead, cancel the drag and close it as soon as the drag ends.
2307 if (view()->IsDoingDrag()) {
2308 view()->CancelDragAndCloseTab();
2309 return;
2310 }
2311
[email protected]420ae012009-04-24 05:16:322312 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2313 if (delegate() && rvh == render_view_host())
2314 delegate()->CloseContents(this);
2315}
2316
2317void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2318 if (delegate() && delegate()->IsPopup(this))
2319 delegate()->MoveContents(this, new_bounds);
2320}
2321
[email protected]7ab1e7d62009-10-14 23:32:012322void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322323 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492324
[email protected]de4761b2010-12-07 21:05:212325 if (delegate()) {
2326 bool is_print_preview_tab =
2327 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2328 if (content_restrictions_ || is_print_preview_tab) {
2329 content_restrictions_= is_print_preview_tab ?
2330 CONTENT_RESTRICTION_PRINT : 0;
2331 delegate()->ContentRestrictionsChanged(this);
2332 }
[email protected]9e823662010-10-13 23:36:002333 }
[email protected]3c9e1872010-11-18 16:17:492334
2335 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172336 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322337}
2338
[email protected]7ab1e7d62009-10-14 23:32:012339void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322340 scoped_ptr<LoadNotificationDetails> details;
2341
2342 NavigationEntry* entry = controller_.GetActiveEntry();
2343 // An entry may not exist for a stop when loading an initial blank page or
2344 // if an iframe injected by script into a blank page finishes loading.
2345 if (entry) {
[email protected]420ae012009-04-24 05:16:322346 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2347
2348 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542349 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322350 entry->transition_type(),
2351 elapsed,
2352 &controller_,
2353 controller_.GetCurrentEntryIndex()));
2354 }
2355
[email protected]420ae012009-04-24 05:16:322356 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492357
2358 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172359 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322360}
2361
[email protected]1a3c3cb2010-12-16 21:03:402362void TabContents::DidChangeLoadProgress(double progress) {
2363 if (delegate())
2364 delegate()->LoadProgressChanged(progress);
2365}
2366
[email protected]25497492010-09-11 15:15:082367void TabContents::DocumentOnLoadCompletedInMainFrame(
2368 RenderViewHost* render_view_host,
2369 int32 page_id) {
2370 NotificationService::current()->Notify(
2371 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2372 Source<TabContents>(this),
2373 Details<int>(&page_id));
2374}
2375
[email protected]420ae012009-04-24 05:16:322376void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2377 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:582378 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352379 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322380 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2381 // generated suggestions).
2382 //
[email protected]e0112912011-02-02 22:54:352383 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162384 // want web sites to see a referrer of "chrome://blah" (and some
2385 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322386 // send to the site), so we send no referrer.
2387 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:582388 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:322389 } else {
2390 OpenURL(url, referrer, disposition, PageTransition::LINK);
2391 }
2392}
2393
[email protected]1ee614862009-07-06 20:29:182394void TabContents::DomOperationResponse(const std::string& json_string,
2395 int automation_id) {
2396}
2397
[email protected]badcca352011-02-12 01:08:082398void TabContents::ProcessWebUIMessage(
[email protected]8b8e7c92010-08-19 18:05:562399 const ViewHostMsg_DomMessage_Params& params) {
[email protected]7ade2732011-02-10 00:13:582400 if (!render_manager_.web_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442401 // This can happen if someone uses window.open() to open an extension URL
2402 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562403 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322404 return;
2405 }
[email protected]badcca352011-02-12 01:08:082406 render_manager_.web_ui()->ProcessWebUIMessage(params);
[email protected]420ae012009-04-24 05:16:322407}
2408
2409void TabContents::ProcessExternalHostMessage(const std::string& message,
2410 const std::string& origin,
2411 const std::string& target) {
2412 if (delegate())
2413 delegate()->ForwardMessageToExternalHost(message, origin, target);
2414}
2415
[email protected]420ae012009-04-24 05:16:322416void TabContents::RunJavaScriptMessage(
2417 const std::wstring& message,
2418 const std::wstring& default_prompt,
2419 const GURL& frame_url,
2420 const int flags,
2421 IPC::Message* reply_msg,
2422 bool* did_suppress_message) {
2423 // Suppress javascript messages when requested and when inside a constrained
2424 // popup window (because that activates them and breaks them out of the
2425 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552426 // Also suppress messages when showing an interstitial. The interstitial is
2427 // shown over the previous page, we don't want the hidden page dialogs to
2428 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502429 bool suppress_this_message =
2430 suppress_javascript_messages_ ||
2431 showing_interstitial_page() ||
2432 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322433 if (delegate())
2434 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312435 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322436
2437 *did_suppress_message = suppress_this_message;
2438
2439 if (!suppress_this_message) {
2440 base::TimeDelta time_since_last_message(
2441 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2442 bool show_suppress_checkbox = false;
2443 // Show a checkbox offering to suppress further messages if this message is
2444 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2445 if (time_since_last_message <
2446 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2447 show_suppress_checkbox = true;
2448
[email protected]d6ad7442010-09-05 19:06:522449 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2450 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322451 } else {
2452 // If we are suppressing messages, just reply as is if the user immediately
2453 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542454 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322455 }
2456}
2457
2458void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2459 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292460 if (delegate())
2461 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502462 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2463 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2464 std::wstring());
2465 return;
2466 }
[email protected]7ab1e7d62009-10-14 23:32:012467 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222468 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322469}
2470
2471void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2472 const std::string& json_arguments,
2473 IPC::Message* reply_msg) {
2474 if (delegate()) {
2475 HtmlDialogUIDelegate* dialog_delegate =
2476 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222477 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322478 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2479 }
2480}
2481
[email protected]420ae012009-04-24 05:16:322482GURL TabContents::GetAlternateErrorPageURL() const {
2483 GURL url;
2484 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2485 if (profile()->IsOffTheRecord())
2486 return url;
2487
2488 PrefService* prefs = profile()->GetPrefs();
2489 DCHECK(prefs);
2490 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152491 url = google_util::AppendGoogleLocaleParam(
2492 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322493 url = google_util::AppendGoogleTLDParam(url);
2494 }
2495 return url;
2496}
2497
2498WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062499 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:582500 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:082501 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:582502 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:082503
[email protected]9beff752010-09-22 19:35:432504 // Force accelerated compositing and 2d canvas off for chrome: and
2505 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432506 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2507 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082508 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432509 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082510 }
2511
[email protected]39553442010-09-09 00:01:552512#if defined(OS_MACOSX)
2513 // Disable accelerated compositing if IOSurface's are not supported,
2514 // as is the case in 10.5.
2515 if (!IOSurfaceSupport::Initialize())
2516 web_prefs.accelerated_compositing_enabled = false;
2517#endif
2518
[email protected]447021c2010-09-08 21:29:082519 return web_prefs;
[email protected]420ae012009-04-24 05:16:322520}
2521
[email protected]7d472472011-01-22 01:30:252522void TabContents::OnUserGesture() {
2523 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
2524 DownloadRequestLimiter* limiter =
2525 g_browser_process->download_request_limiter();
2526 if (limiter)
2527 limiter->OnUserGesture(this);
2528 ExternalProtocolHandler::PermitLaunchUrl();
2529}
2530
[email protected]fa1cf0b82010-01-15 21:49:442531void TabContents::OnIgnoredUIEvent() {
2532 if (constrained_window_count()) {
2533 ConstrainedWindow* window = *constrained_window_begin();
2534 window->FocusConstrainedWindow();
2535 }
2536}
2537
[email protected]420ae012009-04-24 05:16:322538void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2539 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342540 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322541 // delivered to a pending RenderViewHost. We must first run the onunload
2542 // handler of the old RenderViewHost before we can allow it to proceed.
2543 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2544 new_request_id);
2545}
2546
[email protected]420ae012009-04-24 05:16:322547void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2548 bool is_during_unload) {
2549 if (is_during_unload) {
2550 // Hang occurred while firing the beforeunload/unload handler.
2551 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112552 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322553
2554 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2555 return;
2556
2557 // If the tab hangs in the beforeunload/unload handler there's really
2558 // nothing we can do to recover. Pretend the unload listeners have
2559 // all fired and close the tab. If the hang is in the beforeunload handler
2560 // then the user will not have the option of cancelling the close.
2561 Close(rvh);
2562 return;
2563 }
2564
[email protected]61b50092011-02-03 18:02:192565 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
2566 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]e7b8d832009-11-20 22:41:002567 hung_renderer_dialog::ShowForTabContents(this);
[email protected]61b50092011-02-03 18:02:192568 }
[email protected]420ae012009-04-24 05:16:322569}
2570
2571void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002572 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322573}
2574
2575void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562576 net::LoadState load_state,
2577 uint64 upload_position,
2578 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322579 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562580 upload_position_ = upload_position;
2581 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292582 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192583 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292584 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:422585 load_state_host_ = WideToUTF16Hack(
2586 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:322587 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2588 SetNotWaitingForResponse();
2589 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502590 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322591}
2592
[email protected]1ee614862009-07-06 20:29:182593bool TabContents::IsExternalTabContainer() const {
2594 if (!delegate())
2595 return false;
2596
2597 return delegate()->IsExternalTabContainer();
2598}
2599
[email protected]1ee614862009-07-06 20:29:182600void TabContents::DidInsertCSS() {
2601 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322602}
2603
[email protected]546ae4e02010-12-08 14:57:192604void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:352605 NotificationService::current()->Notify(
2606 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:212607 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:192608 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:352609}
2610
[email protected]b75b8292010-10-01 07:28:252611void TabContents::UpdateZoomLimits(int minimum_percent,
2612 int maximum_percent,
2613 bool remember) {
2614 minimum_zoom_percent_ = minimum_percent;
2615 maximum_zoom_percent_ = maximum_percent;
2616 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382617}
2618
[email protected]7d472472011-01-22 01:30:252619void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:442620 if (delegate())
2621 delegate()->WorkerCrashed();
[email protected]7d472472011-01-22 01:30:252622}
2623
[email protected]420ae012009-04-24 05:16:322624void TabContents::BeforeUnloadFiredFromRenderManager(
2625 bool proceed,
2626 bool* proceed_to_fire_unload) {
2627 if (delegate())
2628 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2629}
2630
[email protected]3a3d47472010-07-15 21:03:542631void TabContents::DidStartLoadingFromRenderManager(
2632 RenderViewHost* render_view_host) {
2633 DidStartLoading();
2634}
2635
2636void TabContents::RenderViewGoneFromRenderManager(
2637 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232638 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2639 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542640}
2641
[email protected]420ae012009-04-24 05:16:322642void TabContents::UpdateRenderViewSizeForRenderManager() {
2643 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262644 gfx::Size size = view_->GetContainerSize();
2645 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2646 // here during container initialization and normal window size will be set
2647 // later. In case of tab duplication this resizing to 0x0 prevents setting
2648 // normal size later so just ignore it.
2649 if (!size.IsEmpty())
2650 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322651}
2652
[email protected]3a3d47472010-07-15 21:03:542653void TabContents::NotifySwappedFromRenderManager() {
2654 NotifySwapped();
2655}
2656
2657NavigationController& TabContents::GetControllerForRenderManager() {
2658 return controller();
2659}
2660
[email protected]d0980792011-02-13 19:41:402661WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]80a8fad2011-01-29 04:02:382662 return WebUIFactory::CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322663}
2664
2665NavigationEntry*
2666TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2667 return controller_.GetLastCommittedEntry();
2668}
2669
2670bool TabContents::CreateRenderViewForRenderManager(
2671 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322672 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522673
[email protected]674b3822010-08-04 04:02:512674 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322675 return false;
2676
2677 // Now that the RenderView has been created, we need to tell it its size.
2678 rwh_view->SetSize(view_->GetContainerSize());
2679
2680 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2681 render_view_host);
2682 return true;
2683}
2684
2685void TabContents::Observe(NotificationType type,
2686 const NotificationSource& source,
2687 const NotificationDetails& details) {
2688 switch (type.value) {
[email protected]420ae012009-04-24 05:16:322689 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512690 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322691 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2692 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2693 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:532694 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
2695 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:322696 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:172697 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
2698 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:322699 } else {
2700 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2701 }
2702 break;
2703 }
2704 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2705 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2706 break;
2707
2708 case NotificationType::NAV_ENTRY_COMMITTED: {
2709 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2710
2711 NavigationController::LoadCommittedDetails& committed_details =
2712 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2713 ExpireInfoBars(committed_details);
2714 break;
2715 }
2716
[email protected]d3ba77272009-09-03 00:06:092717#if defined(OS_LINUX)
2718 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542719 renderer_preferences_util::UpdateFromSystemSettings(
2720 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092721 render_view_host()->SyncRendererPrefs();
2722 break;
2723 }
2724#endif
2725
[email protected]6c32ce72010-03-08 05:18:062726 case NotificationType::USER_STYLE_SHEET_UPDATED:
2727 UpdateWebPreferences();
2728 break;
2729
[email protected]79580c62010-02-02 02:36:252730 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:452731 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:252732 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492733 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292734 if (entry)
[email protected]da0c8e92010-02-09 23:25:492735 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292736 if (settings_details.ptr()->update_all() ||
2737 settings_details.ptr()->pattern().Matches(entry_url)) {
2738 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232739 profile()->GetHostContentSettingsMap()->
2740 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252741 }
2742 break;
2743 }
2744
[email protected]e5adff72010-06-14 18:13:062745 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:572746 break;
[email protected]a888b29e62010-04-01 13:38:572747
2748 case NotificationType::EXTENSION_UNLOADED:
[email protected]a888b29e62010-04-01 13:38:572749 break;
[email protected]a888b29e62010-04-01 13:38:572750
[email protected]88152052010-10-01 04:05:182751 case NotificationType::GOOGLE_URL_UPDATED:
2752 UpdateAlternateErrorPageURL();
2753 break;
2754
[email protected]420ae012009-04-24 05:16:322755 default:
2756 NOTREACHED();
2757 }
2758}
[email protected]aacd7cc2009-09-02 14:51:102759
[email protected]9adb9692010-10-29 23:14:022760void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:082761 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432762
[email protected]a888b29e62010-04-01 13:38:572763 if (extension) {
[email protected]98aa0b52010-05-06 17:03:082764 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
2765 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:572766 extension,
[email protected]807871f2010-09-16 01:04:482767 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
2768 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:572769 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
2770 Extension::EXTENSION_ICON_SMALLISH),
2771 ImageLoadingTracker::CACHE);
2772 } else {
[email protected]98aa0b52010-05-06 17:03:082773 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:572774 }
2775}
2776
[email protected]9adb9692010-10-29 23:14:022777const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:002778 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:572779 if (!extensions_service)
2780 return NULL;
2781
[email protected]9adb9692010-10-29 23:14:022782 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:572783 return extension ?
2784 extension : extensions_service->GetExtensionByWebExtent(url);
2785}
2786
[email protected]a888b29e62010-04-01 13:38:572787void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
2788 int index) {
2789 if (image) {
[email protected]98aa0b52010-05-06 17:03:082790 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:572791 NotifyNavigationStateChanged(INVALIDATE_TAB);
2792 }
2793}
2794
[email protected]beb440c2009-11-06 04:08:542795gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2796 return view_->GetTopLevelNativeWindow();
2797}
2798
2799void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2800 bool success,
2801 const std::wstring& prompt) {
2802 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2803 if (is_showing_before_unload_dialog_ && !success) {
2804 // If a beforeunload dialog is canceled, we need to stop the throbber from
2805 // spinning, since we forced it to start spinning in Navigate.
2806 DidStopLoading();
2807
2808 tab_close_start_time_ = base::TimeTicks();
2809 }
2810 is_showing_before_unload_dialog_ = false;
2811 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2812}
2813
2814void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2815 set_suppress_javascript_messages(suppress_message_boxes);
2816}
2817
[email protected]3a3d47472010-07-15 21:03:542818TabContents* TabContents::AsTabContents() {
2819 return this;
2820}
2821
2822ExtensionHost* TabContents::AsExtensionHost() {
2823 return NULL;
2824}
2825
[email protected]41fc0322009-09-04 22:23:402826void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102827 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2828}
[email protected]f45d2a72010-03-08 23:28:352829
2830void TabContents::SetAppIcon(const SkBitmap& app_icon) {
2831 app_icon_ = app_icon;
2832 NotifyNavigationStateChanged(INVALIDATE_TITLE);
2833}
[email protected]33f74972010-12-08 16:40:362834
2835void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2836 render_manager_.SwapInRenderViewHost(rvh);
2837}
2838
2839void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2840 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2841 rwh_view->SetSize(view()->GetContainerSize());
2842}
[email protected]e7d50892011-01-19 21:47:382843
2844bool TabContents::MaybeUsePreloadedPage(const GURL& url) {
[email protected]4c154ff82011-02-15 11:23:592845 prerender::PrerenderManager* pm = profile()->GetPrerenderManager();
[email protected]e7d50892011-01-19 21:47:382846 if (pm != NULL) {
[email protected]973407b2011-01-26 23:18:232847 if (pm->MaybeUsePreloadedPage(this, url))
[email protected]e7d50892011-01-19 21:47:382848 return true;
[email protected]e7d50892011-01-19 21:47:382849 }
2850 return false;
2851}