blob: 04034c48599c6f1e3a23a409a5b8188c0fbe227e [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]5f24f212010-12-02 14:47:4522#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3323#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5424#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1425#include "chrome/browser/defaults.h"
[email protected]74da5bd2011-01-27 22:03:2726#include "chrome/browser/desktop_notification_handler.h"
[email protected]420ae012009-04-24 05:16:3227#include "chrome/browser/dom_operation_notification_details.h"
[email protected]bcef0dc02009-02-28 00:35:0228#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3229#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0130#include "chrome/browser/download/download_request_limiter.h"
[email protected]eaa7dd182010-12-14 11:09:0031#include "chrome/browser/extensions/extension_service.h"
[email protected]3c733bde2010-12-21 19:56:3132#include "chrome/browser/external_protocol_handler.h"
33#include "chrome/browser/favicon_service.h"
[email protected]3c733bde2010-12-21 19:56:3134#include "chrome/browser/google/google_util.h"
[email protected]ef0d04c2010-12-15 23:34:2135#include "chrome/browser/history/history.h"
[email protected]ec0b6c42010-08-26 03:16:5836#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4237#include "chrome/browser/history/top_sites.h"
[email protected]420ae012009-04-24 05:16:3238#include "chrome/browser/load_from_memory_cache_details.h"
39#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4440#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]724159a2010-12-30 01:11:1841#include "chrome/browser/metrics/user_metrics.h"
[email protected]c8865482009-07-23 20:40:1042#include "chrome/browser/omnibox_search_hint.h"
[email protected]c8f73ab2011-01-22 00:05:1743#include "chrome/browser/pdf_unsupported_feature.h"
[email protected]14a000d2010-04-29 21:44:2444#include "chrome/browser/platform_util.h"
[email protected]67c052e2011-01-31 16:33:5845#include "chrome/browser/plugin_observer.h"
[email protected]dbeebd52010-11-16 20:34:1646#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0947#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3348#include "chrome/browser/profiles/profile.h"
[email protected]96d185d2009-04-24 03:28:5449#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3250#include "chrome/browser/renderer_preferences_util.h"
[email protected]fa685ff2011-02-17 19:47:1351#include "chrome/browser/safe_browsing/client_side_detection_host.h"
[email protected]c37e3b62010-01-22 00:15:1752#include "chrome/browser/sessions/session_types.h"
[email protected]a40f6e92011-03-04 23:30:2953#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4954#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]d54169e92011-01-21 09:19:5255#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1656#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3557#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]7ec6bef2011-02-26 02:22:2958#include "chrome/browser/ui/browser_dialogs.h"
[email protected]54ec6472010-04-09 19:39:5859#include "chrome/common/bindings_policy.h"
[email protected]1698f612011-03-11 11:28:1560#include "chrome/common/chrome_constants.h"
[email protected]35f7d212009-04-29 21:19:2761#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2162#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4963#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5764#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4865#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1466#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0967#include "chrome/common/extensions/url_pattern.h"
[email protected]12802702010-07-09 19:43:0968#include "chrome/common/net/url_request_context_getter.h"
initial.commit09911bf2008-07-26 23:55:2969#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3270#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0271#include "chrome/common/render_messages_params.h"
[email protected]96d185d2009-04-24 03:28:5472#include "chrome/common/url_constants.h"
[email protected]567812d2011-02-24 17:40:5073#include "content/browser/child_process_security_policy.h"
74#include "content/browser/host_zoom_map.h"
75#include "content/browser/in_process_webkit/session_storage_namespace.h"
76#include "content/browser/renderer_host/render_process_host.h"
77#include "content/browser/renderer_host/render_view_host.h"
78#include "content/browser/renderer_host/render_widget_host_view.h"
79#include "content/browser/renderer_host/resource_request_details.h"
80#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4481#include "content/browser/tab_contents/interstitial_page.h"
82#include "content/browser/tab_contents/navigation_entry.h"
83#include "content/browser/tab_contents/provisional_load_details.h"
84#include "content/browser/tab_contents/tab_contents_delegate.h"
85#include "content/browser/tab_contents/tab_contents_observer.h"
86#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]67fc0392011-02-25 02:56:5787#include "content/browser/webui/web_ui.h"
[email protected]4dd57932011-03-17 06:06:1288#include "content/common/navigation_types.h"
[email protected]7f070d42011-03-09 20:25:3289#include "content/common/notification_service.h"
[email protected]2c5569662011-03-22 20:45:0290#include "content/common/view_messages.h"
[email protected]d686e812009-06-03 19:10:2991#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3292#include "net/base/registry_controlled_domain.h"
[email protected]8bd0fe62011-01-17 06:44:3793#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]42ce29d2011-01-20 23:19:4694#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:3895#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0396#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:3197#include "webkit/glue/webpreferences.h"
98
99#if defined(OS_MACOSX)
100#include "app/surface/io_surface_support_mac.h"
101#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:00102
[email protected]420ae012009-04-24 05:16:32103// Cross-Site Navigations
104//
105// If a TabContents is told to navigate to a different web site (as determined
106// by SiteInstance), it will replace its current RenderViewHost with a new
107// RenderViewHost dedicated to the new SiteInstance. This works as follows:
108//
109// - Navigate determines whether the destination is cross-site, and if so,
110// it creates a pending_render_view_host_ and moves into the PENDING
111// RendererState.
112// - The pending RVH is "suspended," so that no navigation messages are sent to
113// its renderer until the onbeforeunload JavaScript handler has a chance to
114// run in the current RVH.
115// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
116// that it has a pending cross-site request. ResourceDispatcherHost will
117// check for this when the response arrives.
118// - The current RVH runs its onbeforeunload handler. If it returns false, we
119// cancel all the pending logic and go back to NORMAL. Otherwise we allow
120// the pending RVH to send the navigation request to its renderer.
121// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
122// checks CrossSiteRequestManager to see that the RVH responsible has a
123// pending cross-site request, and then installs a CrossSiteEventHandler.
124// - When RDH receives a response, the BufferedEventHandler determines whether
125// it is a download. If so, it sends a message to the new renderer causing
126// it to cancel the request, and the download proceeds in the download
127// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34128// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32129// doesn't affect any functionality.
130// - After RDH receives a response and determines that it is safe and not a
131// download, it pauses the response to first run the old page's onunload
132// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34133// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32134// to the current RVH.
135// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
136// the ResourceDispatcherHost, who unpauses the response. Data is then sent
137// to the pending RVH.
138// - The pending renderer sends a FrameNavigate message that invokes the
139// DidNavigate method. This replaces the current RVH with the
140// pending RVH and goes back to the NORMAL RendererState.
141
142namespace {
143
144// Amount of time we wait between when a key event is received and the renderer
145// is queried for its state and pushed to the NavigationEntry.
146const int kQueryStateDelay = 5000;
147
[email protected]6ebdc9b2010-09-27 16:55:57148const int kSyncWaitDelay = 40;
149
[email protected]420ae012009-04-24 05:16:32150// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51151const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32152 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17153 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32154 prefs::kWebKitJavaEnabled,
155 prefs::kWebKitJavascriptEnabled,
156 prefs::kWebKitLoadsImagesAutomatically,
157 prefs::kWebKitPluginsEnabled,
158 prefs::kWebKitUsesUniversalDetector,
[email protected]16480f62011-03-01 23:39:10159 prefs::kWebKitStandardFontFamily,
[email protected]420ae012009-04-24 05:16:32160 prefs::kWebKitSerifFontFamily,
161 prefs::kWebKitSansSerifFontFamily,
162 prefs::kWebKitFixedFontFamily,
163 prefs::kWebKitDefaultFontSize,
164 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13165 prefs::kWebKitMinimumFontSize,
166 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36167 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32168 prefs::kDefaultCharset
[email protected]420ae012009-04-24 05:16:32169};
170
171const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
172
[email protected]420ae012009-04-24 05:16:32173#if defined(OS_WIN)
174
175BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
176 // Note: erase is required to properly paint some widgets borders. This can
177 // be seen with textfields.
178 InvalidateRect(hwnd, NULL, TRUE);
179 return TRUE;
180}
181#endif
182
[email protected]2c5569662011-03-22 20:45:02183ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16184 Profile* profile, const NavigationEntry& entry,
185 NavigationController::ReloadType reload_type) {
186 switch (reload_type) {
187 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02188 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16189 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02190 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16191 case NavigationController::NO_RELOAD:
192 break; // Fall through to rest of function.
193 }
[email protected]5e369672009-11-03 23:48:30194
195 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
196 profile->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02197 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30198
[email protected]2c5569662011-03-22 20:45:02199 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30200}
201
[email protected]876bc832010-09-07 16:29:54202void MakeNavigateParams(const NavigationEntry& entry,
203 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16204 NavigationController::ReloadType reload_type,
205 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34206 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54207 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00208 params->current_history_list_offset = controller.last_committed_entry_index();
209 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34210 params->url = entry.url();
211 params->referrer = entry.referrer();
212 params->transition = entry.transition_type();
213 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00214 params->navigation_type =
215 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34216 params->request_time = base::Time::Now();
217}
218
[email protected]420ae012009-04-24 05:16:32219} // namespace
220
[email protected]f4f50ef2011-01-21 19:01:19221
222// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32223
[email protected]420ae012009-04-24 05:16:32224TabContents::TabContents(Profile* profile,
225 SiteInstance* site_instance,
226 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07227 const TabContents* base_tab_contents,
228 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42229 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07230 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
231 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13232 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22233 TabContentsView::Create(this))),
234 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06235 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34236 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23237 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
238 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34239 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34240 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57241 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56242 upload_size_(0),
243 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57244 received_page_title_(false),
[email protected]c65e2f152010-10-14 15:30:40245 blocked_contents_(NULL),
246 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49247 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47248 displayed_insecure_content_(false),
[email protected]98aa0b52010-05-06 17:03:08249 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57250 capturing_contents_(false),
251 is_being_destroyed_(false),
252 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57253#if defined(OS_WIN)
254 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
255#endif
[email protected]c2e74fe82009-09-03 17:57:44256 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01257 is_showing_before_unload_dialog_(false),
[email protected]80a8fad2011-01-29 04:02:38258 opener_web_ui_type_(WebUIFactory::kNoWebUI),
[email protected]777a7b62010-05-11 13:28:16259 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38260 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25261 minimum_zoom_percent_(
262 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
263 maximum_zoom_percent_(
264 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00265 temporary_zoom_settings_(false),
[email protected]4850a7f2011-03-08 23:36:59266 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54267 renderer_preferences_util::UpdateFromSystemSettings(
268 &renderer_preferences_, profile);
269
[email protected]9fb83e82010-07-02 18:24:55270 content_settings_delegate_.reset(
271 new TabSpecificContentSettings(this, profile));
272
[email protected]12636df2009-09-28 22:32:21273 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32274
[email protected]34ac70502009-09-25 17:07:23275 // We have the initial size of the view be based on the size of the passed in
276 // tab contents (normally a tab from the same window).
277 view_->CreateView(base_tab_contents ?
278 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32279
280 // Register for notifications about all interested prefs change.
281 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28282 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32283 if (prefs) {
284 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28285 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32286 }
287
[email protected]420ae012009-04-24 05:16:32288 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
289 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09290#if defined(OS_LINUX)
291 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
292 NotificationService::AllSources());
293#endif
[email protected]420ae012009-04-24 05:16:32294
[email protected]6c32ce72010-03-08 05:18:06295 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
296 NotificationService::AllSources());
297
[email protected]79580c62010-02-02 02:36:25298 // Register for notifications about content setting changes.
299 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
300 NotificationService::AllSources());
301
[email protected]a888b29e62010-04-01 13:38:57302 // Listen for extension changes so we can update extension_for_current_page_.
303 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
304 NotificationService::AllSources());
305 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
306 NotificationService::AllSources());
[email protected]a888b29e62010-04-01 13:38:57307
[email protected]969182a2011-03-03 14:53:23308 // Listen for Google URL changes.
[email protected]88152052010-10-01 04:05:18309 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
310 NotificationService::AllSources());
311
[email protected]c8865482009-07-23 20:40:10312 // Set-up the showing of the omnibox search infobar if applicable.
313 if (OmniboxSearchHint::IsEnabled(profile))
314 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53315
[email protected]b5a1d11c2011-02-17 03:09:42316 // Can only add observers after render_manager_.Init() is called, since that's
317 // what sets up the render_view_host which TabContentObserver's constructor
318 // uses to get the routing_id.
319 AddObservers();
[email protected]332af7732009-03-11 13:21:35320}
initial.commit09911bf2008-07-26 23:55:29321
322TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32323 is_being_destroyed_ = true;
324
[email protected]bfe4c1582009-10-02 18:11:09325 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32326 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28327 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32328
[email protected]420ae012009-04-24 05:16:32329 NotifyDisconnected();
[email protected]7ec6bef2011-02-26 02:22:29330 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:32331
[email protected]420ae012009-04-24 05:16:32332 // First cleanly close all child windows.
333 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
334 // some of these to close. CloseWindows is async, so it might get called
335 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49336 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32337
[email protected]c65e2f152010-10-14 15:30:40338 // Close all blocked contents.
339 if (blocked_contents_)
340 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13341
[email protected]420ae012009-04-24 05:16:32342 // Notify any observer that have a reference on this tab contents.
343 NotificationService::current()->Notify(
344 NotificationType::TAB_CONTENTS_DESTROYED,
345 Source<TabContents>(this),
346 NotificationService::NoDetails());
347
[email protected]1e5e74f2009-05-27 20:55:12348 // Notify any lasting InfobarDelegates that have not yet been removed that
349 // whatever infobar they were handling in this TabContents has closed,
350 // because the TabContents is going away entirely.
351 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
352 // notification may trigger infobars calls that access their delegate. (and
353 // some implementations of InfoBarDelegate do delete themselves on
354 // InfoBarClosed()).
[email protected]ec8f51162011-02-08 04:20:40355 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]1e5e74f2009-05-27 20:55:12356 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
357 delegate->InfoBarClosed();
358 }
359 infobar_delegates_.clear();
360
[email protected]420ae012009-04-24 05:16:32361 // TODO(brettw) this should be moved to the view.
362#if defined(OS_WIN)
363 // If we still have a window handle, destroy it. GetNativeView can return
364 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42365 if (GetNativeView()) {
366 RenderViewHost* host = render_view_host();
367 if (host && host->view()) {
368 host->view()->WillWmDestroy();
369 }
[email protected]420ae012009-04-24 05:16:32370 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42371 }
[email protected]420ae012009-04-24 05:16:32372#endif
[email protected]7ab1e7d62009-10-14 23:32:01373
374 // OnCloseStarted isn't called in unit tests.
375 if (!tab_close_start_time_.is_null()) {
376 UMA_HISTOGRAM_TIMES("Tab.Close",
377 base::TimeTicks::Now() - tab_close_start_time_);
378 }
[email protected]b5a1d11c2011-02-17 03:09:42379
[email protected]07d490bc2011-03-07 17:05:26380 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08381
382 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
[email protected]b5a1d11c2011-02-17 03:09:42383}
384
385void TabContents::AddObservers() {
386 printing_.reset(new printing::PrintViewManager(this));
[email protected]16be5c32011-03-15 17:52:03387 favicon_helper_.reset(new FaviconHelper(this));
[email protected]c4a9e932011-03-05 04:05:55388 autofill_manager_.reset(new AutofillManager(this));
[email protected]b5a1d11c2011-02-17 03:09:42389 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
[email protected]b5a1d11c2011-02-17 03:09:42390 desktop_notification_handler_.reset(
391 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
392 plugin_observer_.reset(new PluginObserver(this));
[email protected]fa685ff2011-02-17 19:47:13393 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost(
394 this));
[email protected]232a5812011-03-04 22:42:08395 net::NetworkChangeNotifier::AddOnlineStateObserver(this);
initial.commit09911bf2008-07-26 23:55:29396}
397
[email protected]724159a2010-12-30 01:11:18398bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]585b30362011-01-28 02:30:17399 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
400 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10401 while ((observer = it.GetNext()) != NULL)
402 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53403 return true;
[email protected]403415a2011-01-10 18:57:53404
[email protected]724159a2010-12-30 01:11:18405 bool handled = true;
406 bool message_is_ok = true;
407 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
408 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
409 OnDidStartProvisionalLoadForFrame)
410 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
411 OnDidRedirectProvisionalLoad)
412 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
413 OnDidFailProvisionalLoadWithError)
414 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
415 OnDidLoadResourceFromMemoryCache)
416 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
417 OnDidDisplayInsecureContent)
418 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
419 OnDidRunInsecureContent)
420 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
421 OnDocumentLoadedInFrame)
422 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17423 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
424 OnUpdateContentRestrictions)
425 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
426 OnPDFHasUnsupportedFeature)
[email protected]7d472472011-01-22 01:30:25427 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]7d472472011-01-22 01:30:25428 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo,
429 OnDidGetApplicationInfo)
430 IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication,
431 OnInstallApplication)
432 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
433 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated)
434 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions)
435 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined,
436 OnInstantSupportDetermined)
[email protected]724159a2010-12-30 01:11:18437 IPC_MESSAGE_UNHANDLED(handled = false)
438 IPC_END_MESSAGE_MAP_EX()
439
440 if (!message_is_ok) {
441 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
442 GetRenderProcessHost()->ReceivedBadMessage();
443 }
444
445 return handled;
446}
447
[email protected]13367f72009-07-08 16:39:02448// Returns true if contains content rendered by an extension.
449bool TabContents::HostsExtension() const {
450 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34451}
452
[email protected]1f18184a2010-07-21 19:34:49453TabContentsSSLHelper* TabContents::GetSSLHelper() {
454 if (ssl_helper_.get() == NULL)
455 ssl_helper_.reset(new TabContentsSSLHelper(this));
456 return ssl_helper_.get();
457}
458
[email protected]8cb5d5b2010-02-09 11:36:16459RenderProcessHost* TabContents::GetRenderProcessHost() const {
460 return render_manager_.current_host()->process();
461}
462
[email protected]9adb9692010-10-29 23:14:02463void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46464 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08465 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10466
[email protected]98aa0b52010-05-06 17:03:08467 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57468
[email protected]fca656c2010-02-10 20:30:10469 NotificationService::current()->Notify(
470 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
471 Source<TabContents>(this),
472 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49473}
474
[email protected]98aa0b52010-05-06 17:03:08475void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
476 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40477 return;
478
[email protected]eaa7dd182010-12-14 11:09:00479 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50480 if (!extension_service || !extension_service->is_ready())
481 return;
482
483 const Extension* extension =
484 extension_service->GetExtensionById(extension_app_id, false);
485 if (extension)
486 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40487}
488
[email protected]98aa0b52010-05-06 17:03:08489SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08490 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51491 return NULL;
492
[email protected]98aa0b52010-05-06 17:03:08493 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51494}
495
[email protected]d5f942ba2008-09-26 19:30:34496const GURL& TabContents::GetURL() const {
497 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57498 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54499 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34500}
501
[email protected]96d185d2009-04-24 03:28:54502const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55503 // Transient entries take precedence. They are used for interstitial pages
504 // that are shown on top of existing pages.
505 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23506 if (entry) {
507 return entry->GetTitleForDisplay(profile()->GetPrefs()->
508 GetString(prefs::kAcceptLanguages));
509 }
[email protected]7ade2732011-02-10 00:13:58510 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
511 render_manager_.pending_web_ui() : render_manager_.web_ui();
512 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54513 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55514 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54515 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35516 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58517 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54518 if (!title.empty())
519 return title;
520 }
521 }
522
523 // We use the title for the last committed entry rather than a pending
524 // navigation entry. For example, when the user types in a URL, we want to
525 // keep the old page's title until the new load has committed and we get a new
526 // title.
[email protected]96d185d2009-04-24 03:28:54527 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23528 if (entry) {
529 return entry->GetTitleForDisplay(profile()->GetPrefs()->
530 GetString(prefs::kAcceptLanguages));
531 }
[email protected]96d185d2009-04-24 03:28:54532 return EmptyString16();
533}
534
[email protected]d5f942ba2008-09-26 19:30:34535int32 TabContents::GetMaxPageID() {
536 if (GetSiteInstance())
537 return GetSiteInstance()->max_page_id();
538 else
539 return max_page_id_;
540}
541
542void TabContents::UpdateMaxPageID(int32 page_id) {
543 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34544 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34545 // testing.
546 if (GetSiteInstance())
547 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16548 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34549}
550
[email protected]96d185d2009-04-24 03:28:54551SiteInstance* TabContents::GetSiteInstance() const {
552 return render_manager_.current_host()->site_instance();
553}
554
[email protected]96d185d2009-04-24 03:28:54555bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15556 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54557 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15558 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01559 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54560 return true;
[email protected]8ab24cc2009-11-13 20:56:15561 }
[email protected]83e3895b2009-06-11 00:07:16562
[email protected]2b9a06402011-02-16 04:57:10563 // We always display the URL for non-WebUI URLs to prevent spoofing.
564 if (entry && !WebUIFactory::HasWebUIScheme(entry->url()))
565 return true;
566
[email protected]d0980792011-02-13 19:41:40567 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58568 if (web_ui)
569 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54570 return true;
571}
572
[email protected]9b488bda2011-03-15 14:42:27573SkBitmap TabContents::GetFavicon() const {
[email protected]d5f942ba2008-09-26 19:30:34574 // Like GetTitle(), we also want to use the favicon for the last committed
575 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57576 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47577 if (entry)
578 return entry->favicon().bitmap();
579
[email protected]ce3fa3c2009-04-20 19:55:57580 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34581 if (entry)
582 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34583 return SkBitmap();
584}
585
[email protected]d8e74e82011-03-15 19:38:48586bool TabContents::FaviconIsValid() const {
[email protected]0b303cc2009-09-28 22:35:15587 NavigationEntry* entry = controller_.GetTransientEntry();
588 if (entry)
589 return entry->favicon().is_valid();
590
591 entry = controller_.GetLastCommittedEntry();
592 if (entry)
593 return entry->favicon().is_valid();
594
595 return false;
596}
597
[email protected]d8e74e82011-03-15 19:38:48598bool TabContents::ShouldDisplayFavicon() {
[email protected]96d185d2009-04-24 03:28:54599 // Always display a throbber during pending loads.
600 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
601 return true;
602
[email protected]d0980792011-02-13 19:41:40603 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58604 if (web_ui)
605 return !web_ui->hide_favicon();
[email protected]96d185d2009-04-24 03:28:54606 return true;
607}
608
[email protected]585b30362011-01-28 02:30:17609void TabContents::AddObserver(TabContentsObserver* observer) {
610 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49611}
612
[email protected]585b30362011-01-28 02:30:17613void TabContents::RemoveObserver(TabContentsObserver* observer) {
614 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49615}
616
[email protected]443b80e2010-12-14 00:42:23617void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
618 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34619 return;
620
[email protected]443b80e2010-12-14 00:42:23621 crashed_status_ = status;
622 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50623 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34624}
625
[email protected]744ef172009-10-16 21:53:46626void TabContents::PageActionStateChanged() {
627 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00628}
[email protected]ce5c4502009-05-06 16:46:11629
[email protected]d5f942ba2008-09-26 19:30:34630void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
631 if (delegate_)
632 delegate_->NavigationStateChanged(this, changed_flags);
633}
634
[email protected]96d185d2009-04-24 03:28:54635void TabContents::DidBecomeSelected() {
636 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16637 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
638 if (rwhv) {
639 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43640#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16641 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43642#endif
643 }
[email protected]96d185d2009-04-24 03:28:54644
[email protected]8cb5d5b2010-02-09 11:36:16645 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11646 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54647}
648
[email protected]a94454b2010-12-16 04:16:03649void TabContents::FadeForInstant(bool animate) {
[email protected]1b072562010-12-13 19:37:45650 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
651 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
652 if (rwhv)
[email protected]a94454b2010-12-16 04:16:03653 rwhv->SetVisuallyDeemphasized(&whitish, animate);
[email protected]1b072562010-12-13 19:37:45654}
655
656void TabContents::CancelInstantFade() {
657 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
658 if (rwhv)
659 rwhv->SetVisuallyDeemphasized(NULL, false);
660}
661
[email protected]96d185d2009-04-24 03:28:54662void TabContents::WasHidden() {
663 if (!capturing_contents()) {
664 // |render_view_host()| can be NULL if the user middle clicks a link to open
665 // a tab in then background, then closes the tab before selecting it. This
666 // is because closing the tab calls TabContents::Destroy(), which removes
667 // the |render_view_host()|; then when we actually destroy the window,
668 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16669 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
670 if (rwhv)
671 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54672 }
673
674 NotificationService::current()->Notify(
675 NotificationType::TAB_CONTENTS_HIDDEN,
676 Source<TabContents>(this),
677 NotificationService::NoDetails());
678}
679
[email protected]d5f942ba2008-09-26 19:30:34680void TabContents::Activate() {
681 if (delegate_)
682 delegate_->ActivateContents(this);
683}
684
[email protected]ea42e7782010-08-23 23:58:12685void TabContents::Deactivate() {
686 if (delegate_)
687 delegate_->DeactivateContents(this);
688}
689
[email protected]96d185d2009-04-24 03:28:54690void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16691 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
692 if (rwhv)
693 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54694}
695
696void TabContents::HideContents() {
697 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
698 // our superclass HideContents(), because some callers want to be very picky
699 // about the order in which these get called. In addition to making the code
700 // here practically impossible to understand, this also means we end up
701 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34702 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54703 WasHidden();
704}
705
[email protected]5aab5e22010-12-08 22:13:29706bool TabContents::NeedToFireBeforeUnload() {
707 // TODO(creis): Should we fire even for interstitial pages?
708 return notify_disconnection() &&
709 !showing_interstitial_page() &&
710 !render_view_host()->SuddenTerminationAllowed();
711}
712
[email protected]c0588052008-10-27 23:01:50713void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34714 WindowOpenDisposition disposition,
715 PageTransition::Type transition) {
716 if (delegate_)
[email protected]c0588052008-10-27 23:01:50717 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34718}
719
[email protected]1ccb3568d2010-02-19 10:51:16720bool TabContents::NavigateToPendingEntry(
721 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54722 return NavigateToEntry(*controller_.pending_entry(), reload_type);
723}
[email protected]96d185d2009-04-24 03:28:54724
[email protected]876bc832010-09-07 16:29:54725bool TabContents::NavigateToEntry(
726 const NavigationEntry& entry,
727 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54728 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
729 if (!dest_render_view_host)
730 return false; // Unable to create the desired render view host.
731
[email protected]770dd8b2010-05-24 18:11:39732 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
733 dest_render_view_host->EnablePreferredSizeChangedMode(
734 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
735 }
[email protected]9fb325e2010-05-06 18:23:24736
[email protected]80a8fad2011-01-29 04:02:38737 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07738 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58739 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]c09163a2011-02-15 00:05:55740 bool is_allowed_in_web_ui_renderer =
[email protected]80a8fad2011-01-29 04:02:38741 WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url());
[email protected]c09163a2011-02-15 00:05:55742 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
743 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58744
[email protected]96d185d2009-04-24 03:28:54745 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12746 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32747 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00748 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
749 dest_render_view_host,
750 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32751 }
[email protected]96d185d2009-04-24 03:28:54752
753 // Used for page load time metrics.
754 current_load_start_ = base::TimeTicks::Now();
755
756 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34757 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54758 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04759 if (delegate_) {
760 navigate_params.extra_headers =
761 delegate_->GetNavigationHeaders(navigate_params.url);
762 }
[email protected]056de2d2009-06-26 16:41:34763 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54764
765 if (entry.page_id() == -1) {
766 // HACK!! This code suppresses javascript: URLs from being added to
767 // session history, which is what we want to do for javascript: URLs that
768 // do not generate content. What we really need is a message from the
769 // renderer telling us that a new page was not created. The same message
770 // could be used for mailto: URLs and the like.
771 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
772 return false;
773 }
774
[email protected]3c9e1872010-11-18 16:17:49775 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:17776 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54777
[email protected]1ccb3568d2010-02-19 10:51:16778 if (reload_type != NavigationController::NO_RELOAD &&
779 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48780 FaviconService* favicon_service =
781 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
782 if (favicon_service)
783 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54784 }
785
[email protected]d5f942ba2008-09-26 19:30:34786 return true;
787}
788
[email protected]96d185d2009-04-24 03:28:54789void TabContents::Stop() {
790 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09791 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54792}
793
[email protected]96d185d2009-04-24 03:28:54794void TabContents::DisassociateFromPopupCount() {
795 render_view_host()->DisassociateFromPopupCount();
796}
797
798TabContents* TabContents::Clone() {
799 // We create a new SiteInstance so that the new tab won't share processes
800 // with the old one. This can be changed in the future if we need it to share
801 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32802 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54803 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07804 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54805 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08806 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08807 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54808 return tc;
809}
810
[email protected]4d677202009-07-19 07:37:12811void TabContents::ShowPageInfo(const GURL& url,
812 const NavigationEntry::SSLStatus& ssl,
813 bool show_history) {
814 if (!delegate_)
815 return;
816
[email protected]bb678332009-07-21 00:15:50817 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12818}
819
[email protected]ef0d04c2010-12-15 23:34:21820void TabContents::SaveFavicon() {
821 NavigationEntry* entry = controller_.GetActiveEntry();
822 if (!entry || entry->url().is_empty())
823 return;
824
825 // Make sure the page is in history, otherwise adding the favicon does
826 // nothing.
827 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
828 Profile::IMPLICIT_ACCESS);
829 if (!history)
830 return;
831 history->AddPageNoVisitForBookmark(entry->url());
832
833 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
834 Profile::IMPLICIT_ACCESS);
835 if (!service)
836 return;
837 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
838 if (!favicon.is_valid() || favicon.url().is_empty() ||
839 favicon.bitmap().empty()) {
840 return;
841 }
842 std::vector<unsigned char> image_data;
843 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
[email protected]849ccee2011-03-16 17:05:30844 service->SetFavicon(
845 entry->url(), favicon.url(), image_data, history::FAVICON);
[email protected]ef0d04c2010-12-15 23:34:21846}
847
initial.commit09911bf2008-07-26 23:55:29848ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28849 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29850 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28851 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
[email protected]aed59602011-02-28 22:57:33852 AddConstrainedDialog(window);
853 return window;
854}
855
856void TabContents::AddConstrainedDialog(ConstrainedWindow* window) {
initial.commit09911bf2008-07-26 23:55:29857 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44858
859 if (child_windows_.size() == 1) {
860 window->ShowConstrainedWindow();
861 BlockTabContent(true);
862 }
initial.commit09911bf2008-07-26 23:55:29863}
864
[email protected]fa1cf0b82010-01-15 21:49:44865void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55866 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45867 // 70% opaque grey.
868 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55869 if (rwhv)
[email protected]1b072562010-12-13 19:37:45870 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44871 render_view_host()->set_ignore_input_events(blocked);
872 if (delegate_)
873 delegate_->SetTabContentBlocked(this, blocked);
874}
875
initial.commit09911bf2008-07-26 23:55:29876void TabContents::AddNewContents(TabContents* new_contents,
877 WindowOpenDisposition disposition,
878 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29879 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40880 if (all_contents_blocked_) {
881 if (!blocked_contents_)
882 blocked_contents_ = new BlockedContentContainer(this);
883 blocked_contents_->AddTabContents(
884 new_contents, disposition, initial_pos, user_gesture);
885 return;
886 }
887
initial.commit09911bf2008-07-26 23:55:29888 if (!delegate_)
889 return;
890
[email protected]35f7d212009-04-29 21:19:27891 if ((disposition == NEW_POPUP) && !user_gesture &&
892 !CommandLine::ForCurrentProcess()->HasSwitch(
893 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22894 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31895 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29896 delegate_->GetConstrainingContents(this)->AddPopup(
897 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31898 } else {
[email protected]0aa55312008-10-17 21:53:08899 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29900 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
901 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49902 NotificationService::current()->Notify(
903 NotificationType::TAB_ADDED,
904 Source<TabContentsDelegate>(delegate_),
905 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29906 }
initial.commit09911bf2008-07-26 23:55:29907
[email protected]8cc8d492010-02-02 10:40:49908 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:40909 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:29910}
911
[email protected]bcd9dc42010-01-23 16:38:18912bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:20913 bool is_js_code, const std::string& code_string,
914 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51915 RenderViewHost* host = render_view_host();
916 if (!host)
917 return false;
918
919 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:17920 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:51921 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35922}
923
[email protected]96d185d2009-04-24 03:28:54924void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49925 if (is_being_destroyed_)
926 return;
[email protected]9fb83e82010-07-02 18:24:55927 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49928 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40929 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:54930}
931
[email protected]5c9e97a2009-09-09 23:48:30932gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54933 return view_->GetContentNativeView();
934}
935
936gfx::NativeView TabContents::GetNativeView() const {
937 return view_->GetNativeView();
938}
939
940void TabContents::GetContainerBounds(gfx::Rect *out) const {
941 view_->GetContainerBounds(out);
942}
943
944void TabContents::Focus() {
945 view_->Focus();
946}
947
[email protected]90daadb42009-06-08 21:27:28948void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54949 if (showing_interstitial_page()) {
950 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
951 return;
952 }
[email protected]96d185d2009-04-24 03:28:54953 render_view_host()->SetInitialFocus(reverse);
954}
955
956bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40957 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58958 if (web_ui)
959 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43960 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25961 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43962 return true;
[email protected]96d185d2009-04-24 03:28:54963 return false;
964}
965
[email protected]a26dc362010-04-23 01:48:58966void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38967 if (delegate())
[email protected]a26dc362010-04-23 01:48:58968 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38969}
970
[email protected]616ed5a2008-11-21 22:27:24971void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32972 if (delegate_ && !delegate_->infobars_enabled()) {
973 delegate->InfoBarClosed();
974 return;
975 }
976
[email protected]616ed5a2008-11-21 22:27:24977 // Look through the existing InfoBarDelegates we have for a match. If we've
978 // already got one that matches, then we don't add the new one.
[email protected]ec8f51162011-02-08 04:20:40979 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:45980 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
981 // Tell the new infobar to close so that it can clean itself up.
982 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:24983 return;
[email protected]6d27a7b2009-12-18 23:25:45984 }
[email protected]616ed5a2008-11-21 22:27:24985 }
986
987 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56988 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:19989 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:56990 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24991
992 // Add ourselves as an observer for navigations the first time a delegate is
993 // added. We use this notification to expire InfoBars that need to expire on
994 // page transitions.
995 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56996 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57997 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24998 }
999}
1000
1001void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321002 if (delegate_ && !delegate_->infobars_enabled()) {
1003 return;
1004 }
1005
[email protected]616ed5a2008-11-21 22:27:241006 std::vector<InfoBarDelegate*>::iterator it =
1007 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1008 if (it != infobar_delegates_.end()) {
1009 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561010 NotificationService::current()->Notify(
1011 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1012 Source<TabContents>(this),
1013 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241014
[email protected]f4f50ef2011-01-21 19:01:191015 infobar_delegates_.erase(it);
1016 // Remove ourselves as an observer if we are tracking no more InfoBars.
1017 if (infobar_delegates_.empty()) {
1018 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1019 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031020 }
[email protected]616ed5a2008-11-21 22:27:241021 }
1022}
[email protected]3edd9522009-03-04 22:19:411023
[email protected]f81821c2009-08-07 01:29:471024void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1025 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321026 if (delegate_ && !delegate_->infobars_enabled()) {
1027 new_delegate->InfoBarClosed();
1028 return;
1029 }
1030
[email protected]f81821c2009-08-07 01:29:471031 std::vector<InfoBarDelegate*>::iterator it =
1032 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1033 DCHECK(it != infobar_delegates_.end());
1034
1035 // Notify the container about the change of plans.
1036 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1037 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1038 old_delegate, new_delegate));
1039 NotificationService::current()->Notify(
1040 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1041 Source<TabContents>(this),
1042 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1043
[email protected]f4f50ef2011-01-21 19:01:191044 // Remove the old one.
1045 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:471046
1047 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081048 DCHECK(find(infobar_delegates_.begin(),
1049 infobar_delegates_.end(), new_delegate) ==
1050 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471051 infobar_delegates_.push_back(new_delegate);
1052}
1053
[email protected]20ede072009-10-06 00:28:351054bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271055 if (showing_interstitial_page())
1056 return false;
1057
[email protected]c8f74942010-09-03 10:04:141058 // Do not show bookmarks bar if bookmarks aren't enabled.
1059 if (!browser_defaults::bookmarks_enabled)
1060 return false;
1061
[email protected]d0980792011-02-13 19:41:401062 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:541063 // similar, but for non-first loads, we want to use the committed entry. This
1064 // is so the bookmarks bar disappears at the same time the page does.
1065 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:351066 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:581067 return (render_manager_.web_ui() == NULL) ?
1068 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541069 }
1070
1071 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:401072 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:541073 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:581074 if (render_manager_.pending_web_ui())
1075 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
1076 return (render_manager_.web_ui() == NULL) ?
1077 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541078}
1079
[email protected]3edd9522009-03-04 22:19:411080void TabContents::ToolbarSizeChanged(bool is_animating) {
1081 TabContentsDelegate* d = delegate();
1082 if (d)
1083 d->ToolbarSizeChanged(this, is_animating);
1084}
[email protected]616ed5a2008-11-21 22:27:241085
[email protected]fc6fb7fb2009-11-07 02:35:041086bool TabContents::CanDownload(int request_id) {
1087 TabContentsDelegate* d = delegate();
1088 if (d)
1089 return d->CanDownload(request_id);
1090 return true;
1091}
1092
[email protected]d5f942ba2008-09-26 19:30:341093void TabContents::OnStartDownload(DownloadItem* download) {
1094 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341095
1096 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311097 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341098
[email protected]5b928b62010-08-03 11:46:511099 if (tab_contents && tab_contents->delegate())
1100 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411101}
[email protected]3edd9522009-03-04 22:19:411102
[email protected]d5f942ba2008-09-26 19:30:341103void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371104 ConstrainedWindowList::iterator i(
1105 std::find(child_windows_.begin(), child_windows_.end(), window));
1106 bool removed_topmost_window = i == child_windows_.begin();
1107 if (i != child_windows_.end())
1108 child_windows_.erase(i);
1109 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441110 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371111 } else {
1112 if (removed_topmost_window)
1113 child_windows_[0]->ShowConstrainedWindow();
1114 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441115 }
[email protected]66ba4932009-06-04 19:22:131116}
[email protected]d5f942ba2008-09-26 19:30:341117
[email protected]c65e2f152010-10-14 15:30:401118void TabContents::WillCloseBlockedContentContainer(
1119 BlockedContentContainer* container) {
1120 DCHECK(blocked_contents_ == container);
1121 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491122 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341123}
1124
[email protected]d5f942ba2008-09-26 19:30:341125void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351126#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061127 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351128#endif
[email protected]d5f942ba2008-09-26 19:30:341129}
1130
[email protected]420ae012009-04-24 05:16:321131void TabContents::OnSavePage() {
1132 // If we can not save the page, try to download it.
1133 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1134 DownloadManager* dlm = profile()->GetDownloadManager();
1135 const GURL& current_page_url = GetURL();
1136 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221137 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321138 return;
1139 }
1140
1141 Stop();
1142
1143 // Create the save package and possibly prompt the user for the name to save
1144 // the page as. The user prompt is an asynchronous operation that runs on
1145 // another thread.
[email protected]b5a1d11c2011-02-17 03:09:421146 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321147 save_package_->GetSaveInfo();
1148}
1149
1150// Used in automated testing to bypass prompting the user for file names.
1151// Instead, the names and paths are hard coded rather than running them through
1152// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111153bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321154 SavePackage::SavePackageType save_type) {
1155 // Stop the page from navigating.
1156 Stop();
1157
[email protected]b5a1d11c2011-02-17 03:09:421158 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591159 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321160}
1161
[email protected]89d6e6e2009-12-03 23:06:511162void TabContents::EmailPageLocation() {
1163 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1164 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1165 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1166 title + "&body=%0A%0A" + page_url;
1167 platform_util::OpenExternal(GURL(mailto));
1168}
1169
[email protected]420ae012009-04-24 05:16:321170void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161171 if (CommandLine::ForCurrentProcess()->HasSwitch(
1172 switches::kEnablePrintPreview)) {
1173 if (showing_interstitial_page())
1174 return;
[email protected]83a58a22011-02-05 03:44:481175
1176 printing::PrintPreviewTabController* tab_controller =
[email protected]01884622011-03-08 01:48:461177 printing::PrintPreviewTabController::GetInstance();
[email protected]83a58a22011-02-05 03:44:481178 if (!tab_controller)
1179 return;
1180 tab_controller->GetOrCreatePreviewTab(this, controller().window_id().id());
[email protected]dbeebd52010-11-16 20:34:161181 } else {
1182 PrintNow();
1183 }
[email protected]420ae012009-04-24 05:16:321184}
1185
1186bool TabContents::PrintNow() {
1187 // We can't print interstitial page for now.
1188 if (showing_interstitial_page())
1189 return false;
1190
1191 return render_view_host()->PrintPages();
1192}
1193
[email protected]82270452009-06-19 15:58:011194void TabContents::PrintingDone(int document_cookie, bool success) {
1195 render_view_host()->PrintingDone(document_cookie, success);
1196}
1197
[email protected]420ae012009-04-24 05:16:321198bool TabContents::IsActiveEntry(int32 page_id) {
1199 NavigationEntry* active_entry = controller_.GetActiveEntry();
1200 return (active_entry != NULL &&
1201 active_entry->site_instance() == GetSiteInstance() &&
1202 active_entry->page_id() == page_id);
1203}
1204
[email protected]b2fe07d12010-02-09 14:38:081205void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161206 set_encoding(encoding);
1207 render_view_host()->SetPageEncoding(encoding);
1208}
1209
[email protected]b2fe07d12010-02-09 14:38:081210void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161211 reset_encoding();
1212 render_view_host()->ResetPageEncodingToDefault();
1213}
1214
1215void TabContents::WindowMoveOrResizeStarted() {
1216 render_view_host()->WindowMoveOrResizeStarted();
1217}
1218
[email protected]c65e2f152010-10-14 15:30:401219void TabContents::SetAllContentsBlocked(bool value) {
1220 if (all_contents_blocked_ == value)
1221 return;
1222
1223 all_contents_blocked_ = value;
1224 if (!all_contents_blocked_ && blocked_contents_) {
1225 std::vector<TabContents*> blocked;
1226 blocked_contents_->GetBlockedContents(&blocked);
1227 for (size_t i = 0; i < blocked.size(); ++i)
1228 blocked_contents_->LaunchForContents(blocked[i]);
1229 }
1230}
1231
[email protected]3f8eb7f2009-10-02 23:58:051232void TabContents::LogNewTabTime(const std::string& event_name) {
1233 // Not all new tab pages get timed. In those cases, we don't have a
1234 // new_tab_start_time_.
1235 if (new_tab_start_time_.is_null())
1236 return;
1237
1238 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441239 MetricEventDurationDetails details(event_name,
1240 static_cast<int>(duration.InMilliseconds()));
1241
[email protected]7ab1e7d62009-10-14 23:32:011242 if (event_name == "Tab.NewTabScriptStart") {
1243 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1244 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1245 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1246 } else if (event_name == "Tab.NewTabOnload") {
1247 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051248 // The new tab page has finished loading; reset it.
1249 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441250 } else {
1251 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051252 }
[email protected]84abba62009-10-07 17:01:441253 NotificationService::current()->Notify(
1254 NotificationType::METRIC_EVENT_DURATION,
1255 Source<TabContents>(this),
1256 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051257}
1258
[email protected]7ab1e7d62009-10-14 23:32:011259void TabContents::OnCloseStarted() {
1260 if (tab_close_start_time_.is_null())
1261 tab_close_start_time_ = base::TimeTicks::Now();
1262}
1263
[email protected]46624bf2010-06-09 16:04:191264bool TabContents::ShouldAcceptDragAndDrop() const {
1265#if defined(OS_CHROMEOS)
1266 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1267 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201268 if (delegate() && delegate()->IsPopup(this))
1269 return false;
1270 return true;
[email protected]46624bf2010-06-09 16:04:191271#else
1272 return true;
1273#endif
1274}
1275
[email protected]7813bd72011-02-05 02:19:341276void TabContents::SystemDragEnded() {
1277 if (render_view_host())
1278 render_view_host()->DragSourceSystemDragEnded();
1279 if (delegate())
1280 delegate()->DragEnded();
1281}
1282
[email protected]ec0b6c42010-08-26 03:16:581283void TabContents::UpdateHistoryForNavigation(
1284 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1285 if (profile()->IsOffTheRecord())
1286 return;
1287
1288 // Add to history service.
1289 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1290 if (hs)
1291 hs->AddPage(*add_page_args);
1292}
1293
1294void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1295 if (profile()->IsOffTheRecord())
1296 return;
1297
1298 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1299 if (hs)
1300 hs->SetPageTitle(entry.virtual_url(), entry.title());
1301}
1302
[email protected]d0b8d092010-10-25 04:05:171303double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251304 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1305 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171306 return 0;
[email protected]b75b8292010-10-01 07:28:251307
1308 double zoom_level;
1309 if (temporary_zoom_settings_) {
1310 zoom_level = zoom_map->GetTemporaryZoomLevel(
1311 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1312 } else {
1313 zoom_level = zoom_map->GetZoomLevel(GetURL());
1314 }
[email protected]d0b8d092010-10-25 04:05:171315 return zoom_level;
1316}
[email protected]b75b8292010-10-01 07:28:251317
[email protected]d0b8d092010-10-25 04:05:171318int TabContents::GetZoomPercent(bool* enable_increment,
1319 bool* enable_decrement) {
1320 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251321 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171322 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251323 *enable_decrement = percent > minimum_zoom_percent_;
1324 *enable_increment = percent < maximum_zoom_percent_;
1325 return percent;
1326}
1327
[email protected]3c733bde2010-12-21 19:56:311328void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501329 if (!delegate_)
1330 return;
1331
1332 NavigationEntry* active_entry = controller().GetActiveEntry();
1333 if (!active_entry)
1334 return;
1335
1336 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121337}
1338
[email protected]932b7a12011-03-09 12:50:271339void TabContents::ViewFrameSource(const GURL& url,
1340 const std::string& content_state) {
1341 if (!delegate_)
1342 return;
1343
1344 delegate_->ViewSourceForFrame(this, url, content_state);
1345}
1346
[email protected]724159a2010-12-30 01:11:181347void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1348 bool is_main_frame,
1349 const GURL& url) {
1350 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1351 GURL validated_url(url);
1352 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1353 GetRenderProcessHost()->id(), &validated_url);
1354
1355 ProvisionalLoadDetails details(
1356 is_main_frame,
1357 controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091358 validated_url, std::string(), is_error_page, frame_id);
[email protected]724159a2010-12-30 01:11:181359 NotificationService::current()->Notify(
1360 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1361 Source<NavigationController>(&controller_),
1362 Details<ProvisionalLoadDetails>(&details));
1363 if (is_main_frame) {
1364 // If we're displaying a network error page do not reset the content
1365 // settings delegate's cookies so the user has a chance to modify cookie
1366 // settings.
1367 if (!is_error_page)
1368 content_settings_delegate_->ClearCookieSpecificContentSettings();
1369 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]e7d50892011-01-19 21:47:381370
[email protected]4850a7f2011-03-08 23:36:591371 // Notify observers about the provisional change in the main frame URL.
1372 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1373 OnProvisionalChangeToMainFrameUrl(url));
[email protected]724159a2010-12-30 01:11:181374 }
1375}
1376
1377void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1378 const GURL& source_url,
1379 const GURL& target_url) {
1380 NavigationEntry* entry;
1381 if (page_id == -1)
1382 entry = controller_.pending_entry();
1383 else
1384 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1385 if (!entry || entry->url() != source_url)
1386 return;
1387 entry->set_url(target_url);
[email protected]e7d50892011-01-19 21:47:381388
[email protected]4850a7f2011-03-08 23:36:591389 // Notify observers about the provisional change in the main frame URL.
1390 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1391 OnProvisionalChangeToMainFrameUrl(target_url));
[email protected]724159a2010-12-30 01:11:181392}
1393
1394void TabContents::OnDidFailProvisionalLoadWithError(
1395 int64 frame_id,
1396 bool is_main_frame,
1397 int error_code,
1398 const GURL& url,
1399 bool showing_repost_interstitial) {
1400 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1401 << ", error_code: " << error_code
1402 << " is_main_frame: " << is_main_frame
1403 << " showing_repost_interstitial: " << showing_repost_interstitial
1404 << " frame_id: " << frame_id;
1405 GURL validated_url(url);
1406 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1407 GetRenderProcessHost()->id(), &validated_url);
1408
1409 if (net::ERR_ABORTED == error_code) {
1410 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1411 // This means that the interstitial won't be torn down properly, which is
1412 // bad. But if we have an interstitial, go back to another tab type, and
1413 // then load the same interstitial again, we could end up getting the first
1414 // interstitial's "failed" message (as a result of the cancel) when we're on
1415 // the second one.
1416 //
1417 // We can't tell this apart, so we think we're tearing down the current page
1418 // which will cause a crash later one. There is also some code in
1419 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1420 // out because of this problem.
1421 //
1422 // http://code.google.com/p/chromium/issues/detail?id=2855
1423 // Because this will not tear down the interstitial properly, if "back" is
1424 // back to another tab type, the interstitial will still be somewhat alive
1425 // in the previous tab type. If you navigate somewhere that activates the
1426 // tab with the interstitial again, you'll see a flash before the new load
1427 // commits of the interstitial page.
1428 if (showing_interstitial_page()) {
1429 LOG(WARNING) << "Discarding message during interstitial.";
1430 return;
1431 }
1432
1433 // This will discard our pending entry if we cancelled the load (e.g., if we
1434 // decided to download the file instead of load it). Only discard the
1435 // pending entry if the URLs match, otherwise the user initiated a navigate
1436 // before the page loaded so that the discard would discard the wrong entry.
1437 NavigationEntry* pending_entry = controller_.pending_entry();
1438 if (pending_entry && pending_entry->url() == validated_url) {
1439 controller_.DiscardNonCommittedEntries();
1440 // Update the URL display.
1441 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1442 }
1443
1444 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1445 }
1446
1447 // Send out a notification that we failed a provisional load with an error.
1448 ProvisionalLoadDetails details(
1449 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091450 validated_url, std::string(), false, frame_id);
[email protected]724159a2010-12-30 01:11:181451 details.set_error_code(error_code);
1452
1453 NotificationService::current()->Notify(
1454 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1455 Source<NavigationController>(&controller_),
1456 Details<ProvisionalLoadDetails>(&details));
1457}
1458
1459void TabContents::OnDidLoadResourceFromMemoryCache(
1460 const GURL& url,
[email protected]724159a2010-12-30 01:11:181461 const std::string& security_info) {
[email protected]28620862011-03-22 23:07:191462 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181463 cache.Increment();
1464
1465 // Send out a notification that we loaded a resource from our memory cache.
1466 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1467 SSLManager::DeserializeSecurityInfo(security_info,
1468 &cert_id, &cert_status,
1469 &security_bits,
1470 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161471 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1472 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181473
1474 NotificationService::current()->Notify(
1475 NotificationType::LOAD_FROM_MEMORY_CACHE,
1476 Source<NavigationController>(&controller_),
1477 Details<LoadFromMemoryCacheDetails>(&details));
1478}
1479
1480void TabContents::OnDidDisplayInsecureContent() {
1481 displayed_insecure_content_ = true;
1482 SSLManager::NotifySSLInternalStateChanged();
1483}
1484
1485void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021486 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231487 LOG(INFO) << security_origin << " ran insecure content from "
1488 << target_url.possibly_invalid_spec();
[email protected]724159a2010-12-30 01:11:181489 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1490}
1491
1492void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1493 controller_.DocumentLoadedInFrame();
1494 NotificationService::current()->Notify(
1495 NotificationType::FRAME_DOM_CONTENT_LOADED,
1496 Source<NavigationController>(&controller_),
1497 Details<int64>(&frame_id));
1498}
1499
1500void TabContents::OnDidFinishLoad(int64 frame_id) {
1501 NotificationService::current()->Notify(
1502 NotificationType::FRAME_DID_FINISH_LOAD,
1503 Source<NavigationController>(&controller_),
1504 Details<int64>(&frame_id));
1505}
1506
[email protected]c8f73ab2011-01-22 00:05:171507void TabContents::OnUpdateContentRestrictions(int restrictions) {
1508 content_restrictions_ = restrictions;
1509 delegate()->ContentRestrictionsChanged(this);
1510}
1511
1512void TabContents::OnPDFHasUnsupportedFeature() {
1513 PDFHasUnsupportedFeature(this);
1514}
1515
[email protected]96d185d2009-04-24 03:28:541516// Notifies the RenderWidgetHost instance about the fact that the page is
1517// loading, or done loading and calls the base implementation.
1518void TabContents::SetIsLoading(bool is_loading,
1519 LoadNotificationDetails* details) {
1520 if (is_loading == is_loading_)
1521 return;
1522
1523 if (!is_loading) {
1524 load_state_ = net::LOAD_STATE_IDLE;
1525 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561526 upload_size_ = 0;
1527 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541528 }
1529
1530 render_manager_.SetIsLoading(is_loading);
1531
1532 is_loading_ = is_loading;
1533 waiting_for_response_ = is_loading;
1534
[email protected]6ebdc9b2010-09-27 16:55:571535 if (delegate_)
1536 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351537 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541538
1539 NotificationType type = is_loading ? NotificationType::LOAD_START :
1540 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111541 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541542 if (details)
1543 det = Details<LoadNotificationDetails>(details);
1544 NotificationService::current()->Notify(type,
1545 Source<NavigationController>(&controller_),
1546 det);
1547}
1548
[email protected]b6c874582009-05-08 19:38:311549void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291550 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061551 // A page can't spawn popups (or do anything else, either) until its load
1552 // commits, so when we reach here, the popup was spawned by the
1553 // NavigationController's last committed entry, not the active entry. For
1554 // example, if a page opens a popup in an onunload() handler, then the active
1555 // entry is the page to be loaded as we navigate away from the unloading
1556 // page. For this reason, we can't use GetURL() to get the opener URL,
1557 // because it returns the active entry.
1558 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1559 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1560
1561 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491562 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091563 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491564 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1565 } else {
[email protected]c65e2f152010-10-14 15:30:401566 if (!blocked_contents_)
1567 blocked_contents_ = new BlockedContentContainer(this);
1568 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1569 true);
[email protected]55126132010-08-19 14:53:281570 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1571 std::string());
[email protected]8cc8d492010-02-02 10:40:491572 }
[email protected]b9681312008-11-07 00:08:261573}
[email protected]616ed5a2008-11-21 22:27:241574
[email protected]616ed5a2008-11-21 22:27:241575void TabContents::ExpireInfoBars(
1576 const NavigationController::LoadCommittedDetails& details) {
1577 // Only hide InfoBars when the user has done something that makes the main
1578 // frame load. We don't want various automatic or subframe navigations making
1579 // it disappear.
1580 if (!details.is_user_initiated_main_frame_load())
1581 return;
1582
[email protected]ec8f51162011-02-08 04:20:401583 // NOTE: It is not safe to change the following code to count upwards or use
1584 // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
1585 // list.
1586 for (size_t i = infobar_count(); i > 0; --i) {
1587 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
[email protected]f86a07022008-11-25 01:06:051588 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241589 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241590 }
1591}
[email protected]fdd61c62009-04-22 19:22:571592
[email protected]d0980792011-02-13 19:41:401593WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581594 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541595 // that goes along with it to control the basic flags. For example, we want to
1596 // show the pending URL in the URL bar, so we want the display_url flag to
1597 // be from the pending entry.
1598 //
1599 // The confusion comes because there are multiple possibilities for the
1600 // initial load in a tab as a side effect of the way the RenderViewHostManager
1601 // works.
1602 //
[email protected]e0112912011-02-02 22:54:351603 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541604 // the pending one, and we want it to apply here.
1605 //
1606 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1607 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581608 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351609 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541610 //
1611 // This condition handles all of these cases:
1612 //
1613 // - First load in first tab: no committed nav entry + pending nav entry +
1614 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351615 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541616 //
1617 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351618 // no pending Web UI:
1619 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541620 //
1621 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351622 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541623 //
1624 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351625 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541626 if (controller_.pending_entry() &&
1627 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581628 render_manager_.pending_web_ui()))
1629 return render_manager_.pending_web_ui();
1630 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541631}
[email protected]420ae012009-04-24 05:16:321632
1633void TabContents::DidNavigateMainFramePostCommit(
1634 const NavigationController::LoadCommittedDetails& details,
1635 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]80a8fad2011-01-29 04:02:381636 if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) {
1637 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441638 // that opened the window, as long as both renderers have the same
1639 // privileges.
[email protected]80a8fad2011-01-29 04:02:381640 if (opener_web_ui_type_ ==
1641 WebUIFactory::GetWebUIType(profile(), GetURL())) {
[email protected]7ade2732011-02-10 00:13:581642 WebUI* web_ui = WebUIFactory::CreateWebUIForURL(this, GetURL());
1643 // web_ui might be NULL if the URL refers to a non-existent extension.
1644 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401645 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581646 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441647 }
1648 }
[email protected]80a8fad2011-01-29 04:02:381649 opener_web_ui_type_ = WebUIFactory::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441650 }
1651
[email protected]420ae012009-04-24 05:16:321652 if (details.is_user_initiated_main_frame_load()) {
1653 // Clear the status bubble. This is a workaround for a bug where WebKit
1654 // doesn't let us know that the cursor left an element during a
1655 // transition (this is also why the mouse cursor remains as a hand after
1656 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1657 // clear the bubble when a user navigates to a named anchor in the same
1658 // page.
1659 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321660 }
1661
[email protected]420ae012009-04-24 05:16:321662 // Allow the new page to set the title again.
1663 received_page_title_ = false;
1664
1665 // Get the favicon, either from history or request it from the net.
[email protected]16be5c32011-03-15 17:52:031666 favicon_helper_->FetchFavicon(details.entry->url());
[email protected]420ae012009-04-24 05:16:321667
[email protected]0de80162010-02-03 04:52:351668 // Clear all page actions, blocked content notifications and browser actions
1669 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141670 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:001671 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:081672 if (service) {
1673 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571674 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081675 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521676 if (browser_action) {
1677 browser_action->ClearAllValuesForTab(controller().session_id().id());
1678 NotificationService::current()->Notify(
1679 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571680 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521681 NotificationService::NoDetails());
1682 }
[email protected]92c6f9b92009-10-24 04:35:081683
[email protected]5d246db22009-10-27 06:17:571684 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521685 service->extensions()->at(i)->page_action();
1686 if (page_action) {
1687 page_action->ClearAllValuesForTab(controller().session_id().id());
1688 PageActionStateChanged();
1689 }
[email protected]92c6f9b92009-10-24 04:35:081690 }
[email protected]aece2c7f2009-08-27 20:43:171691 }
[email protected]0de80162010-02-03 04:52:351692
1693 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401694 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341695 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401696 blocked_contents_->Destroy();
1697 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351698 }
1699
1700 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411701 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551702 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471703
1704 // Once the main frame is navigated, we're no longer considered to have
1705 // displayed insecure content.
1706 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171707 }
[email protected]ce5c4502009-05-06 16:46:111708
[email protected]8cc8d492010-02-02 10:40:491709 // Close constrained windows if necessary.
1710 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1711 details.previous_url, details.entry->url()))
1712 CloseConstrainedWindows();
1713
[email protected]3c9e1872010-11-18 16:17:491714 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171715 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491716 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321717}
1718
1719void TabContents::DidNavigateAnyFramePostCommit(
1720 RenderViewHost* render_view_host,
1721 const NavigationController::LoadCommittedDetails& details,
1722 const ViewHostMsg_FrameNavigate_Params& params) {
1723 // If we navigate, start showing messages again. This does nothing to prevent
1724 // a malicious script from spamming messages, since the script could just
1725 // reload the page to stop blocking.
1726 suppress_javascript_messages_ = false;
1727
[email protected]3c9e1872010-11-18 16:17:491728 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171729 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491730 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551731
1732 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581733 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321734}
1735
[email protected]8cc8d492010-02-02 10:40:491736void TabContents::CloseConstrainedWindows() {
1737 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]aed59602011-02-28 22:57:331738 // To ensure that we iterate over every element in child_windows_ we
1739 // need to use a copy of child_windows_. Otherwise if
1740 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
1741 // skipping some elements.
1742 ConstrainedWindowList child_windows_copy(child_windows_);
1743 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
1744 it != child_windows_copy.end(); ++it) {
1745 ConstrainedWindow* window = *it;
[email protected]fa1cf0b82010-01-15 21:49:441746 if (window) {
[email protected]420ae012009-04-24 05:16:321747 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441748 BlockTabContent(false);
1749 }
[email protected]420ae012009-04-24 05:16:321750 }
1751}
1752
[email protected]420ae012009-04-24 05:16:321753void TabContents::UpdateAlternateErrorPageURL() {
1754 GURL url = GetAlternateErrorPageURL();
1755 render_view_host()->SetAlternateErrorPageURL(url);
1756}
1757
1758void TabContents::UpdateWebPreferences() {
1759 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1760}
1761
[email protected]d0b8d092010-10-25 04:05:171762void TabContents::UpdateZoomLevel() {
1763 render_view_host()->SetZoomLevel(GetZoomLevel());
1764}
1765
[email protected]420ae012009-04-24 05:16:321766void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1767 RenderViewHost* rvh) {
1768 // If we are creating a RVH for a restored controller, then we might
1769 // have more page IDs than the SiteInstance's current max page ID. We must
1770 // make sure that the max page ID is larger than any restored page ID.
1771 // Note that it is ok for conflicting page IDs to exist in another tab
1772 // (i.e., NavigationController), but if any page ID is larger than the max,
1773 // the back/forward list will get confused.
1774 int max_restored_page_id = controller_.max_restored_page_id();
1775 if (max_restored_page_id > 0) {
1776 int curr_max_page_id = site_instance->max_page_id();
1777 if (max_restored_page_id > curr_max_page_id) {
1778 // Need to update the site instance immediately.
1779 site_instance->UpdateMaxPageID(max_restored_page_id);
1780
1781 // Also tell the renderer to update its internal representation. We
1782 // need to reserve enough IDs to make all restored page IDs less than
1783 // the max.
1784 if (curr_max_page_id < 0)
1785 curr_max_page_id = 0;
1786 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1787 }
1788 }
1789}
1790
[email protected]ec0b6c42010-08-26 03:16:581791scoped_refptr<history::HistoryAddPageArgs>
1792TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541793 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471794 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321795 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581796 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1797 new history::HistoryAddPageArgs(
1798 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1799 params.redirects, params.transition, history::SOURCE_BROWSED,
1800 details.did_replace_entry));
1801 if (PageTransition::IsMainFrame(params.transition) &&
1802 virtual_url != params.url) {
1803 // Hack on the "virtual" URL so that it will appear in history. For some
1804 // types of URLs, we will display a magic URL that is different from where
1805 // the page is actually navigated. We want the user to see in history what
1806 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1807 // only applies to the main frame, as the virtual URL doesn't apply to
1808 // sub-frames.
1809 add_page_args->url = virtual_url;
1810 if (!add_page_args->redirects.empty())
1811 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321812 }
[email protected]ec0b6c42010-08-26 03:16:581813 return add_page_args;
[email protected]420ae012009-04-24 05:16:321814}
1815
1816bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1817 const std::wstring& title) {
1818 // For file URLs without a title, use the pathname instead. In the case of a
1819 // synthesized title, we don't want the update to count toward the "one set
1820 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251821 string16 final_title;
[email protected]420ae012009-04-24 05:16:321822 bool explicit_set;
1823 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251824 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321825 explicit_set = false; // Don't count synthetic titles toward the set limit.
1826 } else {
[email protected]e53668962010-06-23 15:35:251827 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321828 explicit_set = true;
1829 }
1830
[email protected]e53668962010-06-23 15:35:251831 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321832 return false; // Nothing changed, don't bother.
1833
[email protected]e53668962010-06-23 15:35:251834 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321835
[email protected]ec0b6c42010-08-26 03:16:581836 if (!received_page_title_) {
1837 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321838 received_page_title_ = explicit_set;
1839 }
1840
1841 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251842 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321843
[email protected]cbc0e1b2010-04-12 18:33:041844 NotificationService::current()->Notify(
1845 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1846 Source<TabContents>(this),
1847 NotificationService::NoDetails());
1848
[email protected]420ae012009-04-24 05:16:321849 return true;
1850}
1851
1852void TabContents::NotifySwapped() {
1853 // After sending out a swap notification, we need to send a disconnect
1854 // notification so that clients that pick up a pointer to |this| can NULL the
1855 // pointer. See Bug 1230284.
1856 notify_disconnection_ = true;
1857 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341858 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221859 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321860 NotificationService::NoDetails());
1861}
1862
1863void TabContents::NotifyConnected() {
1864 notify_disconnection_ = true;
1865 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341866 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221867 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321868 NotificationService::NoDetails());
1869}
1870
1871void TabContents::NotifyDisconnected() {
1872 if (!notify_disconnection_)
1873 return;
1874
1875 notify_disconnection_ = false;
1876 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341877 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221878 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321879 NotificationService::NoDetails());
1880}
1881
[email protected]7d472472011-01-22 01:30:251882void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541883 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1884 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1885 if (!entry)
1886 return;
1887 // Note that we don't call NavigationController::GotToOffset() as we don't
1888 // want to create a pending navigation entry (it might end up lingering
1889 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:521890 entry->set_transition_type(entry->transition_type() |
1891 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:541892 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
1893 }
[email protected]bf5c2ff392009-07-08 16:24:331894}
1895
[email protected]38789d82010-11-17 06:03:441896void TabContents::OnDidGetApplicationInfo(int32 page_id,
1897 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511898 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331899
[email protected]ed5431872009-11-17 08:39:511900 if (delegate())
1901 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331902}
1903
[email protected]bb461532010-11-26 21:50:231904void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
1905 if (delegate())
1906 delegate()->OnInstallApplication(this, info);
1907}
1908
[email protected]a2cf65eb2010-01-18 08:20:381909void TabContents::OnPageContents(const GURL& url,
[email protected]a2cf65eb2010-01-18 08:20:381910 int32 page_id,
[email protected]e5106202010-06-11 21:12:361911 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:101912 const std::string& language,
1913 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:381914 // Don't index any https pages. People generally don't want their bank
1915 // accounts, etc. indexed on their computer, especially since some of these
1916 // things are not marked cachable.
1917 // TODO(brettw) we may want to consider more elaborate heuristics such as
1918 // the cachability of the page. We may also want to consider subframes (this
1919 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271920 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1921 // content indexing for chromeos in some future releases.
1922#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381923 if (!url.SchemeIsSecure()) {
1924 Profile* p = profile();
1925 if (p && !p->IsOffTheRecord()) {
1926 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1927 if (hs)
1928 hs->SetPageContents(url, contents);
1929 }
1930 }
[email protected]ccd40a52010-05-11 16:15:271931#endif
[email protected]a8a81292010-01-21 00:32:451932
[email protected]1c57b7b2010-07-12 17:38:101933 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:451934
1935 std::string lang = language;
1936 NotificationService::current()->Notify(
1937 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151938 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451939 Details<std::string>(&lang));
[email protected]d54169e92011-01-21 09:19:521940
1941 // Generate the thumbnail here if the in-browser thumbnailing is enabled.
1942 if (CommandLine::ForCurrentProcess()->HasSwitch(
1943 switches::kEnableInBrowserThumbnailing)) {
1944 ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url);
1945 }
[email protected]a2cf65eb2010-01-18 08:20:381946}
1947
[email protected]7e0831b2010-02-01 08:45:151948void TabContents::OnPageTranslated(int32 page_id,
1949 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:161950 const std::string& translated_lang,
1951 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:551952 language_state_.set_current_language(translated_lang);
1953 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:161954 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:151955 NotificationService::current()->Notify(
1956 NotificationType::PAGE_TRANSLATED,
1957 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:161958 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:151959}
1960
[email protected]ce833282010-11-04 15:48:391961void TabContents::OnSetSuggestions(
1962 int32 page_id,
[email protected]1c9c7fb2011-03-11 16:38:381963 const std::vector<std::string>& suggestions,
1964 InstantCompleteBehavior behavior) {
[email protected]15d9c0c2010-09-10 22:36:261965 if (delegate())
[email protected]1c9c7fb2011-03-11 16:38:381966 delegate()->OnSetSuggestions(page_id, suggestions, behavior);
[email protected]ce833282010-11-04 15:48:391967}
1968
1969void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
1970 if (delegate())
1971 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:261972}
1973
[email protected]dcd5b332010-08-11 08:55:181974void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:561975 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241976 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:561977}
1978
[email protected]8d3347f2009-07-09 22:00:211979RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321980 return view_.get();
1981}
1982
[email protected]8d3347f2009-07-09 22:00:211983RenderViewHostDelegate::RendererManagement*
1984TabContents::GetRendererManagementDelegate() {
1985 return &render_manager_;
1986}
1987
[email protected]46ba9082010-06-22 10:00:581988RenderViewHostDelegate::ContentSettings*
1989TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:551990 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:581991}
1992
[email protected]1f18184a2010-07-21 19:34:491993RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
1994 return GetSSLHelper();
1995}
1996
[email protected]fd571bb2010-03-19 01:23:541997AutomationResourceRoutingDelegate*
1998TabContents::GetAutomationResourceRoutingDelegate() {
1999 return delegate();
2000}
2001
[email protected]ced90ae12010-02-20 02:06:162002RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2003 return bookmark_drag_;
2004}
2005
2006void TabContents::SetBookmarkDragDelegate(
2007 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2008 bookmark_drag_ = bookmark_drag;
2009}
2010
[email protected]9fb83e82010-07-02 18:24:552011TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2012 return content_settings_delegate_.get();
2013}
2014
[email protected]93623c5d2009-12-10 21:40:322015RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462016 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512017}
2018
[email protected]57c6a652009-05-04 07:58:342019TabContents* TabContents::GetAsTabContents() {
2020 return this;
2021}
2022
[email protected]7b291f92009-08-14 05:43:532023ViewType::Type TabContents::GetRenderViewType() const {
2024 return ViewType::TAB_CONTENTS;
2025}
2026
2027int TabContents::GetBrowserWindowID() const {
2028 return controller().window_id().id();
2029}
2030
[email protected]420ae012009-04-24 05:16:322031void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062032 NotificationService::current()->Notify(
2033 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2034 Source<TabContents>(this),
2035 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322036 NavigationEntry* entry = controller_.GetActiveEntry();
2037 if (!entry)
2038 return;
2039
2040 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352041 // use the pending Web UI rather than any possibly existing committed one.
[email protected]7ade2732011-02-10 00:13:582042 if (render_manager_.pending_web_ui()) {
2043 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322044 }
2045
2046 if (entry->IsViewSourceMode()) {
2047 // Put the renderer in view source mode.
2048 render_view_host->Send(
2049 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2050 }
[email protected]0666aef2009-05-13 19:48:082051
2052 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322053}
2054
2055void TabContents::RenderViewReady(RenderViewHost* rvh) {
2056 if (rvh != render_view_host()) {
2057 // Don't notify the world, since this came from a renderer in the
2058 // background.
2059 return;
2060 }
2061
2062 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302063 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232064 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302065
2066 // Restore the focus to the tab (otherwise the focus will be on the top
2067 // window).
[email protected]484ae5912010-09-29 19:16:142068 if (was_crashed && !FocusLocationBarByDefault() &&
2069 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302070 Focus();
[email protected]484ae5912010-09-29 19:16:142071 }
[email protected]420ae012009-04-24 05:16:322072}
2073
[email protected]443b80e2010-12-14 00:42:232074void TabContents::RenderViewGone(RenderViewHost* rvh,
2075 base::TerminationStatus status,
2076 int error_code) {
[email protected]420ae012009-04-24 05:16:322077 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092078 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322079 return;
2080 if (rvh != render_view_host()) {
2081 // The pending page's RenderViewHost is gone.
2082 return;
2083 }
2084
2085 SetIsLoading(false, NULL);
2086 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232087 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322088
[email protected]ff9efc62010-02-18 22:10:542089 // Remove all infobars.
[email protected]ec8f51162011-02-08 04:20:402090 while (!infobar_delegates_.empty())
2091 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
[email protected]ff9efc62010-02-18 22:10:542092
[email protected]8e537302009-06-10 21:19:582093 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552094 // Only do this if we're not in browser shutdown, so that TabContents
2095 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2096 // visible do not flash a sad tab page.
2097 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:162098 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322099
2100 // Hide any visible hung renderer warning for this web contents' process.
[email protected]7ec6bef2011-02-26 02:22:292101 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:322102}
2103
[email protected]2e4633c2009-07-09 16:58:062104void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2105 NotificationService::current()->Notify(
2106 NotificationType::RENDER_VIEW_HOST_DELETED,
2107 Source<TabContents>(this),
2108 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482109 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062110}
2111
[email protected]420ae012009-04-24 05:16:322112void TabContents::DidNavigate(RenderViewHost* rvh,
2113 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372114 int extra_invalidate_flags = 0;
2115
2116 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352117 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372118
[email protected]420ae012009-04-24 05:16:322119 render_manager_.DidNavigateMainFrame(rvh);
2120
[email protected]20ede072009-10-06 00:28:352121 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372122 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372123 }
2124
[email protected]420ae012009-04-24 05:16:322125 // Update the site of the SiteInstance if it doesn't have one yet.
2126 if (!GetSiteInstance()->has_site())
2127 GetSiteInstance()->SetSite(params.url);
2128
2129 // Need to update MIME type here because it's referred to in
2130 // UpdateNavigationCommands() called by RendererDidNavigate() to
2131 // determine whether or not to enable the encoding menu.
2132 // It's updated only for the main frame. For a subframe,
2133 // RenderView::UpdateURL does not set params.contents_mime_type.
2134 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2135 // TODO(jungshik): Add a test for the encoding menu to avoid
2136 // regressing it again.
2137 if (PageTransition::IsMainFrame(params.transition))
2138 contents_mime_type_ = params.contents_mime_type;
2139
2140 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372141 bool did_navigate = controller_.RendererDidNavigate(
2142 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392143
[email protected]a9c0bfe2010-09-17 08:35:222144 // Send notification about committed provisional loads. This notification is
2145 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2146 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2147 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072148 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2149 // that is not recorded in the navigation history. For the purpose of
2150 // tracking navigation events, we treat this event as a sub frame navigation
2151 // event.
2152 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2153 ProvisionalLoadDetails load_details(
[email protected]b9e8ea62011-03-04 06:29:092154 is_main_frame, details.is_in_page, params.url, std::string(),
[email protected]dd0aafd2010-12-02 13:13:412155 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222156 load_details.set_transition_type(params.transition);
2157 // Whether or not a page transition was triggered by going backward or
2158 // forward in the history is only stored in the navigation controller's
2159 // entry list.
2160 if (did_navigate &&
2161 (controller_.GetActiveEntry()->transition_type() &
2162 PageTransition::FORWARD_BACK)) {
2163 load_details.set_transition_type(
2164 params.transition | PageTransition::FORWARD_BACK);
2165 }
2166 NotificationService::current()->Notify(
2167 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2168 Source<NavigationController>(&controller_),
2169 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222170 }
2171
[email protected]3e90d4a2009-07-03 17:38:392172 // Update history. Note that this needs to happen after the entry is complete,
2173 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582174 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392175 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582176 // URLs, we use a data: URL as the real value. We actually want to save the
2177 // about: URL to the history db and keep the data: URL hidden. This is what
2178 // the TabContents' URL getter does.
2179 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2180 CreateHistoryAddPageArgs(GetURL(), details, params));
2181 if (!delegate() ||
2182 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2183 details.type)) {
2184 UpdateHistoryForNavigation(add_page_args);
2185 }
[email protected]3e90d4a2009-07-03 17:38:392186 }
2187
[email protected]76543b92009-08-31 17:27:452188 if (!did_navigate)
2189 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322190
2191 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2192 // for the appropriate notification (best) or you can add it to
2193 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2194 // necessary, please).
2195
2196 // Run post-commit tasks.
2197 if (details.is_main_frame)
2198 DidNavigateMainFramePostCommit(details, params);
2199 DidNavigateAnyFramePostCommit(rvh, details, params);
2200}
2201
2202void TabContents::UpdateState(RenderViewHost* rvh,
2203 int32 page_id,
2204 const std::string& state) {
2205 DCHECK(rvh == render_view_host());
2206
2207 // We must be prepared to handle state updates for any page, these occur
2208 // when the user is scrolling and entering form data, as well as when we're
2209 // leaving a page, in which case our state may have already been moved to
2210 // the next page. The navigation controller will look up the appropriate
2211 // NavigationEntry and update it when it is notified via the delegate.
2212
2213 int entry_index = controller_.GetEntryIndexWithPageID(
2214 GetSiteInstance(), page_id);
2215 if (entry_index < 0)
2216 return;
2217 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2218
2219 if (state == entry->content_state())
2220 return; // Nothing to update.
2221 entry->set_content_state(state);
2222 controller_.NotifyEntryChanged(entry, entry_index);
2223}
2224
2225void TabContents::UpdateTitle(RenderViewHost* rvh,
2226 int32 page_id, const std::wstring& title) {
2227 // If we have a title, that's a pretty good indication that we've started
2228 // getting useful data.
2229 SetNotWaitingForResponse();
2230
2231 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482232 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582233 page_id);
[email protected]420ae012009-04-24 05:16:322234 if (!entry || !UpdateTitleForEntry(entry, title))
2235 return;
2236
2237 // Broadcast notifications when the UI should be updated.
2238 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032239 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322240}
2241
[email protected]420ae012009-04-24 05:16:322242void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402243 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322244 set_encoding(encoding);
2245}
2246
2247void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2248 if (delegate())
2249 delegate()->UpdateTargetURL(this, url);
2250}
2251
2252void TabContents::UpdateThumbnail(const GURL& url,
2253 const SkBitmap& bitmap,
2254 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442255 if (profile()->IsOffTheRecord())
2256 return;
2257
[email protected]420ae012009-04-24 05:16:322258 // Tell History about this thumbnail
[email protected]54097492f2011-01-18 08:32:072259 history::TopSites* ts = profile()->GetTopSites();
2260 if (ts)
2261 ts->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322262}
2263
[email protected]c4e98902010-06-01 10:20:142264void TabContents::UpdateInspectorSetting(const std::string& key,
2265 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052266 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082267}
2268
[email protected]45aafc92010-06-07 14:18:532269void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052270 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532271}
2272
[email protected]420ae012009-04-24 05:16:322273void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292274 // The UI may be in an event-tracking loop, such as between the
2275 // mouse-down and mouse-up in text selection or a button click.
2276 // Defer the close until after tracking is complete, so that we
2277 // don't free objects out from under the UI.
2278 // TODO(shess): This could probably be integrated with the
2279 // IsDoingDrag() test below. Punting for now because I need more
2280 // research to understand how this impacts platforms other than Mac.
2281 // TODO(shess): This could get more fine-grained. For instance,
2282 // closing a tab in another window while selecting text in the
2283 // current window's Omnibox should be just fine.
2284 if (view()->IsEventTracking()) {
2285 view()->CloseTabAfterEventTracking();
2286 return;
2287 }
2288
[email protected]24a4d1062009-07-10 23:10:422289 // If we close the tab while we're in the middle of a drag, we'll crash.
2290 // Instead, cancel the drag and close it as soon as the drag ends.
2291 if (view()->IsDoingDrag()) {
2292 view()->CancelDragAndCloseTab();
2293 return;
2294 }
2295
[email protected]420ae012009-04-24 05:16:322296 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2297 if (delegate() && rvh == render_view_host())
2298 delegate()->CloseContents(this);
2299}
2300
2301void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2302 if (delegate() && delegate()->IsPopup(this))
2303 delegate()->MoveContents(this, new_bounds);
2304}
2305
[email protected]7ab1e7d62009-10-14 23:32:012306void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322307 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492308
[email protected]de4761b2010-12-07 21:05:212309 if (delegate()) {
2310 bool is_print_preview_tab =
2311 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2312 if (content_restrictions_ || is_print_preview_tab) {
2313 content_restrictions_= is_print_preview_tab ?
2314 CONTENT_RESTRICTION_PRINT : 0;
2315 delegate()->ContentRestrictionsChanged(this);
2316 }
[email protected]9e823662010-10-13 23:36:002317 }
[email protected]3c9e1872010-11-18 16:17:492318
2319 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172320 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322321}
2322
[email protected]7ab1e7d62009-10-14 23:32:012323void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322324 scoped_ptr<LoadNotificationDetails> details;
2325
2326 NavigationEntry* entry = controller_.GetActiveEntry();
2327 // An entry may not exist for a stop when loading an initial blank page or
2328 // if an iframe injected by script into a blank page finishes loading.
2329 if (entry) {
[email protected]420ae012009-04-24 05:16:322330 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2331
2332 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542333 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322334 entry->transition_type(),
2335 elapsed,
2336 &controller_,
2337 controller_.GetCurrentEntryIndex()));
2338 }
2339
[email protected]420ae012009-04-24 05:16:322340 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492341
2342 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172343 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322344}
2345
[email protected]1a3c3cb2010-12-16 21:03:402346void TabContents::DidChangeLoadProgress(double progress) {
2347 if (delegate())
2348 delegate()->LoadProgressChanged(progress);
2349}
2350
[email protected]25497492010-09-11 15:15:082351void TabContents::DocumentOnLoadCompletedInMainFrame(
2352 RenderViewHost* render_view_host,
2353 int32 page_id) {
2354 NotificationService::current()->Notify(
2355 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2356 Source<TabContents>(this),
2357 Details<int>(&page_id));
2358}
2359
[email protected]420ae012009-04-24 05:16:322360void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2361 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:582362 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352363 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322364 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2365 // generated suggestions).
2366 //
[email protected]e0112912011-02-02 22:54:352367 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162368 // want web sites to see a referrer of "chrome://blah" (and some
2369 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322370 // send to the site), so we send no referrer.
2371 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:582372 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:322373 } else {
2374 OpenURL(url, referrer, disposition, PageTransition::LINK);
2375 }
2376}
2377
[email protected]1ee614862009-07-06 20:29:182378void TabContents::DomOperationResponse(const std::string& json_string,
2379 int automation_id) {
2380}
2381
[email protected]badcca352011-02-12 01:08:082382void TabContents::ProcessWebUIMessage(
[email protected]8b8e7c92010-08-19 18:05:562383 const ViewHostMsg_DomMessage_Params& params) {
[email protected]7ade2732011-02-10 00:13:582384 if (!render_manager_.web_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442385 // This can happen if someone uses window.open() to open an extension URL
2386 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562387 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322388 return;
2389 }
[email protected]badcca352011-02-12 01:08:082390 render_manager_.web_ui()->ProcessWebUIMessage(params);
[email protected]420ae012009-04-24 05:16:322391}
2392
2393void TabContents::ProcessExternalHostMessage(const std::string& message,
2394 const std::string& origin,
2395 const std::string& target) {
2396 if (delegate())
2397 delegate()->ForwardMessageToExternalHost(message, origin, target);
2398}
2399
[email protected]420ae012009-04-24 05:16:322400void TabContents::RunJavaScriptMessage(
2401 const std::wstring& message,
2402 const std::wstring& default_prompt,
2403 const GURL& frame_url,
2404 const int flags,
2405 IPC::Message* reply_msg,
2406 bool* did_suppress_message) {
2407 // Suppress javascript messages when requested and when inside a constrained
2408 // popup window (because that activates them and breaks them out of the
2409 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552410 // Also suppress messages when showing an interstitial. The interstitial is
2411 // shown over the previous page, we don't want the hidden page dialogs to
2412 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502413 bool suppress_this_message =
2414 suppress_javascript_messages_ ||
2415 showing_interstitial_page() ||
2416 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322417 if (delegate())
2418 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312419 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322420
2421 *did_suppress_message = suppress_this_message;
2422
2423 if (!suppress_this_message) {
2424 base::TimeDelta time_since_last_message(
2425 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2426 bool show_suppress_checkbox = false;
2427 // Show a checkbox offering to suppress further messages if this message is
2428 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2429 if (time_since_last_message <
[email protected]1698f612011-03-11 11:28:152430 base::TimeDelta::FromMilliseconds(
2431 chrome::kJavascriptMessageExpectedDelay))
[email protected]420ae012009-04-24 05:16:322432 show_suppress_checkbox = true;
2433
[email protected]d6ad7442010-09-05 19:06:522434 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2435 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322436 } else {
2437 // If we are suppressing messages, just reply as is if the user immediately
2438 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542439 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322440 }
2441}
2442
2443void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2444 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292445 if (delegate())
2446 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502447 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2448 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2449 std::wstring());
2450 return;
2451 }
[email protected]7ab1e7d62009-10-14 23:32:012452 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222453 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322454}
2455
[email protected]420ae012009-04-24 05:16:322456GURL TabContents::GetAlternateErrorPageURL() const {
2457 GURL url;
2458 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2459 if (profile()->IsOffTheRecord())
2460 return url;
2461
2462 PrefService* prefs = profile()->GetPrefs();
2463 DCHECK(prefs);
2464 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152465 url = google_util::AppendGoogleLocaleParam(
2466 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322467 url = google_util::AppendGoogleTLDParam(url);
2468 }
2469 return url;
2470}
2471
2472WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062473 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:582474 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:082475 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:582476 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:082477
[email protected]9beff752010-09-22 19:35:432478 // Force accelerated compositing and 2d canvas off for chrome: and
2479 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432480 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2481 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082482 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432483 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082484 }
2485
[email protected]39553442010-09-09 00:01:552486#if defined(OS_MACOSX)
2487 // Disable accelerated compositing if IOSurface's are not supported,
2488 // as is the case in 10.5.
2489 if (!IOSurfaceSupport::Initialize())
2490 web_prefs.accelerated_compositing_enabled = false;
2491#endif
2492
[email protected]447021c2010-09-08 21:29:082493 return web_prefs;
[email protected]420ae012009-04-24 05:16:322494}
2495
[email protected]7d472472011-01-22 01:30:252496void TabContents::OnUserGesture() {
2497 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
2498 DownloadRequestLimiter* limiter =
2499 g_browser_process->download_request_limiter();
2500 if (limiter)
2501 limiter->OnUserGesture(this);
2502 ExternalProtocolHandler::PermitLaunchUrl();
2503}
2504
[email protected]fa1cf0b82010-01-15 21:49:442505void TabContents::OnIgnoredUIEvent() {
2506 if (constrained_window_count()) {
2507 ConstrainedWindow* window = *constrained_window_begin();
2508 window->FocusConstrainedWindow();
2509 }
2510}
2511
[email protected]420ae012009-04-24 05:16:322512void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2513 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342514 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322515 // delivered to a pending RenderViewHost. We must first run the onunload
2516 // handler of the old RenderViewHost before we can allow it to proceed.
2517 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2518 new_request_id);
2519}
2520
[email protected]420ae012009-04-24 05:16:322521void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2522 bool is_during_unload) {
2523 if (is_during_unload) {
2524 // Hang occurred while firing the beforeunload/unload handler.
2525 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112526 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322527
2528 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2529 return;
2530
2531 // If the tab hangs in the beforeunload/unload handler there's really
2532 // nothing we can do to recover. Pretend the unload listeners have
2533 // all fired and close the tab. If the hang is in the beforeunload handler
2534 // then the user will not have the option of cancelling the close.
2535 Close(rvh);
2536 return;
2537 }
2538
[email protected]61b50092011-02-03 18:02:192539 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
2540 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]7ec6bef2011-02-26 02:22:292541 browser::ShowHungRendererDialog(this);
[email protected]61b50092011-02-03 18:02:192542 }
[email protected]420ae012009-04-24 05:16:322543}
2544
2545void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]7ec6bef2011-02-26 02:22:292546 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:322547}
2548
2549void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562550 net::LoadState load_state,
2551 uint64 upload_position,
2552 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322553 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562554 upload_position_ = upload_position;
2555 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292556 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192557 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292558 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:422559 load_state_host_ = WideToUTF16Hack(
2560 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:322561 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2562 SetNotWaitingForResponse();
2563 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502564 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322565}
2566
[email protected]1ee614862009-07-06 20:29:182567bool TabContents::IsExternalTabContainer() const {
2568 if (!delegate())
2569 return false;
2570
2571 return delegate()->IsExternalTabContainer();
2572}
2573
[email protected]1ee614862009-07-06 20:29:182574void TabContents::DidInsertCSS() {
2575 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322576}
2577
[email protected]546ae4e02010-12-08 14:57:192578void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:352579 NotificationService::current()->Notify(
2580 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:212581 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:192582 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:352583}
2584
[email protected]b75b8292010-10-01 07:28:252585void TabContents::UpdateZoomLimits(int minimum_percent,
2586 int maximum_percent,
2587 bool remember) {
2588 minimum_zoom_percent_ = minimum_percent;
2589 maximum_zoom_percent_ = maximum_percent;
2590 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382591}
2592
[email protected]7d472472011-01-22 01:30:252593void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:442594 if (delegate())
2595 delegate()->WorkerCrashed();
[email protected]7d472472011-01-22 01:30:252596}
2597
[email protected]420ae012009-04-24 05:16:322598void TabContents::BeforeUnloadFiredFromRenderManager(
2599 bool proceed,
2600 bool* proceed_to_fire_unload) {
2601 if (delegate())
2602 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2603}
2604
[email protected]3a3d47472010-07-15 21:03:542605void TabContents::DidStartLoadingFromRenderManager(
2606 RenderViewHost* render_view_host) {
2607 DidStartLoading();
2608}
2609
2610void TabContents::RenderViewGoneFromRenderManager(
2611 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232612 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2613 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542614}
2615
[email protected]420ae012009-04-24 05:16:322616void TabContents::UpdateRenderViewSizeForRenderManager() {
2617 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262618 gfx::Size size = view_->GetContainerSize();
2619 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2620 // here during container initialization and normal window size will be set
2621 // later. In case of tab duplication this resizing to 0x0 prevents setting
2622 // normal size later so just ignore it.
2623 if (!size.IsEmpty())
2624 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322625}
2626
[email protected]3a3d47472010-07-15 21:03:542627void TabContents::NotifySwappedFromRenderManager() {
2628 NotifySwapped();
2629}
2630
2631NavigationController& TabContents::GetControllerForRenderManager() {
2632 return controller();
2633}
2634
[email protected]d0980792011-02-13 19:41:402635WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]80a8fad2011-01-29 04:02:382636 return WebUIFactory::CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322637}
2638
2639NavigationEntry*
2640TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2641 return controller_.GetLastCommittedEntry();
2642}
2643
2644bool TabContents::CreateRenderViewForRenderManager(
2645 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322646 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522647
[email protected]674b3822010-08-04 04:02:512648 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322649 return false;
2650
2651 // Now that the RenderView has been created, we need to tell it its size.
2652 rwh_view->SetSize(view_->GetContainerSize());
2653
2654 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2655 render_view_host);
2656 return true;
2657}
2658
2659void TabContents::Observe(NotificationType type,
2660 const NotificationSource& source,
2661 const NotificationDetails& details) {
2662 switch (type.value) {
[email protected]420ae012009-04-24 05:16:322663 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512664 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322665 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2666 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2667 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:532668 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
2669 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:322670 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:172671 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
2672 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:322673 } else {
2674 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2675 }
2676 break;
2677 }
2678 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2679 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2680 break;
2681
2682 case NotificationType::NAV_ENTRY_COMMITTED: {
2683 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2684
2685 NavigationController::LoadCommittedDetails& committed_details =
2686 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2687 ExpireInfoBars(committed_details);
2688 break;
2689 }
2690
[email protected]d3ba77272009-09-03 00:06:092691#if defined(OS_LINUX)
2692 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542693 renderer_preferences_util::UpdateFromSystemSettings(
2694 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092695 render_view_host()->SyncRendererPrefs();
2696 break;
2697 }
2698#endif
2699
[email protected]6c32ce72010-03-08 05:18:062700 case NotificationType::USER_STYLE_SHEET_UPDATED:
2701 UpdateWebPreferences();
2702 break;
2703
[email protected]79580c62010-02-02 02:36:252704 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:452705 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:252706 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492707 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292708 if (entry)
[email protected]da0c8e92010-02-09 23:25:492709 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292710 if (settings_details.ptr()->update_all() ||
2711 settings_details.ptr()->pattern().Matches(entry_url)) {
2712 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232713 profile()->GetHostContentSettingsMap()->
2714 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252715 }
2716 break;
2717 }
2718
[email protected]e5adff72010-06-14 18:13:062719 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:572720 break;
[email protected]a888b29e62010-04-01 13:38:572721
2722 case NotificationType::EXTENSION_UNLOADED:
[email protected]a888b29e62010-04-01 13:38:572723 break;
[email protected]a888b29e62010-04-01 13:38:572724
[email protected]88152052010-10-01 04:05:182725 case NotificationType::GOOGLE_URL_UPDATED:
2726 UpdateAlternateErrorPageURL();
2727 break;
2728
[email protected]420ae012009-04-24 05:16:322729 default:
2730 NOTREACHED();
2731 }
2732}
[email protected]aacd7cc2009-09-02 14:51:102733
[email protected]9adb9692010-10-29 23:14:022734void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:082735 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432736
[email protected]a888b29e62010-04-01 13:38:572737 if (extension) {
[email protected]98aa0b52010-05-06 17:03:082738 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
2739 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:572740 extension,
[email protected]807871f2010-09-16 01:04:482741 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
2742 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:572743 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
2744 Extension::EXTENSION_ICON_SMALLISH),
2745 ImageLoadingTracker::CACHE);
2746 } else {
[email protected]98aa0b52010-05-06 17:03:082747 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:572748 }
2749}
2750
[email protected]9adb9692010-10-29 23:14:022751const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:002752 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:572753 if (!extensions_service)
2754 return NULL;
2755
[email protected]9adb9692010-10-29 23:14:022756 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:572757 return extension ?
2758 extension : extensions_service->GetExtensionByWebExtent(url);
2759}
2760
[email protected]bd5174d2011-03-11 01:02:562761void TabContents::OnImageLoaded(SkBitmap* image,
2762 const ExtensionResource& resource,
[email protected]a888b29e62010-04-01 13:38:572763 int index) {
2764 if (image) {
[email protected]98aa0b52010-05-06 17:03:082765 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:572766 NotifyNavigationStateChanged(INVALIDATE_TAB);
2767 }
2768}
2769
[email protected]beb440c2009-11-06 04:08:542770gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2771 return view_->GetTopLevelNativeWindow();
2772}
2773
2774void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2775 bool success,
2776 const std::wstring& prompt) {
2777 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2778 if (is_showing_before_unload_dialog_ && !success) {
2779 // If a beforeunload dialog is canceled, we need to stop the throbber from
2780 // spinning, since we forced it to start spinning in Navigate.
2781 DidStopLoading();
2782
2783 tab_close_start_time_ = base::TimeTicks();
2784 }
2785 is_showing_before_unload_dialog_ = false;
2786 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2787}
2788
2789void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2790 set_suppress_javascript_messages(suppress_message_boxes);
2791}
2792
[email protected]3a3d47472010-07-15 21:03:542793TabContents* TabContents::AsTabContents() {
2794 return this;
2795}
2796
2797ExtensionHost* TabContents::AsExtensionHost() {
2798 return NULL;
2799}
2800
[email protected]41fc0322009-09-04 22:23:402801void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102802 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2803}
[email protected]f45d2a72010-03-08 23:28:352804
2805void TabContents::SetAppIcon(const SkBitmap& app_icon) {
2806 app_icon_ = app_icon;
2807 NotifyNavigationStateChanged(INVALIDATE_TITLE);
2808}
[email protected]33f74972010-12-08 16:40:362809
2810void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2811 render_manager_.SwapInRenderViewHost(rvh);
2812}
2813
2814void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2815 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2816 rwh_view->SetSize(view()->GetContainerSize());
2817}
[email protected]e7d50892011-01-19 21:47:382818
[email protected]232a5812011-03-04 22:42:082819void TabContents::OnOnlineStateChanged(bool online) {
2820 render_view_host()->Send(new ViewMsg_NetworkStateChanged(
2821 render_view_host()->routing_id(), online));
2822}