blob: b4900ac172ab2ee74a2dabb97775d25958cf28c7 [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]eb15e24e2011-02-03 22:34:3446#include "chrome/browser/printing/print_preview_message_handler.h"
[email protected]dbeebd52010-11-16 20:34:1647#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0948#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3349#include "chrome/browser/profiles/profile.h"
[email protected]96d185d2009-04-24 03:28:5450#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3251#include "chrome/browser/renderer_preferences_util.h"
[email protected]fa685ff2011-02-17 19:47:1352#include "chrome/browser/safe_browsing/client_side_detection_host.h"
[email protected]c37e3b62010-01-22 00:15:1753#include "chrome/browser/sessions/session_types.h"
[email protected]a40f6e92011-03-04 23:30:2954#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4955#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]d54169e92011-01-21 09:19:5256#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1657#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3558#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]7ec6bef2011-02-26 02:22:2959#include "chrome/browser/ui/browser_dialogs.h"
[email protected]54ec6472010-04-09 19:39:5860#include "chrome/common/bindings_policy.h"
[email protected]1698f612011-03-11 11:28:1561#include "chrome/common/chrome_constants.h"
[email protected]35f7d212009-04-29 21:19:2762#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2163#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4964#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5765#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4866#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1467#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0968#include "chrome/common/extensions/url_pattern.h"
69#include "chrome/common/navigation_types.h"
70#include "chrome/common/net/url_request_context_getter.h"
initial.commit09911bf2008-07-26 23:55:2971#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3272#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0273#include "chrome/common/render_messages_params.h"
[email protected]96d185d2009-04-24 03:28:5474#include "chrome/common/url_constants.h"
[email protected]567812d2011-02-24 17:40:5075#include "content/browser/child_process_security_policy.h"
76#include "content/browser/host_zoom_map.h"
77#include "content/browser/in_process_webkit/session_storage_namespace.h"
[email protected]567812d2011-02-24 17:40:5078#include "content/browser/renderer_host/render_process_host.h"
79#include "content/browser/renderer_host/render_view_host.h"
80#include "content/browser/renderer_host/render_widget_host_view.h"
81#include "content/browser/renderer_host/resource_request_details.h"
82#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4483#include "content/browser/tab_contents/interstitial_page.h"
84#include "content/browser/tab_contents/navigation_entry.h"
85#include "content/browser/tab_contents/provisional_load_details.h"
86#include "content/browser/tab_contents/tab_contents_delegate.h"
87#include "content/browser/tab_contents/tab_contents_observer.h"
88#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]67fc0392011-02-25 02:56:5789#include "content/browser/webui/web_ui.h"
[email protected]7f070d42011-03-09 20:25:3290#include "content/common/notification_service.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]61d68ef12011-01-13 14:02:56103#if defined(OS_CHROMEOS)
104#include "chrome/browser/chromeos/locale_change_guard.h"
105#endif // defined(OS_CHROMEOS)
106
[email protected]420ae012009-04-24 05:16:32107// Cross-Site Navigations
108//
109// If a TabContents is told to navigate to a different web site (as determined
110// by SiteInstance), it will replace its current RenderViewHost with a new
111// RenderViewHost dedicated to the new SiteInstance. This works as follows:
112//
113// - Navigate determines whether the destination is cross-site, and if so,
114// it creates a pending_render_view_host_ and moves into the PENDING
115// RendererState.
116// - The pending RVH is "suspended," so that no navigation messages are sent to
117// its renderer until the onbeforeunload JavaScript handler has a chance to
118// run in the current RVH.
119// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
120// that it has a pending cross-site request. ResourceDispatcherHost will
121// check for this when the response arrives.
122// - The current RVH runs its onbeforeunload handler. If it returns false, we
123// cancel all the pending logic and go back to NORMAL. Otherwise we allow
124// the pending RVH to send the navigation request to its renderer.
125// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
126// checks CrossSiteRequestManager to see that the RVH responsible has a
127// pending cross-site request, and then installs a CrossSiteEventHandler.
128// - When RDH receives a response, the BufferedEventHandler determines whether
129// it is a download. If so, it sends a message to the new renderer causing
130// it to cancel the request, and the download proceeds in the download
131// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34132// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32133// doesn't affect any functionality.
134// - After RDH receives a response and determines that it is safe and not a
135// download, it pauses the response to first run the old page's onunload
136// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34137// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32138// to the current RVH.
139// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
140// the ResourceDispatcherHost, who unpauses the response. Data is then sent
141// to the pending RVH.
142// - The pending renderer sends a FrameNavigate message that invokes the
143// DidNavigate method. This replaces the current RVH with the
144// pending RVH and goes back to the NORMAL RendererState.
145
146namespace {
147
148// Amount of time we wait between when a key event is received and the renderer
149// is queried for its state and pushed to the NavigationEntry.
150const int kQueryStateDelay = 5000;
151
[email protected]6ebdc9b2010-09-27 16:55:57152const int kSyncWaitDelay = 40;
153
[email protected]420ae012009-04-24 05:16:32154// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51155const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32156 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17157 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32158 prefs::kWebKitJavaEnabled,
159 prefs::kWebKitJavascriptEnabled,
160 prefs::kWebKitLoadsImagesAutomatically,
161 prefs::kWebKitPluginsEnabled,
162 prefs::kWebKitUsesUniversalDetector,
[email protected]16480f62011-03-01 23:39:10163 prefs::kWebKitStandardFontFamily,
[email protected]420ae012009-04-24 05:16:32164 prefs::kWebKitSerifFontFamily,
165 prefs::kWebKitSansSerifFontFamily,
166 prefs::kWebKitFixedFontFamily,
167 prefs::kWebKitDefaultFontSize,
168 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13169 prefs::kWebKitMinimumFontSize,
170 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36171 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32172 prefs::kDefaultCharset
[email protected]420ae012009-04-24 05:16:32173};
174
175const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
176
[email protected]420ae012009-04-24 05:16:32177#if defined(OS_WIN)
178
179BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
180 // Note: erase is required to properly paint some widgets borders. This can
181 // be seen with textfields.
182 InvalidateRect(hwnd, NULL, TRUE);
183 return TRUE;
184}
185#endif
186
[email protected]5e369672009-11-03 23:48:30187ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16188 Profile* profile, const NavigationEntry& entry,
189 NavigationController::ReloadType reload_type) {
190 switch (reload_type) {
191 case NavigationController::RELOAD:
192 return ViewMsg_Navigate_Params::RELOAD;
193 case NavigationController::RELOAD_IGNORING_CACHE:
194 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
195 case NavigationController::NO_RELOAD:
196 break; // Fall through to rest of function.
197 }
[email protected]5e369672009-11-03 23:48:30198
199 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
200 profile->DidLastSessionExitCleanly())
201 return ViewMsg_Navigate_Params::RESTORE;
202
203 return ViewMsg_Navigate_Params::NORMAL;
204}
205
[email protected]876bc832010-09-07 16:29:54206void MakeNavigateParams(const NavigationEntry& entry,
207 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16208 NavigationController::ReloadType reload_type,
209 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34210 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54211 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00212 params->current_history_list_offset = controller.last_committed_entry_index();
213 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34214 params->url = entry.url();
215 params->referrer = entry.referrer();
216 params->transition = entry.transition_type();
217 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00218 params->navigation_type =
219 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34220 params->request_time = base::Time::Now();
221}
222
[email protected]420ae012009-04-24 05:16:32223} // namespace
224
[email protected]f4f50ef2011-01-21 19:01:19225
226// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32227
[email protected]420ae012009-04-24 05:16:32228TabContents::TabContents(Profile* profile,
229 SiteInstance* site_instance,
230 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07231 const TabContents* base_tab_contents,
232 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42233 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07234 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
235 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13236 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22237 TabContentsView::Create(this))),
238 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06239 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34240 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23241 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
242 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34243 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34244 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57245 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56246 upload_size_(0),
247 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57248 received_page_title_(false),
[email protected]c65e2f152010-10-14 15:30:40249 blocked_contents_(NULL),
250 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49251 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47252 displayed_insecure_content_(false),
[email protected]98aa0b52010-05-06 17:03:08253 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57254 capturing_contents_(false),
255 is_being_destroyed_(false),
256 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57257#if defined(OS_WIN)
258 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
259#endif
[email protected]c2e74fe82009-09-03 17:57:44260 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01261 is_showing_before_unload_dialog_(false),
[email protected]80a8fad2011-01-29 04:02:38262 opener_web_ui_type_(WebUIFactory::kNoWebUI),
[email protected]777a7b62010-05-11 13:28:16263 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38264 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25265 minimum_zoom_percent_(
266 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
267 maximum_zoom_percent_(
268 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00269 temporary_zoom_settings_(false),
[email protected]4850a7f2011-03-08 23:36:59270 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54271 renderer_preferences_util::UpdateFromSystemSettings(
272 &renderer_preferences_, profile);
273
[email protected]9fb83e82010-07-02 18:24:55274 content_settings_delegate_.reset(
275 new TabSpecificContentSettings(this, profile));
276
[email protected]12636df2009-09-28 22:32:21277 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32278
[email protected]34ac70502009-09-25 17:07:23279 // We have the initial size of the view be based on the size of the passed in
280 // tab contents (normally a tab from the same window).
281 view_->CreateView(base_tab_contents ?
282 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32283
284 // Register for notifications about all interested prefs change.
285 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28286 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32287 if (prefs) {
288 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28289 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32290 }
291
[email protected]420ae012009-04-24 05:16:32292 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
293 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09294#if defined(OS_LINUX)
295 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
296 NotificationService::AllSources());
297#endif
[email protected]420ae012009-04-24 05:16:32298
[email protected]6c32ce72010-03-08 05:18:06299 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
300 NotificationService::AllSources());
301
[email protected]79580c62010-02-02 02:36:25302 // Register for notifications about content setting changes.
303 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
304 NotificationService::AllSources());
305
[email protected]a888b29e62010-04-01 13:38:57306 // Listen for extension changes so we can update extension_for_current_page_.
307 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
308 NotificationService::AllSources());
309 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
310 NotificationService::AllSources());
[email protected]a888b29e62010-04-01 13:38:57311
[email protected]969182a2011-03-03 14:53:23312 // Listen for Google URL changes.
[email protected]88152052010-10-01 04:05:18313 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
314 NotificationService::AllSources());
315
[email protected]c8865482009-07-23 20:40:10316 // Set-up the showing of the omnibox search infobar if applicable.
317 if (OmniboxSearchHint::IsEnabled(profile))
318 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53319
[email protected]b5a1d11c2011-02-17 03:09:42320 // Can only add observers after render_manager_.Init() is called, since that's
321 // what sets up the render_view_host which TabContentObserver's constructor
322 // uses to get the routing_id.
323 AddObservers();
[email protected]332af7732009-03-11 13:21:35324}
initial.commit09911bf2008-07-26 23:55:29325
326TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32327 is_being_destroyed_ = true;
328
[email protected]bfe4c1582009-10-02 18:11:09329 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32330 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28331 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32332
[email protected]420ae012009-04-24 05:16:32333 NotifyDisconnected();
[email protected]7ec6bef2011-02-26 02:22:29334 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:32335
[email protected]420ae012009-04-24 05:16:32336 // First cleanly close all child windows.
337 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
338 // some of these to close. CloseWindows is async, so it might get called
339 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49340 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32341
[email protected]c65e2f152010-10-14 15:30:40342 // Close all blocked contents.
343 if (blocked_contents_)
344 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13345
[email protected]420ae012009-04-24 05:16:32346 // Notify any observer that have a reference on this tab contents.
347 NotificationService::current()->Notify(
348 NotificationType::TAB_CONTENTS_DESTROYED,
349 Source<TabContents>(this),
350 NotificationService::NoDetails());
351
[email protected]1e5e74f2009-05-27 20:55:12352 // Notify any lasting InfobarDelegates that have not yet been removed that
353 // whatever infobar they were handling in this TabContents has closed,
354 // because the TabContents is going away entirely.
355 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
356 // notification may trigger infobars calls that access their delegate. (and
357 // some implementations of InfoBarDelegate do delete themselves on
358 // InfoBarClosed()).
[email protected]ec8f51162011-02-08 04:20:40359 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]1e5e74f2009-05-27 20:55:12360 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
361 delegate->InfoBarClosed();
362 }
363 infobar_delegates_.clear();
364
[email protected]420ae012009-04-24 05:16:32365 // TODO(brettw) this should be moved to the view.
366#if defined(OS_WIN)
367 // If we still have a window handle, destroy it. GetNativeView can return
368 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42369 if (GetNativeView()) {
370 RenderViewHost* host = render_view_host();
371 if (host && host->view()) {
372 host->view()->WillWmDestroy();
373 }
[email protected]420ae012009-04-24 05:16:32374 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42375 }
[email protected]420ae012009-04-24 05:16:32376#endif
[email protected]7ab1e7d62009-10-14 23:32:01377
378 // OnCloseStarted isn't called in unit tests.
379 if (!tab_close_start_time_.is_null()) {
380 UMA_HISTOGRAM_TIMES("Tab.Close",
381 base::TimeTicks::Now() - tab_close_start_time_);
382 }
[email protected]b5a1d11c2011-02-17 03:09:42383
[email protected]07d490bc2011-03-07 17:05:26384 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08385
386 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
[email protected]b5a1d11c2011-02-17 03:09:42387}
388
389void TabContents::AddObservers() {
390 printing_.reset(new printing::PrintViewManager(this));
391 print_preview_.reset(new printing::PrintPreviewMessageHandler(this));
[email protected]34952d12011-03-14 19:45:13392 fav_icon_helper_.reset(new FaviconHelper(this));
[email protected]c4a9e932011-03-05 04:05:55393 autofill_manager_.reset(new AutofillManager(this));
[email protected]b5a1d11c2011-02-17 03:09:42394 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
[email protected]b5a1d11c2011-02-17 03:09:42395 desktop_notification_handler_.reset(
396 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
397 plugin_observer_.reset(new PluginObserver(this));
[email protected]fa685ff2011-02-17 19:47:13398 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost(
399 this));
[email protected]232a5812011-03-04 22:42:08400 net::NetworkChangeNotifier::AddOnlineStateObserver(this);
initial.commit09911bf2008-07-26 23:55:29401}
402
[email protected]724159a2010-12-30 01:11:18403bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]585b30362011-01-28 02:30:17404 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
405 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10406 while ((observer = it.GetNext()) != NULL)
407 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53408 return true;
[email protected]403415a2011-01-10 18:57:53409
[email protected]724159a2010-12-30 01:11:18410 bool handled = true;
411 bool message_is_ok = true;
412 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
413 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
414 OnDidStartProvisionalLoadForFrame)
415 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
416 OnDidRedirectProvisionalLoad)
417 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
418 OnDidFailProvisionalLoadWithError)
419 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
420 OnDidLoadResourceFromMemoryCache)
421 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
422 OnDidDisplayInsecureContent)
423 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
424 OnDidRunInsecureContent)
425 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
426 OnDocumentLoadedInFrame)
427 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17428 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
429 OnUpdateContentRestrictions)
430 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
431 OnPDFHasUnsupportedFeature)
[email protected]7d472472011-01-22 01:30:25432 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]7d472472011-01-22 01:30:25433 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo,
434 OnDidGetApplicationInfo)
435 IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication,
436 OnInstallApplication)
437 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
438 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated)
439 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions)
440 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined,
441 OnInstantSupportDetermined)
[email protected]724159a2010-12-30 01:11:18442 IPC_MESSAGE_UNHANDLED(handled = false)
443 IPC_END_MESSAGE_MAP_EX()
444
445 if (!message_is_ok) {
446 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
447 GetRenderProcessHost()->ReceivedBadMessage();
448 }
449
450 return handled;
451}
452
[email protected]13367f72009-07-08 16:39:02453// Returns true if contains content rendered by an extension.
454bool TabContents::HostsExtension() const {
455 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34456}
457
[email protected]1f18184a2010-07-21 19:34:49458TabContentsSSLHelper* TabContents::GetSSLHelper() {
459 if (ssl_helper_.get() == NULL)
460 ssl_helper_.reset(new TabContentsSSLHelper(this));
461 return ssl_helper_.get();
462}
463
[email protected]8cb5d5b2010-02-09 11:36:16464RenderProcessHost* TabContents::GetRenderProcessHost() const {
465 return render_manager_.current_host()->process();
466}
467
[email protected]9adb9692010-10-29 23:14:02468void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46469 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08470 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10471
[email protected]98aa0b52010-05-06 17:03:08472 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57473
[email protected]fca656c2010-02-10 20:30:10474 NotificationService::current()->Notify(
475 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
476 Source<TabContents>(this),
477 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49478}
479
[email protected]98aa0b52010-05-06 17:03:08480void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
481 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40482 return;
483
[email protected]eaa7dd182010-12-14 11:09:00484 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50485 if (!extension_service || !extension_service->is_ready())
486 return;
487
488 const Extension* extension =
489 extension_service->GetExtensionById(extension_app_id, false);
490 if (extension)
491 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40492}
493
[email protected]98aa0b52010-05-06 17:03:08494SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08495 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51496 return NULL;
497
[email protected]98aa0b52010-05-06 17:03:08498 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51499}
500
[email protected]d5f942ba2008-09-26 19:30:34501const GURL& TabContents::GetURL() const {
502 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57503 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54504 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34505}
506
[email protected]96d185d2009-04-24 03:28:54507const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55508 // Transient entries take precedence. They are used for interstitial pages
509 // that are shown on top of existing pages.
510 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23511 if (entry) {
512 return entry->GetTitleForDisplay(profile()->GetPrefs()->
513 GetString(prefs::kAcceptLanguages));
514 }
[email protected]7ade2732011-02-10 00:13:58515 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
516 render_manager_.pending_web_ui() : render_manager_.web_ui();
517 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54518 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55519 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54520 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35521 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58522 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54523 if (!title.empty())
524 return title;
525 }
526 }
527
528 // We use the title for the last committed entry rather than a pending
529 // navigation entry. For example, when the user types in a URL, we want to
530 // keep the old page's title until the new load has committed and we get a new
531 // title.
[email protected]96d185d2009-04-24 03:28:54532 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23533 if (entry) {
534 return entry->GetTitleForDisplay(profile()->GetPrefs()->
535 GetString(prefs::kAcceptLanguages));
536 }
[email protected]96d185d2009-04-24 03:28:54537 return EmptyString16();
538}
539
[email protected]d5f942ba2008-09-26 19:30:34540int32 TabContents::GetMaxPageID() {
541 if (GetSiteInstance())
542 return GetSiteInstance()->max_page_id();
543 else
544 return max_page_id_;
545}
546
547void TabContents::UpdateMaxPageID(int32 page_id) {
548 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34549 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34550 // testing.
551 if (GetSiteInstance())
552 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16553 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34554}
555
[email protected]96d185d2009-04-24 03:28:54556SiteInstance* TabContents::GetSiteInstance() const {
557 return render_manager_.current_host()->site_instance();
558}
559
[email protected]96d185d2009-04-24 03:28:54560bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15561 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54562 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15563 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01564 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54565 return true;
[email protected]8ab24cc2009-11-13 20:56:15566 }
[email protected]83e3895b2009-06-11 00:07:16567
[email protected]2b9a06402011-02-16 04:57:10568 // We always display the URL for non-WebUI URLs to prevent spoofing.
569 if (entry && !WebUIFactory::HasWebUIScheme(entry->url()))
570 return true;
571
[email protected]d0980792011-02-13 19:41:40572 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58573 if (web_ui)
574 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54575 return true;
576}
577
[email protected]9b488bda2011-03-15 14:42:27578SkBitmap TabContents::GetFavicon() const {
[email protected]d5f942ba2008-09-26 19:30:34579 // Like GetTitle(), we also want to use the favicon for the last committed
580 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57581 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47582 if (entry)
583 return entry->favicon().bitmap();
584
[email protected]ce3fa3c2009-04-20 19:55:57585 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34586 if (entry)
587 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34588 return SkBitmap();
589}
590
[email protected]0b303cc2009-09-28 22:35:15591bool TabContents::FavIconIsValid() const {
592 NavigationEntry* entry = controller_.GetTransientEntry();
593 if (entry)
594 return entry->favicon().is_valid();
595
596 entry = controller_.GetLastCommittedEntry();
597 if (entry)
598 return entry->favicon().is_valid();
599
600 return false;
601}
602
[email protected]96d185d2009-04-24 03:28:54603bool TabContents::ShouldDisplayFavIcon() {
604 // Always display a throbber during pending loads.
605 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
606 return true;
607
[email protected]d0980792011-02-13 19:41:40608 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58609 if (web_ui)
610 return !web_ui->hide_favicon();
[email protected]96d185d2009-04-24 03:28:54611 return true;
612}
613
[email protected]585b30362011-01-28 02:30:17614void TabContents::AddObserver(TabContentsObserver* observer) {
615 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49616}
617
[email protected]585b30362011-01-28 02:30:17618void TabContents::RemoveObserver(TabContentsObserver* observer) {
619 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49620}
621
[email protected]443b80e2010-12-14 00:42:23622void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
623 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34624 return;
625
[email protected]443b80e2010-12-14 00:42:23626 crashed_status_ = status;
627 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50628 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34629}
630
[email protected]744ef172009-10-16 21:53:46631void TabContents::PageActionStateChanged() {
632 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00633}
[email protected]ce5c4502009-05-06 16:46:11634
[email protected]d5f942ba2008-09-26 19:30:34635void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
636 if (delegate_)
637 delegate_->NavigationStateChanged(this, changed_flags);
638}
639
[email protected]96d185d2009-04-24 03:28:54640void TabContents::DidBecomeSelected() {
641 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16642 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
643 if (rwhv) {
644 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43645#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16646 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43647#endif
648 }
[email protected]96d185d2009-04-24 03:28:54649
[email protected]8cb5d5b2010-02-09 11:36:16650 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11651 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54652}
653
[email protected]a94454b2010-12-16 04:16:03654void TabContents::FadeForInstant(bool animate) {
[email protected]1b072562010-12-13 19:37:45655 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
656 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
657 if (rwhv)
[email protected]a94454b2010-12-16 04:16:03658 rwhv->SetVisuallyDeemphasized(&whitish, animate);
[email protected]1b072562010-12-13 19:37:45659}
660
661void TabContents::CancelInstantFade() {
662 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
663 if (rwhv)
664 rwhv->SetVisuallyDeemphasized(NULL, false);
665}
666
[email protected]96d185d2009-04-24 03:28:54667void TabContents::WasHidden() {
668 if (!capturing_contents()) {
669 // |render_view_host()| can be NULL if the user middle clicks a link to open
670 // a tab in then background, then closes the tab before selecting it. This
671 // is because closing the tab calls TabContents::Destroy(), which removes
672 // the |render_view_host()|; then when we actually destroy the window,
673 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16674 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
675 if (rwhv)
676 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54677 }
678
679 NotificationService::current()->Notify(
680 NotificationType::TAB_CONTENTS_HIDDEN,
681 Source<TabContents>(this),
682 NotificationService::NoDetails());
683}
684
[email protected]d5f942ba2008-09-26 19:30:34685void TabContents::Activate() {
686 if (delegate_)
687 delegate_->ActivateContents(this);
688}
689
[email protected]ea42e7782010-08-23 23:58:12690void TabContents::Deactivate() {
691 if (delegate_)
692 delegate_->DeactivateContents(this);
693}
694
[email protected]96d185d2009-04-24 03:28:54695void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16696 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
697 if (rwhv)
698 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54699}
700
701void TabContents::HideContents() {
702 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
703 // our superclass HideContents(), because some callers want to be very picky
704 // about the order in which these get called. In addition to making the code
705 // here practically impossible to understand, this also means we end up
706 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34707 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54708 WasHidden();
709}
710
[email protected]5aab5e22010-12-08 22:13:29711bool TabContents::NeedToFireBeforeUnload() {
712 // TODO(creis): Should we fire even for interstitial pages?
713 return notify_disconnection() &&
714 !showing_interstitial_page() &&
715 !render_view_host()->SuddenTerminationAllowed();
716}
717
[email protected]c0588052008-10-27 23:01:50718void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34719 WindowOpenDisposition disposition,
720 PageTransition::Type transition) {
721 if (delegate_)
[email protected]c0588052008-10-27 23:01:50722 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34723}
724
[email protected]1ccb3568d2010-02-19 10:51:16725bool TabContents::NavigateToPendingEntry(
726 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54727 return NavigateToEntry(*controller_.pending_entry(), reload_type);
728}
[email protected]96d185d2009-04-24 03:28:54729
[email protected]876bc832010-09-07 16:29:54730bool TabContents::NavigateToEntry(
731 const NavigationEntry& entry,
732 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54733 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
734 if (!dest_render_view_host)
735 return false; // Unable to create the desired render view host.
736
[email protected]770dd8b2010-05-24 18:11:39737 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
738 dest_render_view_host->EnablePreferredSizeChangedMode(
739 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
740 }
[email protected]9fb325e2010-05-06 18:23:24741
[email protected]80a8fad2011-01-29 04:02:38742 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07743 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58744 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]c09163a2011-02-15 00:05:55745 bool is_allowed_in_web_ui_renderer =
[email protected]80a8fad2011-01-29 04:02:38746 WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url());
[email protected]c09163a2011-02-15 00:05:55747 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
748 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58749
[email protected]96d185d2009-04-24 03:28:54750 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12751 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32752 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00753 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
754 dest_render_view_host,
755 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32756 }
[email protected]96d185d2009-04-24 03:28:54757
758 // Used for page load time metrics.
759 current_load_start_ = base::TimeTicks::Now();
760
761 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34762 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54763 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04764 if (delegate_) {
765 navigate_params.extra_headers =
766 delegate_->GetNavigationHeaders(navigate_params.url);
767 }
[email protected]056de2d2009-06-26 16:41:34768 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54769
770 if (entry.page_id() == -1) {
771 // HACK!! This code suppresses javascript: URLs from being added to
772 // session history, which is what we want to do for javascript: URLs that
773 // do not generate content. What we really need is a message from the
774 // renderer telling us that a new page was not created. The same message
775 // could be used for mailto: URLs and the like.
776 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
777 return false;
778 }
779
[email protected]3c9e1872010-11-18 16:17:49780 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:17781 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54782
[email protected]1ccb3568d2010-02-19 10:51:16783 if (reload_type != NavigationController::NO_RELOAD &&
784 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48785 FaviconService* favicon_service =
786 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
787 if (favicon_service)
788 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54789 }
790
[email protected]d5f942ba2008-09-26 19:30:34791 return true;
792}
793
[email protected]96d185d2009-04-24 03:28:54794void TabContents::Stop() {
795 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09796 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54797}
798
[email protected]96d185d2009-04-24 03:28:54799void TabContents::DisassociateFromPopupCount() {
800 render_view_host()->DisassociateFromPopupCount();
801}
802
803TabContents* TabContents::Clone() {
804 // We create a new SiteInstance so that the new tab won't share processes
805 // with the old one. This can be changed in the future if we need it to share
806 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32807 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54808 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07809 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54810 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08811 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08812 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54813 return tc;
814}
815
[email protected]4d677202009-07-19 07:37:12816void TabContents::ShowPageInfo(const GURL& url,
817 const NavigationEntry::SSLStatus& ssl,
818 bool show_history) {
819 if (!delegate_)
820 return;
821
[email protected]bb678332009-07-21 00:15:50822 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12823}
824
[email protected]ef0d04c2010-12-15 23:34:21825void TabContents::SaveFavicon() {
826 NavigationEntry* entry = controller_.GetActiveEntry();
827 if (!entry || entry->url().is_empty())
828 return;
829
830 // Make sure the page is in history, otherwise adding the favicon does
831 // nothing.
832 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
833 Profile::IMPLICIT_ACCESS);
834 if (!history)
835 return;
836 history->AddPageNoVisitForBookmark(entry->url());
837
838 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
839 Profile::IMPLICIT_ACCESS);
840 if (!service)
841 return;
842 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
843 if (!favicon.is_valid() || favicon.url().is_empty() ||
844 favicon.bitmap().empty()) {
845 return;
846 }
847 std::vector<unsigned char> image_data;
848 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
849 service->SetFavicon(entry->url(), favicon.url(), image_data);
850}
851
initial.commit09911bf2008-07-26 23:55:29852ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28853 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29854 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28855 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
[email protected]aed59602011-02-28 22:57:33856 AddConstrainedDialog(window);
857 return window;
858}
859
860void TabContents::AddConstrainedDialog(ConstrainedWindow* window) {
initial.commit09911bf2008-07-26 23:55:29861 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44862
863 if (child_windows_.size() == 1) {
864 window->ShowConstrainedWindow();
865 BlockTabContent(true);
866 }
initial.commit09911bf2008-07-26 23:55:29867}
868
[email protected]fa1cf0b82010-01-15 21:49:44869void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55870 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45871 // 70% opaque grey.
872 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55873 if (rwhv)
[email protected]1b072562010-12-13 19:37:45874 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44875 render_view_host()->set_ignore_input_events(blocked);
876 if (delegate_)
877 delegate_->SetTabContentBlocked(this, blocked);
878}
879
initial.commit09911bf2008-07-26 23:55:29880void TabContents::AddNewContents(TabContents* new_contents,
881 WindowOpenDisposition disposition,
882 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29883 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40884 if (all_contents_blocked_) {
885 if (!blocked_contents_)
886 blocked_contents_ = new BlockedContentContainer(this);
887 blocked_contents_->AddTabContents(
888 new_contents, disposition, initial_pos, user_gesture);
889 return;
890 }
891
initial.commit09911bf2008-07-26 23:55:29892 if (!delegate_)
893 return;
894
[email protected]35f7d212009-04-29 21:19:27895 if ((disposition == NEW_POPUP) && !user_gesture &&
896 !CommandLine::ForCurrentProcess()->HasSwitch(
897 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22898 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31899 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29900 delegate_->GetConstrainingContents(this)->AddPopup(
901 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31902 } else {
[email protected]0aa55312008-10-17 21:53:08903 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29904 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
905 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49906 NotificationService::current()->Notify(
907 NotificationType::TAB_ADDED,
908 Source<TabContentsDelegate>(delegate_),
909 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29910 }
initial.commit09911bf2008-07-26 23:55:29911
[email protected]8cc8d492010-02-02 10:40:49912 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:40913 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:29914}
915
[email protected]bcd9dc42010-01-23 16:38:18916bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:20917 bool is_js_code, const std::string& code_string,
918 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51919 RenderViewHost* host = render_view_host();
920 if (!host)
921 return false;
922
923 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:17924 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:51925 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35926}
927
[email protected]96d185d2009-04-24 03:28:54928void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49929 if (is_being_destroyed_)
930 return;
[email protected]9fb83e82010-07-02 18:24:55931 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49932 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40933 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:54934}
935
[email protected]5c9e97a2009-09-09 23:48:30936gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54937 return view_->GetContentNativeView();
938}
939
940gfx::NativeView TabContents::GetNativeView() const {
941 return view_->GetNativeView();
942}
943
944void TabContents::GetContainerBounds(gfx::Rect *out) const {
945 view_->GetContainerBounds(out);
946}
947
948void TabContents::Focus() {
949 view_->Focus();
950}
951
[email protected]90daadb42009-06-08 21:27:28952void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54953 if (showing_interstitial_page()) {
954 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
955 return;
956 }
[email protected]96d185d2009-04-24 03:28:54957 render_view_host()->SetInitialFocus(reverse);
958}
959
960bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40961 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58962 if (web_ui)
963 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43964 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25965 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43966 return true;
[email protected]96d185d2009-04-24 03:28:54967 return false;
968}
969
[email protected]a26dc362010-04-23 01:48:58970void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38971 if (delegate())
[email protected]a26dc362010-04-23 01:48:58972 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38973}
974
[email protected]616ed5a2008-11-21 22:27:24975void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32976 if (delegate_ && !delegate_->infobars_enabled()) {
977 delegate->InfoBarClosed();
978 return;
979 }
980
[email protected]616ed5a2008-11-21 22:27:24981 // Look through the existing InfoBarDelegates we have for a match. If we've
982 // already got one that matches, then we don't add the new one.
[email protected]ec8f51162011-02-08 04:20:40983 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:45984 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
985 // Tell the new infobar to close so that it can clean itself up.
986 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:24987 return;
[email protected]6d27a7b2009-12-18 23:25:45988 }
[email protected]616ed5a2008-11-21 22:27:24989 }
990
991 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56992 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:19993 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:56994 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24995
996 // Add ourselves as an observer for navigations the first time a delegate is
997 // added. We use this notification to expire InfoBars that need to expire on
998 // page transitions.
999 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561000 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571001 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241002 }
1003}
1004
1005void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321006 if (delegate_ && !delegate_->infobars_enabled()) {
1007 return;
1008 }
1009
[email protected]616ed5a2008-11-21 22:27:241010 std::vector<InfoBarDelegate*>::iterator it =
1011 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1012 if (it != infobar_delegates_.end()) {
1013 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561014 NotificationService::current()->Notify(
1015 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1016 Source<TabContents>(this),
1017 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241018
[email protected]f4f50ef2011-01-21 19:01:191019 infobar_delegates_.erase(it);
1020 // Remove ourselves as an observer if we are tracking no more InfoBars.
1021 if (infobar_delegates_.empty()) {
1022 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1023 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031024 }
[email protected]616ed5a2008-11-21 22:27:241025 }
1026}
[email protected]3edd9522009-03-04 22:19:411027
[email protected]f81821c2009-08-07 01:29:471028void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1029 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321030 if (delegate_ && !delegate_->infobars_enabled()) {
1031 new_delegate->InfoBarClosed();
1032 return;
1033 }
1034
[email protected]f81821c2009-08-07 01:29:471035 std::vector<InfoBarDelegate*>::iterator it =
1036 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1037 DCHECK(it != infobar_delegates_.end());
1038
1039 // Notify the container about the change of plans.
1040 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1041 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1042 old_delegate, new_delegate));
1043 NotificationService::current()->Notify(
1044 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1045 Source<TabContents>(this),
1046 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1047
[email protected]f4f50ef2011-01-21 19:01:191048 // Remove the old one.
1049 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:471050
1051 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081052 DCHECK(find(infobar_delegates_.begin(),
1053 infobar_delegates_.end(), new_delegate) ==
1054 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471055 infobar_delegates_.push_back(new_delegate);
1056}
1057
[email protected]20ede072009-10-06 00:28:351058bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271059 if (showing_interstitial_page())
1060 return false;
1061
[email protected]c8f74942010-09-03 10:04:141062 // Do not show bookmarks bar if bookmarks aren't enabled.
1063 if (!browser_defaults::bookmarks_enabled)
1064 return false;
1065
[email protected]d0980792011-02-13 19:41:401066 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:541067 // similar, but for non-first loads, we want to use the committed entry. This
1068 // is so the bookmarks bar disappears at the same time the page does.
1069 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:351070 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:581071 return (render_manager_.web_ui() == NULL) ?
1072 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541073 }
1074
1075 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:401076 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:541077 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:581078 if (render_manager_.pending_web_ui())
1079 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
1080 return (render_manager_.web_ui() == NULL) ?
1081 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541082}
1083
[email protected]3edd9522009-03-04 22:19:411084void TabContents::ToolbarSizeChanged(bool is_animating) {
1085 TabContentsDelegate* d = delegate();
1086 if (d)
1087 d->ToolbarSizeChanged(this, is_animating);
1088}
[email protected]616ed5a2008-11-21 22:27:241089
[email protected]fc6fb7fb2009-11-07 02:35:041090bool TabContents::CanDownload(int request_id) {
1091 TabContentsDelegate* d = delegate();
1092 if (d)
1093 return d->CanDownload(request_id);
1094 return true;
1095}
1096
[email protected]d5f942ba2008-09-26 19:30:341097void TabContents::OnStartDownload(DownloadItem* download) {
1098 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341099
1100 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311101 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341102
[email protected]5b928b62010-08-03 11:46:511103 if (tab_contents && tab_contents->delegate())
1104 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411105}
[email protected]3edd9522009-03-04 22:19:411106
[email protected]d5f942ba2008-09-26 19:30:341107void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371108 ConstrainedWindowList::iterator i(
1109 std::find(child_windows_.begin(), child_windows_.end(), window));
1110 bool removed_topmost_window = i == child_windows_.begin();
1111 if (i != child_windows_.end())
1112 child_windows_.erase(i);
1113 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441114 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371115 } else {
1116 if (removed_topmost_window)
1117 child_windows_[0]->ShowConstrainedWindow();
1118 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441119 }
[email protected]66ba4932009-06-04 19:22:131120}
[email protected]d5f942ba2008-09-26 19:30:341121
[email protected]c65e2f152010-10-14 15:30:401122void TabContents::WillCloseBlockedContentContainer(
1123 BlockedContentContainer* container) {
1124 DCHECK(blocked_contents_ == container);
1125 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491126 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341127}
1128
[email protected]d5f942ba2008-09-26 19:30:341129void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351130#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061131 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351132#endif
[email protected]d5f942ba2008-09-26 19:30:341133}
1134
[email protected]420ae012009-04-24 05:16:321135void TabContents::OnSavePage() {
1136 // If we can not save the page, try to download it.
1137 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1138 DownloadManager* dlm = profile()->GetDownloadManager();
1139 const GURL& current_page_url = GetURL();
1140 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221141 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321142 return;
1143 }
1144
1145 Stop();
1146
1147 // Create the save package and possibly prompt the user for the name to save
1148 // the page as. The user prompt is an asynchronous operation that runs on
1149 // another thread.
[email protected]b5a1d11c2011-02-17 03:09:421150 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321151 save_package_->GetSaveInfo();
1152}
1153
1154// Used in automated testing to bypass prompting the user for file names.
1155// Instead, the names and paths are hard coded rather than running them through
1156// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111157bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321158 SavePackage::SavePackageType save_type) {
1159 // Stop the page from navigating.
1160 Stop();
1161
[email protected]b5a1d11c2011-02-17 03:09:421162 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591163 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321164}
1165
[email protected]89d6e6e2009-12-03 23:06:511166void TabContents::EmailPageLocation() {
1167 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1168 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1169 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1170 title + "&body=%0A%0A" + page_url;
1171 platform_util::OpenExternal(GURL(mailto));
1172}
1173
[email protected]420ae012009-04-24 05:16:321174void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161175 if (CommandLine::ForCurrentProcess()->HasSwitch(
1176 switches::kEnablePrintPreview)) {
1177 if (showing_interstitial_page())
1178 return;
[email protected]83a58a22011-02-05 03:44:481179
1180 printing::PrintPreviewTabController* tab_controller =
[email protected]01884622011-03-08 01:48:461181 printing::PrintPreviewTabController::GetInstance();
[email protected]83a58a22011-02-05 03:44:481182 if (!tab_controller)
1183 return;
1184 tab_controller->GetOrCreatePreviewTab(this, controller().window_id().id());
[email protected]dbeebd52010-11-16 20:34:161185 } else {
1186 PrintNow();
1187 }
[email protected]420ae012009-04-24 05:16:321188}
1189
1190bool TabContents::PrintNow() {
1191 // We can't print interstitial page for now.
1192 if (showing_interstitial_page())
1193 return false;
1194
1195 return render_view_host()->PrintPages();
1196}
1197
[email protected]82270452009-06-19 15:58:011198void TabContents::PrintingDone(int document_cookie, bool success) {
1199 render_view_host()->PrintingDone(document_cookie, success);
1200}
1201
[email protected]420ae012009-04-24 05:16:321202bool TabContents::IsActiveEntry(int32 page_id) {
1203 NavigationEntry* active_entry = controller_.GetActiveEntry();
1204 return (active_entry != NULL &&
1205 active_entry->site_instance() == GetSiteInstance() &&
1206 active_entry->page_id() == page_id);
1207}
1208
[email protected]b2fe07d12010-02-09 14:38:081209void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161210 set_encoding(encoding);
1211 render_view_host()->SetPageEncoding(encoding);
1212}
1213
[email protected]b2fe07d12010-02-09 14:38:081214void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161215 reset_encoding();
1216 render_view_host()->ResetPageEncodingToDefault();
1217}
1218
1219void TabContents::WindowMoveOrResizeStarted() {
1220 render_view_host()->WindowMoveOrResizeStarted();
1221}
1222
[email protected]c65e2f152010-10-14 15:30:401223void TabContents::SetAllContentsBlocked(bool value) {
1224 if (all_contents_blocked_ == value)
1225 return;
1226
1227 all_contents_blocked_ = value;
1228 if (!all_contents_blocked_ && blocked_contents_) {
1229 std::vector<TabContents*> blocked;
1230 blocked_contents_->GetBlockedContents(&blocked);
1231 for (size_t i = 0; i < blocked.size(); ++i)
1232 blocked_contents_->LaunchForContents(blocked[i]);
1233 }
1234}
1235
[email protected]3f8eb7f2009-10-02 23:58:051236void TabContents::LogNewTabTime(const std::string& event_name) {
1237 // Not all new tab pages get timed. In those cases, we don't have a
1238 // new_tab_start_time_.
1239 if (new_tab_start_time_.is_null())
1240 return;
1241
1242 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441243 MetricEventDurationDetails details(event_name,
1244 static_cast<int>(duration.InMilliseconds()));
1245
[email protected]7ab1e7d62009-10-14 23:32:011246 if (event_name == "Tab.NewTabScriptStart") {
1247 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1248 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1249 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1250 } else if (event_name == "Tab.NewTabOnload") {
1251 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051252 // The new tab page has finished loading; reset it.
1253 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441254 } else {
1255 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051256 }
[email protected]84abba62009-10-07 17:01:441257 NotificationService::current()->Notify(
1258 NotificationType::METRIC_EVENT_DURATION,
1259 Source<TabContents>(this),
1260 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051261}
1262
[email protected]7ab1e7d62009-10-14 23:32:011263void TabContents::OnCloseStarted() {
1264 if (tab_close_start_time_.is_null())
1265 tab_close_start_time_ = base::TimeTicks::Now();
1266}
1267
[email protected]46624bf2010-06-09 16:04:191268bool TabContents::ShouldAcceptDragAndDrop() const {
1269#if defined(OS_CHROMEOS)
1270 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1271 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201272 if (delegate() && delegate()->IsPopup(this))
1273 return false;
1274 return true;
[email protected]46624bf2010-06-09 16:04:191275#else
1276 return true;
1277#endif
1278}
1279
[email protected]7813bd72011-02-05 02:19:341280void TabContents::SystemDragEnded() {
1281 if (render_view_host())
1282 render_view_host()->DragSourceSystemDragEnded();
1283 if (delegate())
1284 delegate()->DragEnded();
1285}
1286
[email protected]ec0b6c42010-08-26 03:16:581287void TabContents::UpdateHistoryForNavigation(
1288 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1289 if (profile()->IsOffTheRecord())
1290 return;
1291
1292 // Add to history service.
1293 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1294 if (hs)
1295 hs->AddPage(*add_page_args);
1296}
1297
1298void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1299 if (profile()->IsOffTheRecord())
1300 return;
1301
1302 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1303 if (hs)
1304 hs->SetPageTitle(entry.virtual_url(), entry.title());
1305}
1306
[email protected]d0b8d092010-10-25 04:05:171307double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251308 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1309 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171310 return 0;
[email protected]b75b8292010-10-01 07:28:251311
1312 double zoom_level;
1313 if (temporary_zoom_settings_) {
1314 zoom_level = zoom_map->GetTemporaryZoomLevel(
1315 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1316 } else {
1317 zoom_level = zoom_map->GetZoomLevel(GetURL());
1318 }
[email protected]d0b8d092010-10-25 04:05:171319 return zoom_level;
1320}
[email protected]b75b8292010-10-01 07:28:251321
[email protected]d0b8d092010-10-25 04:05:171322int TabContents::GetZoomPercent(bool* enable_increment,
1323 bool* enable_decrement) {
1324 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251325 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171326 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251327 *enable_decrement = percent > minimum_zoom_percent_;
1328 *enable_increment = percent < maximum_zoom_percent_;
1329 return percent;
1330}
1331
[email protected]3c733bde2010-12-21 19:56:311332void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501333 if (!delegate_)
1334 return;
1335
1336 NavigationEntry* active_entry = controller().GetActiveEntry();
1337 if (!active_entry)
1338 return;
1339
1340 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121341}
1342
[email protected]932b7a12011-03-09 12:50:271343void TabContents::ViewFrameSource(const GURL& url,
1344 const std::string& content_state) {
1345 if (!delegate_)
1346 return;
1347
1348 delegate_->ViewSourceForFrame(this, url, content_state);
1349}
1350
[email protected]724159a2010-12-30 01:11:181351void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1352 bool is_main_frame,
1353 const GURL& url) {
1354 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1355 GURL validated_url(url);
1356 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1357 GetRenderProcessHost()->id(), &validated_url);
1358
1359 ProvisionalLoadDetails details(
1360 is_main_frame,
1361 controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091362 validated_url, std::string(), is_error_page, frame_id);
[email protected]724159a2010-12-30 01:11:181363 NotificationService::current()->Notify(
1364 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1365 Source<NavigationController>(&controller_),
1366 Details<ProvisionalLoadDetails>(&details));
1367 if (is_main_frame) {
1368 // If we're displaying a network error page do not reset the content
1369 // settings delegate's cookies so the user has a chance to modify cookie
1370 // settings.
1371 if (!is_error_page)
1372 content_settings_delegate_->ClearCookieSpecificContentSettings();
1373 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]e7d50892011-01-19 21:47:381374
[email protected]4850a7f2011-03-08 23:36:591375 // Notify observers about the provisional change in the main frame URL.
1376 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1377 OnProvisionalChangeToMainFrameUrl(url));
[email protected]724159a2010-12-30 01:11:181378 }
1379}
1380
1381void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1382 const GURL& source_url,
1383 const GURL& target_url) {
1384 NavigationEntry* entry;
1385 if (page_id == -1)
1386 entry = controller_.pending_entry();
1387 else
1388 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1389 if (!entry || entry->url() != source_url)
1390 return;
1391 entry->set_url(target_url);
[email protected]e7d50892011-01-19 21:47:381392
[email protected]4850a7f2011-03-08 23:36:591393 // Notify observers about the provisional change in the main frame URL.
1394 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1395 OnProvisionalChangeToMainFrameUrl(target_url));
[email protected]724159a2010-12-30 01:11:181396}
1397
1398void TabContents::OnDidFailProvisionalLoadWithError(
1399 int64 frame_id,
1400 bool is_main_frame,
1401 int error_code,
1402 const GURL& url,
1403 bool showing_repost_interstitial) {
1404 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1405 << ", error_code: " << error_code
1406 << " is_main_frame: " << is_main_frame
1407 << " showing_repost_interstitial: " << showing_repost_interstitial
1408 << " frame_id: " << frame_id;
1409 GURL validated_url(url);
1410 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1411 GetRenderProcessHost()->id(), &validated_url);
1412
1413 if (net::ERR_ABORTED == error_code) {
1414 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1415 // This means that the interstitial won't be torn down properly, which is
1416 // bad. But if we have an interstitial, go back to another tab type, and
1417 // then load the same interstitial again, we could end up getting the first
1418 // interstitial's "failed" message (as a result of the cancel) when we're on
1419 // the second one.
1420 //
1421 // We can't tell this apart, so we think we're tearing down the current page
1422 // which will cause a crash later one. There is also some code in
1423 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1424 // out because of this problem.
1425 //
1426 // http://code.google.com/p/chromium/issues/detail?id=2855
1427 // Because this will not tear down the interstitial properly, if "back" is
1428 // back to another tab type, the interstitial will still be somewhat alive
1429 // in the previous tab type. If you navigate somewhere that activates the
1430 // tab with the interstitial again, you'll see a flash before the new load
1431 // commits of the interstitial page.
1432 if (showing_interstitial_page()) {
1433 LOG(WARNING) << "Discarding message during interstitial.";
1434 return;
1435 }
1436
1437 // This will discard our pending entry if we cancelled the load (e.g., if we
1438 // decided to download the file instead of load it). Only discard the
1439 // pending entry if the URLs match, otherwise the user initiated a navigate
1440 // before the page loaded so that the discard would discard the wrong entry.
1441 NavigationEntry* pending_entry = controller_.pending_entry();
1442 if (pending_entry && pending_entry->url() == validated_url) {
1443 controller_.DiscardNonCommittedEntries();
1444 // Update the URL display.
1445 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1446 }
1447
1448 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1449 }
1450
1451 // Send out a notification that we failed a provisional load with an error.
1452 ProvisionalLoadDetails details(
1453 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091454 validated_url, std::string(), false, frame_id);
[email protected]724159a2010-12-30 01:11:181455 details.set_error_code(error_code);
1456
1457 NotificationService::current()->Notify(
1458 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1459 Source<NavigationController>(&controller_),
1460 Details<ProvisionalLoadDetails>(&details));
1461}
1462
1463void TabContents::OnDidLoadResourceFromMemoryCache(
1464 const GURL& url,
[email protected]724159a2010-12-30 01:11:181465 const std::string& security_info) {
1466 static base::StatsCounter cache("WebKit.CacheHit");
1467 cache.Increment();
1468
1469 // Send out a notification that we loaded a resource from our memory cache.
1470 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1471 SSLManager::DeserializeSecurityInfo(security_info,
1472 &cert_id, &cert_status,
1473 &security_bits,
1474 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161475 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1476 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181477
1478 NotificationService::current()->Notify(
1479 NotificationType::LOAD_FROM_MEMORY_CACHE,
1480 Source<NavigationController>(&controller_),
1481 Details<LoadFromMemoryCacheDetails>(&details));
1482}
1483
1484void TabContents::OnDidDisplayInsecureContent() {
1485 displayed_insecure_content_ = true;
1486 SSLManager::NotifySSLInternalStateChanged();
1487}
1488
1489void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021490 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231491 LOG(INFO) << security_origin << " ran insecure content from "
1492 << target_url.possibly_invalid_spec();
[email protected]724159a2010-12-30 01:11:181493 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1494}
1495
1496void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1497 controller_.DocumentLoadedInFrame();
1498 NotificationService::current()->Notify(
1499 NotificationType::FRAME_DOM_CONTENT_LOADED,
1500 Source<NavigationController>(&controller_),
1501 Details<int64>(&frame_id));
1502}
1503
1504void TabContents::OnDidFinishLoad(int64 frame_id) {
1505 NotificationService::current()->Notify(
1506 NotificationType::FRAME_DID_FINISH_LOAD,
1507 Source<NavigationController>(&controller_),
1508 Details<int64>(&frame_id));
1509}
1510
[email protected]c8f73ab2011-01-22 00:05:171511void TabContents::OnUpdateContentRestrictions(int restrictions) {
1512 content_restrictions_ = restrictions;
1513 delegate()->ContentRestrictionsChanged(this);
1514}
1515
1516void TabContents::OnPDFHasUnsupportedFeature() {
1517 PDFHasUnsupportedFeature(this);
1518}
1519
[email protected]96d185d2009-04-24 03:28:541520// Notifies the RenderWidgetHost instance about the fact that the page is
1521// loading, or done loading and calls the base implementation.
1522void TabContents::SetIsLoading(bool is_loading,
1523 LoadNotificationDetails* details) {
1524 if (is_loading == is_loading_)
1525 return;
1526
1527 if (!is_loading) {
1528 load_state_ = net::LOAD_STATE_IDLE;
1529 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561530 upload_size_ = 0;
1531 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541532 }
1533
1534 render_manager_.SetIsLoading(is_loading);
1535
1536 is_loading_ = is_loading;
1537 waiting_for_response_ = is_loading;
1538
[email protected]6ebdc9b2010-09-27 16:55:571539 if (delegate_)
1540 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351541 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541542
1543 NotificationType type = is_loading ? NotificationType::LOAD_START :
1544 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111545 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541546 if (details)
1547 det = Details<LoadNotificationDetails>(details);
1548 NotificationService::current()->Notify(type,
1549 Source<NavigationController>(&controller_),
1550 det);
1551}
1552
[email protected]b6c874582009-05-08 19:38:311553void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291554 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061555 // A page can't spawn popups (or do anything else, either) until its load
1556 // commits, so when we reach here, the popup was spawned by the
1557 // NavigationController's last committed entry, not the active entry. For
1558 // example, if a page opens a popup in an onunload() handler, then the active
1559 // entry is the page to be loaded as we navigate away from the unloading
1560 // page. For this reason, we can't use GetURL() to get the opener URL,
1561 // because it returns the active entry.
1562 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1563 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1564
1565 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491566 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091567 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491568 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1569 } else {
[email protected]c65e2f152010-10-14 15:30:401570 if (!blocked_contents_)
1571 blocked_contents_ = new BlockedContentContainer(this);
1572 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1573 true);
[email protected]55126132010-08-19 14:53:281574 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1575 std::string());
[email protected]8cc8d492010-02-02 10:40:491576 }
[email protected]b9681312008-11-07 00:08:261577}
[email protected]616ed5a2008-11-21 22:27:241578
[email protected]616ed5a2008-11-21 22:27:241579void TabContents::ExpireInfoBars(
1580 const NavigationController::LoadCommittedDetails& details) {
1581 // Only hide InfoBars when the user has done something that makes the main
1582 // frame load. We don't want various automatic or subframe navigations making
1583 // it disappear.
1584 if (!details.is_user_initiated_main_frame_load())
1585 return;
1586
[email protected]ec8f51162011-02-08 04:20:401587 // NOTE: It is not safe to change the following code to count upwards or use
1588 // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
1589 // list.
1590 for (size_t i = infobar_count(); i > 0; --i) {
1591 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
[email protected]f86a07022008-11-25 01:06:051592 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241593 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241594 }
1595}
[email protected]fdd61c62009-04-22 19:22:571596
[email protected]d0980792011-02-13 19:41:401597WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581598 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541599 // that goes along with it to control the basic flags. For example, we want to
1600 // show the pending URL in the URL bar, so we want the display_url flag to
1601 // be from the pending entry.
1602 //
1603 // The confusion comes because there are multiple possibilities for the
1604 // initial load in a tab as a side effect of the way the RenderViewHostManager
1605 // works.
1606 //
[email protected]e0112912011-02-02 22:54:351607 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541608 // the pending one, and we want it to apply here.
1609 //
1610 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1611 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581612 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351613 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541614 //
1615 // This condition handles all of these cases:
1616 //
1617 // - First load in first tab: no committed nav entry + pending nav entry +
1618 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351619 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541620 //
1621 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351622 // no pending Web UI:
1623 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541624 //
1625 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351626 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541627 //
1628 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351629 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541630 if (controller_.pending_entry() &&
1631 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581632 render_manager_.pending_web_ui()))
1633 return render_manager_.pending_web_ui();
1634 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541635}
[email protected]420ae012009-04-24 05:16:321636
1637void TabContents::DidNavigateMainFramePostCommit(
1638 const NavigationController::LoadCommittedDetails& details,
1639 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]80a8fad2011-01-29 04:02:381640 if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) {
1641 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441642 // that opened the window, as long as both renderers have the same
1643 // privileges.
[email protected]80a8fad2011-01-29 04:02:381644 if (opener_web_ui_type_ ==
1645 WebUIFactory::GetWebUIType(profile(), GetURL())) {
[email protected]7ade2732011-02-10 00:13:581646 WebUI* web_ui = WebUIFactory::CreateWebUIForURL(this, GetURL());
1647 // web_ui might be NULL if the URL refers to a non-existent extension.
1648 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401649 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581650 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441651 }
1652 }
[email protected]80a8fad2011-01-29 04:02:381653 opener_web_ui_type_ = WebUIFactory::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441654 }
1655
[email protected]420ae012009-04-24 05:16:321656 if (details.is_user_initiated_main_frame_load()) {
1657 // Clear the status bubble. This is a workaround for a bug where WebKit
1658 // doesn't let us know that the cursor left an element during a
1659 // transition (this is also why the mouse cursor remains as a hand after
1660 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1661 // clear the bubble when a user navigates to a named anchor in the same
1662 // page.
1663 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321664 }
1665
[email protected]420ae012009-04-24 05:16:321666 // Allow the new page to set the title again.
1667 received_page_title_ = false;
1668
1669 // Get the favicon, either from history or request it from the net.
[email protected]34952d12011-03-14 19:45:131670 fav_icon_helper_->FetchFavicon(details.entry->url());
[email protected]420ae012009-04-24 05:16:321671
[email protected]0de80162010-02-03 04:52:351672 // Clear all page actions, blocked content notifications and browser actions
1673 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141674 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:001675 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:081676 if (service) {
1677 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571678 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081679 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521680 if (browser_action) {
1681 browser_action->ClearAllValuesForTab(controller().session_id().id());
1682 NotificationService::current()->Notify(
1683 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571684 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521685 NotificationService::NoDetails());
1686 }
[email protected]92c6f9b92009-10-24 04:35:081687
[email protected]5d246db22009-10-27 06:17:571688 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521689 service->extensions()->at(i)->page_action();
1690 if (page_action) {
1691 page_action->ClearAllValuesForTab(controller().session_id().id());
1692 PageActionStateChanged();
1693 }
[email protected]92c6f9b92009-10-24 04:35:081694 }
[email protected]aece2c7f2009-08-27 20:43:171695 }
[email protected]0de80162010-02-03 04:52:351696
1697 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401698 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341699 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401700 blocked_contents_->Destroy();
1701 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351702 }
1703
1704 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411705 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551706 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471707
1708 // Once the main frame is navigated, we're no longer considered to have
1709 // displayed insecure content.
1710 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171711 }
[email protected]ce5c4502009-05-06 16:46:111712
[email protected]8cc8d492010-02-02 10:40:491713 // Close constrained windows if necessary.
1714 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1715 details.previous_url, details.entry->url()))
1716 CloseConstrainedWindows();
1717
[email protected]3c9e1872010-11-18 16:17:491718 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171719 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491720 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321721}
1722
1723void TabContents::DidNavigateAnyFramePostCommit(
1724 RenderViewHost* render_view_host,
1725 const NavigationController::LoadCommittedDetails& details,
1726 const ViewHostMsg_FrameNavigate_Params& params) {
1727 // If we navigate, start showing messages again. This does nothing to prevent
1728 // a malicious script from spamming messages, since the script could just
1729 // reload the page to stop blocking.
1730 suppress_javascript_messages_ = false;
1731
[email protected]3c9e1872010-11-18 16:17:491732 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171733 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491734 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551735
1736 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581737 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321738}
1739
[email protected]8cc8d492010-02-02 10:40:491740void TabContents::CloseConstrainedWindows() {
1741 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]aed59602011-02-28 22:57:331742 // To ensure that we iterate over every element in child_windows_ we
1743 // need to use a copy of child_windows_. Otherwise if
1744 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
1745 // skipping some elements.
1746 ConstrainedWindowList child_windows_copy(child_windows_);
1747 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
1748 it != child_windows_copy.end(); ++it) {
1749 ConstrainedWindow* window = *it;
[email protected]fa1cf0b82010-01-15 21:49:441750 if (window) {
[email protected]420ae012009-04-24 05:16:321751 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441752 BlockTabContent(false);
1753 }
[email protected]420ae012009-04-24 05:16:321754 }
1755}
1756
[email protected]420ae012009-04-24 05:16:321757void TabContents::UpdateAlternateErrorPageURL() {
1758 GURL url = GetAlternateErrorPageURL();
1759 render_view_host()->SetAlternateErrorPageURL(url);
1760}
1761
1762void TabContents::UpdateWebPreferences() {
1763 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1764}
1765
[email protected]d0b8d092010-10-25 04:05:171766void TabContents::UpdateZoomLevel() {
1767 render_view_host()->SetZoomLevel(GetZoomLevel());
1768}
1769
[email protected]420ae012009-04-24 05:16:321770void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1771 RenderViewHost* rvh) {
1772 // If we are creating a RVH for a restored controller, then we might
1773 // have more page IDs than the SiteInstance's current max page ID. We must
1774 // make sure that the max page ID is larger than any restored page ID.
1775 // Note that it is ok for conflicting page IDs to exist in another tab
1776 // (i.e., NavigationController), but if any page ID is larger than the max,
1777 // the back/forward list will get confused.
1778 int max_restored_page_id = controller_.max_restored_page_id();
1779 if (max_restored_page_id > 0) {
1780 int curr_max_page_id = site_instance->max_page_id();
1781 if (max_restored_page_id > curr_max_page_id) {
1782 // Need to update the site instance immediately.
1783 site_instance->UpdateMaxPageID(max_restored_page_id);
1784
1785 // Also tell the renderer to update its internal representation. We
1786 // need to reserve enough IDs to make all restored page IDs less than
1787 // the max.
1788 if (curr_max_page_id < 0)
1789 curr_max_page_id = 0;
1790 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1791 }
1792 }
1793}
1794
[email protected]ec0b6c42010-08-26 03:16:581795scoped_refptr<history::HistoryAddPageArgs>
1796TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541797 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471798 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321799 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581800 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1801 new history::HistoryAddPageArgs(
1802 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1803 params.redirects, params.transition, history::SOURCE_BROWSED,
1804 details.did_replace_entry));
1805 if (PageTransition::IsMainFrame(params.transition) &&
1806 virtual_url != params.url) {
1807 // Hack on the "virtual" URL so that it will appear in history. For some
1808 // types of URLs, we will display a magic URL that is different from where
1809 // the page is actually navigated. We want the user to see in history what
1810 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1811 // only applies to the main frame, as the virtual URL doesn't apply to
1812 // sub-frames.
1813 add_page_args->url = virtual_url;
1814 if (!add_page_args->redirects.empty())
1815 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321816 }
[email protected]ec0b6c42010-08-26 03:16:581817 return add_page_args;
[email protected]420ae012009-04-24 05:16:321818}
1819
1820bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1821 const std::wstring& title) {
1822 // For file URLs without a title, use the pathname instead. In the case of a
1823 // synthesized title, we don't want the update to count toward the "one set
1824 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251825 string16 final_title;
[email protected]420ae012009-04-24 05:16:321826 bool explicit_set;
1827 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251828 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321829 explicit_set = false; // Don't count synthetic titles toward the set limit.
1830 } else {
[email protected]e53668962010-06-23 15:35:251831 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321832 explicit_set = true;
1833 }
1834
[email protected]e53668962010-06-23 15:35:251835 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321836 return false; // Nothing changed, don't bother.
1837
[email protected]e53668962010-06-23 15:35:251838 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321839
[email protected]ec0b6c42010-08-26 03:16:581840 if (!received_page_title_) {
1841 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321842 received_page_title_ = explicit_set;
1843 }
1844
1845 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251846 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321847
[email protected]cbc0e1b2010-04-12 18:33:041848 NotificationService::current()->Notify(
1849 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1850 Source<TabContents>(this),
1851 NotificationService::NoDetails());
1852
[email protected]420ae012009-04-24 05:16:321853 return true;
1854}
1855
1856void TabContents::NotifySwapped() {
1857 // After sending out a swap notification, we need to send a disconnect
1858 // notification so that clients that pick up a pointer to |this| can NULL the
1859 // pointer. See Bug 1230284.
1860 notify_disconnection_ = true;
1861 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341862 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221863 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321864 NotificationService::NoDetails());
1865}
1866
1867void TabContents::NotifyConnected() {
1868 notify_disconnection_ = true;
1869 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341870 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221871 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321872 NotificationService::NoDetails());
1873}
1874
1875void TabContents::NotifyDisconnected() {
1876 if (!notify_disconnection_)
1877 return;
1878
1879 notify_disconnection_ = false;
1880 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341881 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221882 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321883 NotificationService::NoDetails());
1884}
1885
[email protected]7d472472011-01-22 01:30:251886void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541887 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1888 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1889 if (!entry)
1890 return;
1891 // Note that we don't call NavigationController::GotToOffset() as we don't
1892 // want to create a pending navigation entry (it might end up lingering
1893 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:521894 entry->set_transition_type(entry->transition_type() |
1895 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:541896 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
1897 }
[email protected]bf5c2ff392009-07-08 16:24:331898}
1899
[email protected]38789d82010-11-17 06:03:441900void TabContents::OnDidGetApplicationInfo(int32 page_id,
1901 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511902 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331903
[email protected]ed5431872009-11-17 08:39:511904 if (delegate())
1905 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331906}
1907
[email protected]bb461532010-11-26 21:50:231908void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
1909 if (delegate())
1910 delegate()->OnInstallApplication(this, info);
1911}
1912
[email protected]a2cf65eb2010-01-18 08:20:381913void TabContents::OnPageContents(const GURL& url,
[email protected]a2cf65eb2010-01-18 08:20:381914 int32 page_id,
[email protected]e5106202010-06-11 21:12:361915 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:101916 const std::string& language,
1917 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:381918 // Don't index any https pages. People generally don't want their bank
1919 // accounts, etc. indexed on their computer, especially since some of these
1920 // things are not marked cachable.
1921 // TODO(brettw) we may want to consider more elaborate heuristics such as
1922 // the cachability of the page. We may also want to consider subframes (this
1923 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271924 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1925 // content indexing for chromeos in some future releases.
1926#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381927 if (!url.SchemeIsSecure()) {
1928 Profile* p = profile();
1929 if (p && !p->IsOffTheRecord()) {
1930 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1931 if (hs)
1932 hs->SetPageContents(url, contents);
1933 }
1934 }
[email protected]ccd40a52010-05-11 16:15:271935#endif
[email protected]a8a81292010-01-21 00:32:451936
[email protected]1c57b7b2010-07-12 17:38:101937 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:451938
1939 std::string lang = language;
1940 NotificationService::current()->Notify(
1941 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151942 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451943 Details<std::string>(&lang));
[email protected]d54169e92011-01-21 09:19:521944
1945 // Generate the thumbnail here if the in-browser thumbnailing is enabled.
1946 if (CommandLine::ForCurrentProcess()->HasSwitch(
1947 switches::kEnableInBrowserThumbnailing)) {
1948 ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url);
1949 }
[email protected]a2cf65eb2010-01-18 08:20:381950}
1951
[email protected]7e0831b2010-02-01 08:45:151952void TabContents::OnPageTranslated(int32 page_id,
1953 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:161954 const std::string& translated_lang,
1955 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:551956 language_state_.set_current_language(translated_lang);
1957 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:161958 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:151959 NotificationService::current()->Notify(
1960 NotificationType::PAGE_TRANSLATED,
1961 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:161962 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:151963}
1964
[email protected]ce833282010-11-04 15:48:391965void TabContents::OnSetSuggestions(
1966 int32 page_id,
[email protected]1c9c7fb2011-03-11 16:38:381967 const std::vector<std::string>& suggestions,
1968 InstantCompleteBehavior behavior) {
[email protected]15d9c0c2010-09-10 22:36:261969 if (delegate())
[email protected]1c9c7fb2011-03-11 16:38:381970 delegate()->OnSetSuggestions(page_id, suggestions, behavior);
[email protected]ce833282010-11-04 15:48:391971}
1972
1973void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
1974 if (delegate())
1975 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:261976}
1977
[email protected]dcd5b332010-08-11 08:55:181978void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:561979 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241980 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:561981}
1982
[email protected]8d3347f2009-07-09 22:00:211983RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321984 return view_.get();
1985}
1986
[email protected]8d3347f2009-07-09 22:00:211987RenderViewHostDelegate::RendererManagement*
1988TabContents::GetRendererManagementDelegate() {
1989 return &render_manager_;
1990}
1991
[email protected]46ba9082010-06-22 10:00:581992RenderViewHostDelegate::ContentSettings*
1993TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:551994 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:581995}
1996
[email protected]1f18184a2010-07-21 19:34:491997RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
1998 return GetSSLHelper();
1999}
2000
[email protected]fd571bb2010-03-19 01:23:542001AutomationResourceRoutingDelegate*
2002TabContents::GetAutomationResourceRoutingDelegate() {
2003 return delegate();
2004}
2005
[email protected]ced90ae12010-02-20 02:06:162006RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2007 return bookmark_drag_;
2008}
2009
2010void TabContents::SetBookmarkDragDelegate(
2011 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2012 bookmark_drag_ = bookmark_drag;
2013}
2014
[email protected]9fb83e82010-07-02 18:24:552015TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2016 return content_settings_delegate_.get();
2017}
2018
[email protected]93623c5d2009-12-10 21:40:322019RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462020 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512021}
2022
[email protected]57c6a652009-05-04 07:58:342023TabContents* TabContents::GetAsTabContents() {
2024 return this;
2025}
2026
[email protected]7b291f92009-08-14 05:43:532027ViewType::Type TabContents::GetRenderViewType() const {
2028 return ViewType::TAB_CONTENTS;
2029}
2030
2031int TabContents::GetBrowserWindowID() const {
2032 return controller().window_id().id();
2033}
2034
[email protected]420ae012009-04-24 05:16:322035void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062036 NotificationService::current()->Notify(
2037 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2038 Source<TabContents>(this),
2039 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322040 NavigationEntry* entry = controller_.GetActiveEntry();
2041 if (!entry)
2042 return;
2043
2044 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352045 // use the pending Web UI rather than any possibly existing committed one.
[email protected]7ade2732011-02-10 00:13:582046 if (render_manager_.pending_web_ui()) {
2047 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322048 }
2049
2050 if (entry->IsViewSourceMode()) {
2051 // Put the renderer in view source mode.
2052 render_view_host->Send(
2053 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2054 }
[email protected]0666aef2009-05-13 19:48:082055
2056 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322057}
2058
2059void TabContents::RenderViewReady(RenderViewHost* rvh) {
2060 if (rvh != render_view_host()) {
2061 // Don't notify the world, since this came from a renderer in the
2062 // background.
2063 return;
2064 }
2065
2066 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302067 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232068 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302069
2070 // Restore the focus to the tab (otherwise the focus will be on the top
2071 // window).
[email protected]484ae5912010-09-29 19:16:142072 if (was_crashed && !FocusLocationBarByDefault() &&
2073 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302074 Focus();
[email protected]484ae5912010-09-29 19:16:142075 }
[email protected]420ae012009-04-24 05:16:322076}
2077
[email protected]443b80e2010-12-14 00:42:232078void TabContents::RenderViewGone(RenderViewHost* rvh,
2079 base::TerminationStatus status,
2080 int error_code) {
[email protected]420ae012009-04-24 05:16:322081 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092082 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322083 return;
2084 if (rvh != render_view_host()) {
2085 // The pending page's RenderViewHost is gone.
2086 return;
2087 }
2088
2089 SetIsLoading(false, NULL);
2090 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232091 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322092
[email protected]ff9efc62010-02-18 22:10:542093 // Remove all infobars.
[email protected]ec8f51162011-02-08 04:20:402094 while (!infobar_delegates_.empty())
2095 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
[email protected]ff9efc62010-02-18 22:10:542096
[email protected]8e537302009-06-10 21:19:582097 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552098 // Only do this if we're not in browser shutdown, so that TabContents
2099 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2100 // visible do not flash a sad tab page.
2101 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:162102 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322103
2104 // Hide any visible hung renderer warning for this web contents' process.
[email protected]7ec6bef2011-02-26 02:22:292105 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:322106}
2107
[email protected]2e4633c2009-07-09 16:58:062108void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2109 NotificationService::current()->Notify(
2110 NotificationType::RENDER_VIEW_HOST_DELETED,
2111 Source<TabContents>(this),
2112 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482113 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062114}
2115
[email protected]420ae012009-04-24 05:16:322116void TabContents::DidNavigate(RenderViewHost* rvh,
2117 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372118 int extra_invalidate_flags = 0;
2119
2120 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352121 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372122
[email protected]420ae012009-04-24 05:16:322123 render_manager_.DidNavigateMainFrame(rvh);
2124
[email protected]20ede072009-10-06 00:28:352125 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372126 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372127 }
2128
[email protected]420ae012009-04-24 05:16:322129 // Update the site of the SiteInstance if it doesn't have one yet.
2130 if (!GetSiteInstance()->has_site())
2131 GetSiteInstance()->SetSite(params.url);
2132
2133 // Need to update MIME type here because it's referred to in
2134 // UpdateNavigationCommands() called by RendererDidNavigate() to
2135 // determine whether or not to enable the encoding menu.
2136 // It's updated only for the main frame. For a subframe,
2137 // RenderView::UpdateURL does not set params.contents_mime_type.
2138 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2139 // TODO(jungshik): Add a test for the encoding menu to avoid
2140 // regressing it again.
2141 if (PageTransition::IsMainFrame(params.transition))
2142 contents_mime_type_ = params.contents_mime_type;
2143
2144 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372145 bool did_navigate = controller_.RendererDidNavigate(
2146 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392147
[email protected]a9c0bfe2010-09-17 08:35:222148 // Send notification about committed provisional loads. This notification is
2149 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2150 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2151 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072152 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2153 // that is not recorded in the navigation history. For the purpose of
2154 // tracking navigation events, we treat this event as a sub frame navigation
2155 // event.
2156 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2157 ProvisionalLoadDetails load_details(
[email protected]b9e8ea62011-03-04 06:29:092158 is_main_frame, details.is_in_page, params.url, std::string(),
[email protected]dd0aafd2010-12-02 13:13:412159 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222160 load_details.set_transition_type(params.transition);
2161 // Whether or not a page transition was triggered by going backward or
2162 // forward in the history is only stored in the navigation controller's
2163 // entry list.
2164 if (did_navigate &&
2165 (controller_.GetActiveEntry()->transition_type() &
2166 PageTransition::FORWARD_BACK)) {
2167 load_details.set_transition_type(
2168 params.transition | PageTransition::FORWARD_BACK);
2169 }
2170 NotificationService::current()->Notify(
2171 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2172 Source<NavigationController>(&controller_),
2173 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222174 }
2175
[email protected]3e90d4a2009-07-03 17:38:392176 // Update history. Note that this needs to happen after the entry is complete,
2177 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582178 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392179 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582180 // URLs, we use a data: URL as the real value. We actually want to save the
2181 // about: URL to the history db and keep the data: URL hidden. This is what
2182 // the TabContents' URL getter does.
2183 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2184 CreateHistoryAddPageArgs(GetURL(), details, params));
2185 if (!delegate() ||
2186 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2187 details.type)) {
2188 UpdateHistoryForNavigation(add_page_args);
2189 }
[email protected]3e90d4a2009-07-03 17:38:392190 }
2191
[email protected]76543b92009-08-31 17:27:452192 if (!did_navigate)
2193 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322194
2195 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2196 // for the appropriate notification (best) or you can add it to
2197 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2198 // necessary, please).
2199
2200 // Run post-commit tasks.
2201 if (details.is_main_frame)
2202 DidNavigateMainFramePostCommit(details, params);
2203 DidNavigateAnyFramePostCommit(rvh, details, params);
2204}
2205
2206void TabContents::UpdateState(RenderViewHost* rvh,
2207 int32 page_id,
2208 const std::string& state) {
2209 DCHECK(rvh == render_view_host());
2210
2211 // We must be prepared to handle state updates for any page, these occur
2212 // when the user is scrolling and entering form data, as well as when we're
2213 // leaving a page, in which case our state may have already been moved to
2214 // the next page. The navigation controller will look up the appropriate
2215 // NavigationEntry and update it when it is notified via the delegate.
2216
2217 int entry_index = controller_.GetEntryIndexWithPageID(
2218 GetSiteInstance(), page_id);
2219 if (entry_index < 0)
2220 return;
2221 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2222
2223 if (state == entry->content_state())
2224 return; // Nothing to update.
2225 entry->set_content_state(state);
2226 controller_.NotifyEntryChanged(entry, entry_index);
2227}
2228
2229void TabContents::UpdateTitle(RenderViewHost* rvh,
2230 int32 page_id, const std::wstring& title) {
2231 // If we have a title, that's a pretty good indication that we've started
2232 // getting useful data.
2233 SetNotWaitingForResponse();
2234
2235 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482236 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582237 page_id);
[email protected]420ae012009-04-24 05:16:322238 if (!entry || !UpdateTitleForEntry(entry, title))
2239 return;
2240
2241 // Broadcast notifications when the UI should be updated.
2242 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032243 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322244}
2245
[email protected]420ae012009-04-24 05:16:322246void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402247 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322248 set_encoding(encoding);
2249}
2250
2251void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2252 if (delegate())
2253 delegate()->UpdateTargetURL(this, url);
2254}
2255
2256void TabContents::UpdateThumbnail(const GURL& url,
2257 const SkBitmap& bitmap,
2258 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442259 if (profile()->IsOffTheRecord())
2260 return;
2261
[email protected]420ae012009-04-24 05:16:322262 // Tell History about this thumbnail
[email protected]54097492f2011-01-18 08:32:072263 history::TopSites* ts = profile()->GetTopSites();
2264 if (ts)
2265 ts->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322266}
2267
[email protected]c4e98902010-06-01 10:20:142268void TabContents::UpdateInspectorSetting(const std::string& key,
2269 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052270 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082271}
2272
[email protected]45aafc92010-06-07 14:18:532273void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052274 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532275}
2276
[email protected]420ae012009-04-24 05:16:322277void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292278 // The UI may be in an event-tracking loop, such as between the
2279 // mouse-down and mouse-up in text selection or a button click.
2280 // Defer the close until after tracking is complete, so that we
2281 // don't free objects out from under the UI.
2282 // TODO(shess): This could probably be integrated with the
2283 // IsDoingDrag() test below. Punting for now because I need more
2284 // research to understand how this impacts platforms other than Mac.
2285 // TODO(shess): This could get more fine-grained. For instance,
2286 // closing a tab in another window while selecting text in the
2287 // current window's Omnibox should be just fine.
2288 if (view()->IsEventTracking()) {
2289 view()->CloseTabAfterEventTracking();
2290 return;
2291 }
2292
[email protected]24a4d1062009-07-10 23:10:422293 // If we close the tab while we're in the middle of a drag, we'll crash.
2294 // Instead, cancel the drag and close it as soon as the drag ends.
2295 if (view()->IsDoingDrag()) {
2296 view()->CancelDragAndCloseTab();
2297 return;
2298 }
2299
[email protected]420ae012009-04-24 05:16:322300 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2301 if (delegate() && rvh == render_view_host())
2302 delegate()->CloseContents(this);
2303}
2304
2305void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2306 if (delegate() && delegate()->IsPopup(this))
2307 delegate()->MoveContents(this, new_bounds);
2308}
2309
[email protected]7ab1e7d62009-10-14 23:32:012310void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322311 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492312
[email protected]de4761b2010-12-07 21:05:212313 if (delegate()) {
2314 bool is_print_preview_tab =
2315 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2316 if (content_restrictions_ || is_print_preview_tab) {
2317 content_restrictions_= is_print_preview_tab ?
2318 CONTENT_RESTRICTION_PRINT : 0;
2319 delegate()->ContentRestrictionsChanged(this);
2320 }
[email protected]9e823662010-10-13 23:36:002321 }
[email protected]3c9e1872010-11-18 16:17:492322
2323 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172324 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322325}
2326
[email protected]7ab1e7d62009-10-14 23:32:012327void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322328 scoped_ptr<LoadNotificationDetails> details;
2329
2330 NavigationEntry* entry = controller_.GetActiveEntry();
2331 // An entry may not exist for a stop when loading an initial blank page or
2332 // if an iframe injected by script into a blank page finishes loading.
2333 if (entry) {
[email protected]420ae012009-04-24 05:16:322334 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2335
2336 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542337 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322338 entry->transition_type(),
2339 elapsed,
2340 &controller_,
2341 controller_.GetCurrentEntryIndex()));
2342 }
2343
[email protected]420ae012009-04-24 05:16:322344 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492345
2346 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172347 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322348}
2349
[email protected]1a3c3cb2010-12-16 21:03:402350void TabContents::DidChangeLoadProgress(double progress) {
2351 if (delegate())
2352 delegate()->LoadProgressChanged(progress);
2353}
2354
[email protected]25497492010-09-11 15:15:082355void TabContents::DocumentOnLoadCompletedInMainFrame(
2356 RenderViewHost* render_view_host,
2357 int32 page_id) {
2358 NotificationService::current()->Notify(
2359 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2360 Source<TabContents>(this),
2361 Details<int>(&page_id));
2362}
2363
[email protected]420ae012009-04-24 05:16:322364void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2365 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:582366 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352367 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322368 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2369 // generated suggestions).
2370 //
[email protected]e0112912011-02-02 22:54:352371 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162372 // want web sites to see a referrer of "chrome://blah" (and some
2373 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322374 // send to the site), so we send no referrer.
2375 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:582376 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:322377 } else {
2378 OpenURL(url, referrer, disposition, PageTransition::LINK);
2379 }
2380}
2381
[email protected]1ee614862009-07-06 20:29:182382void TabContents::DomOperationResponse(const std::string& json_string,
2383 int automation_id) {
2384}
2385
[email protected]badcca352011-02-12 01:08:082386void TabContents::ProcessWebUIMessage(
[email protected]8b8e7c92010-08-19 18:05:562387 const ViewHostMsg_DomMessage_Params& params) {
[email protected]7ade2732011-02-10 00:13:582388 if (!render_manager_.web_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442389 // This can happen if someone uses window.open() to open an extension URL
2390 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562391 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322392 return;
2393 }
[email protected]badcca352011-02-12 01:08:082394 render_manager_.web_ui()->ProcessWebUIMessage(params);
[email protected]420ae012009-04-24 05:16:322395}
2396
2397void TabContents::ProcessExternalHostMessage(const std::string& message,
2398 const std::string& origin,
2399 const std::string& target) {
2400 if (delegate())
2401 delegate()->ForwardMessageToExternalHost(message, origin, target);
2402}
2403
[email protected]420ae012009-04-24 05:16:322404void TabContents::RunJavaScriptMessage(
2405 const std::wstring& message,
2406 const std::wstring& default_prompt,
2407 const GURL& frame_url,
2408 const int flags,
2409 IPC::Message* reply_msg,
2410 bool* did_suppress_message) {
2411 // Suppress javascript messages when requested and when inside a constrained
2412 // popup window (because that activates them and breaks them out of the
2413 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552414 // Also suppress messages when showing an interstitial. The interstitial is
2415 // shown over the previous page, we don't want the hidden page dialogs to
2416 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502417 bool suppress_this_message =
2418 suppress_javascript_messages_ ||
2419 showing_interstitial_page() ||
2420 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322421 if (delegate())
2422 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312423 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322424
2425 *did_suppress_message = suppress_this_message;
2426
2427 if (!suppress_this_message) {
2428 base::TimeDelta time_since_last_message(
2429 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2430 bool show_suppress_checkbox = false;
2431 // Show a checkbox offering to suppress further messages if this message is
2432 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2433 if (time_since_last_message <
[email protected]1698f612011-03-11 11:28:152434 base::TimeDelta::FromMilliseconds(
2435 chrome::kJavascriptMessageExpectedDelay))
[email protected]420ae012009-04-24 05:16:322436 show_suppress_checkbox = true;
2437
[email protected]d6ad7442010-09-05 19:06:522438 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2439 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322440 } else {
2441 // If we are suppressing messages, just reply as is if the user immediately
2442 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542443 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322444 }
2445}
2446
2447void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2448 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292449 if (delegate())
2450 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502451 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2452 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2453 std::wstring());
2454 return;
2455 }
[email protected]7ab1e7d62009-10-14 23:32:012456 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222457 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322458}
2459
[email protected]420ae012009-04-24 05:16:322460GURL TabContents::GetAlternateErrorPageURL() const {
2461 GURL url;
2462 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2463 if (profile()->IsOffTheRecord())
2464 return url;
2465
2466 PrefService* prefs = profile()->GetPrefs();
2467 DCHECK(prefs);
2468 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152469 url = google_util::AppendGoogleLocaleParam(
2470 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322471 url = google_util::AppendGoogleTLDParam(url);
2472 }
2473 return url;
2474}
2475
2476WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062477 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:582478 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:082479 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:582480 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:082481
[email protected]9beff752010-09-22 19:35:432482 // Force accelerated compositing and 2d canvas off for chrome: and
2483 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432484 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2485 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082486 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432487 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082488 }
2489
[email protected]39553442010-09-09 00:01:552490#if defined(OS_MACOSX)
2491 // Disable accelerated compositing if IOSurface's are not supported,
2492 // as is the case in 10.5.
2493 if (!IOSurfaceSupport::Initialize())
2494 web_prefs.accelerated_compositing_enabled = false;
2495#endif
2496
[email protected]447021c2010-09-08 21:29:082497 return web_prefs;
[email protected]420ae012009-04-24 05:16:322498}
2499
[email protected]7d472472011-01-22 01:30:252500void TabContents::OnUserGesture() {
2501 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
2502 DownloadRequestLimiter* limiter =
2503 g_browser_process->download_request_limiter();
2504 if (limiter)
2505 limiter->OnUserGesture(this);
2506 ExternalProtocolHandler::PermitLaunchUrl();
2507}
2508
[email protected]fa1cf0b82010-01-15 21:49:442509void TabContents::OnIgnoredUIEvent() {
2510 if (constrained_window_count()) {
2511 ConstrainedWindow* window = *constrained_window_begin();
2512 window->FocusConstrainedWindow();
2513 }
2514}
2515
[email protected]420ae012009-04-24 05:16:322516void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2517 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342518 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322519 // delivered to a pending RenderViewHost. We must first run the onunload
2520 // handler of the old RenderViewHost before we can allow it to proceed.
2521 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2522 new_request_id);
2523}
2524
[email protected]420ae012009-04-24 05:16:322525void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2526 bool is_during_unload) {
2527 if (is_during_unload) {
2528 // Hang occurred while firing the beforeunload/unload handler.
2529 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112530 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322531
2532 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2533 return;
2534
2535 // If the tab hangs in the beforeunload/unload handler there's really
2536 // nothing we can do to recover. Pretend the unload listeners have
2537 // all fired and close the tab. If the hang is in the beforeunload handler
2538 // then the user will not have the option of cancelling the close.
2539 Close(rvh);
2540 return;
2541 }
2542
[email protected]61b50092011-02-03 18:02:192543 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
2544 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]7ec6bef2011-02-26 02:22:292545 browser::ShowHungRendererDialog(this);
[email protected]61b50092011-02-03 18:02:192546 }
[email protected]420ae012009-04-24 05:16:322547}
2548
2549void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]7ec6bef2011-02-26 02:22:292550 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:322551}
2552
2553void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562554 net::LoadState load_state,
2555 uint64 upload_position,
2556 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322557 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562558 upload_position_ = upload_position;
2559 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292560 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192561 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292562 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:422563 load_state_host_ = WideToUTF16Hack(
2564 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:322565 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2566 SetNotWaitingForResponse();
2567 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502568 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322569}
2570
[email protected]1ee614862009-07-06 20:29:182571bool TabContents::IsExternalTabContainer() const {
2572 if (!delegate())
2573 return false;
2574
2575 return delegate()->IsExternalTabContainer();
2576}
2577
[email protected]1ee614862009-07-06 20:29:182578void TabContents::DidInsertCSS() {
2579 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322580}
2581
[email protected]546ae4e02010-12-08 14:57:192582void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:352583 NotificationService::current()->Notify(
2584 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:212585 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:192586 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:352587}
2588
[email protected]b75b8292010-10-01 07:28:252589void TabContents::UpdateZoomLimits(int minimum_percent,
2590 int maximum_percent,
2591 bool remember) {
2592 minimum_zoom_percent_ = minimum_percent;
2593 maximum_zoom_percent_ = maximum_percent;
2594 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382595}
2596
[email protected]7d472472011-01-22 01:30:252597void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:442598 if (delegate())
2599 delegate()->WorkerCrashed();
[email protected]7d472472011-01-22 01:30:252600}
2601
[email protected]420ae012009-04-24 05:16:322602void TabContents::BeforeUnloadFiredFromRenderManager(
2603 bool proceed,
2604 bool* proceed_to_fire_unload) {
2605 if (delegate())
2606 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2607}
2608
[email protected]3a3d47472010-07-15 21:03:542609void TabContents::DidStartLoadingFromRenderManager(
2610 RenderViewHost* render_view_host) {
2611 DidStartLoading();
2612}
2613
2614void TabContents::RenderViewGoneFromRenderManager(
2615 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232616 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2617 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542618}
2619
[email protected]420ae012009-04-24 05:16:322620void TabContents::UpdateRenderViewSizeForRenderManager() {
2621 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262622 gfx::Size size = view_->GetContainerSize();
2623 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2624 // here during container initialization and normal window size will be set
2625 // later. In case of tab duplication this resizing to 0x0 prevents setting
2626 // normal size later so just ignore it.
2627 if (!size.IsEmpty())
2628 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322629}
2630
[email protected]3a3d47472010-07-15 21:03:542631void TabContents::NotifySwappedFromRenderManager() {
2632 NotifySwapped();
2633}
2634
2635NavigationController& TabContents::GetControllerForRenderManager() {
2636 return controller();
2637}
2638
[email protected]d0980792011-02-13 19:41:402639WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]80a8fad2011-01-29 04:02:382640 return WebUIFactory::CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322641}
2642
2643NavigationEntry*
2644TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2645 return controller_.GetLastCommittedEntry();
2646}
2647
2648bool TabContents::CreateRenderViewForRenderManager(
2649 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322650 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522651
[email protected]674b3822010-08-04 04:02:512652 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322653 return false;
2654
2655 // Now that the RenderView has been created, we need to tell it its size.
2656 rwh_view->SetSize(view_->GetContainerSize());
2657
2658 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2659 render_view_host);
2660 return true;
2661}
2662
2663void TabContents::Observe(NotificationType type,
2664 const NotificationSource& source,
2665 const NotificationDetails& details) {
2666 switch (type.value) {
[email protected]420ae012009-04-24 05:16:322667 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512668 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322669 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2670 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2671 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:532672 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
2673 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:322674 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:172675 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
2676 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:322677 } else {
2678 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2679 }
2680 break;
2681 }
2682 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2683 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2684 break;
2685
2686 case NotificationType::NAV_ENTRY_COMMITTED: {
2687 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2688
2689 NavigationController::LoadCommittedDetails& committed_details =
2690 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2691 ExpireInfoBars(committed_details);
2692 break;
2693 }
2694
[email protected]d3ba77272009-09-03 00:06:092695#if defined(OS_LINUX)
2696 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542697 renderer_preferences_util::UpdateFromSystemSettings(
2698 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092699 render_view_host()->SyncRendererPrefs();
2700 break;
2701 }
2702#endif
2703
[email protected]6c32ce72010-03-08 05:18:062704 case NotificationType::USER_STYLE_SHEET_UPDATED:
2705 UpdateWebPreferences();
2706 break;
2707
[email protected]79580c62010-02-02 02:36:252708 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:452709 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:252710 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492711 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292712 if (entry)
[email protected]da0c8e92010-02-09 23:25:492713 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292714 if (settings_details.ptr()->update_all() ||
2715 settings_details.ptr()->pattern().Matches(entry_url)) {
2716 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232717 profile()->GetHostContentSettingsMap()->
2718 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252719 }
2720 break;
2721 }
2722
[email protected]e5adff72010-06-14 18:13:062723 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:572724 break;
[email protected]a888b29e62010-04-01 13:38:572725
2726 case NotificationType::EXTENSION_UNLOADED:
[email protected]a888b29e62010-04-01 13:38:572727 break;
[email protected]a888b29e62010-04-01 13:38:572728
[email protected]88152052010-10-01 04:05:182729 case NotificationType::GOOGLE_URL_UPDATED:
2730 UpdateAlternateErrorPageURL();
2731 break;
2732
[email protected]420ae012009-04-24 05:16:322733 default:
2734 NOTREACHED();
2735 }
2736}
[email protected]aacd7cc2009-09-02 14:51:102737
[email protected]9adb9692010-10-29 23:14:022738void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:082739 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432740
[email protected]a888b29e62010-04-01 13:38:572741 if (extension) {
[email protected]98aa0b52010-05-06 17:03:082742 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
2743 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:572744 extension,
[email protected]807871f2010-09-16 01:04:482745 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
2746 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:572747 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
2748 Extension::EXTENSION_ICON_SMALLISH),
2749 ImageLoadingTracker::CACHE);
2750 } else {
[email protected]98aa0b52010-05-06 17:03:082751 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:572752 }
2753}
2754
[email protected]9adb9692010-10-29 23:14:022755const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:002756 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:572757 if (!extensions_service)
2758 return NULL;
2759
[email protected]9adb9692010-10-29 23:14:022760 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:572761 return extension ?
2762 extension : extensions_service->GetExtensionByWebExtent(url);
2763}
2764
[email protected]bd5174d2011-03-11 01:02:562765void TabContents::OnImageLoaded(SkBitmap* image,
2766 const ExtensionResource& resource,
[email protected]a888b29e62010-04-01 13:38:572767 int index) {
2768 if (image) {
[email protected]98aa0b52010-05-06 17:03:082769 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:572770 NotifyNavigationStateChanged(INVALIDATE_TAB);
2771 }
2772}
2773
[email protected]beb440c2009-11-06 04:08:542774gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2775 return view_->GetTopLevelNativeWindow();
2776}
2777
2778void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2779 bool success,
2780 const std::wstring& prompt) {
2781 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2782 if (is_showing_before_unload_dialog_ && !success) {
2783 // If a beforeunload dialog is canceled, we need to stop the throbber from
2784 // spinning, since we forced it to start spinning in Navigate.
2785 DidStopLoading();
2786
2787 tab_close_start_time_ = base::TimeTicks();
2788 }
2789 is_showing_before_unload_dialog_ = false;
2790 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2791}
2792
2793void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2794 set_suppress_javascript_messages(suppress_message_boxes);
2795}
2796
[email protected]3a3d47472010-07-15 21:03:542797TabContents* TabContents::AsTabContents() {
2798 return this;
2799}
2800
2801ExtensionHost* TabContents::AsExtensionHost() {
2802 return NULL;
2803}
2804
[email protected]41fc0322009-09-04 22:23:402805void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102806 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2807}
[email protected]f45d2a72010-03-08 23:28:352808
2809void TabContents::SetAppIcon(const SkBitmap& app_icon) {
2810 app_icon_ = app_icon;
2811 NotifyNavigationStateChanged(INVALIDATE_TITLE);
2812}
[email protected]33f74972010-12-08 16:40:362813
2814void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2815 render_manager_.SwapInRenderViewHost(rvh);
2816}
2817
2818void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2819 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2820 rwh_view->SetSize(view()->GetContainerSize());
2821}
[email protected]e7d50892011-01-19 21:47:382822
[email protected]232a5812011-03-04 22:42:082823void TabContents::OnOnlineStateChanged(bool online) {
2824 render_view_host()->Send(new ViewMsg_NetworkStateChanged(
2825 render_view_host()->routing_id(), online));
2826}