blob: f710569f9f30b7d0aacaed68dcf6a103c1285ba0 [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]a6d36cc2011-02-23 00:39:4824#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
25#include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h"
[email protected]96d185d2009-04-24 03:28:5426#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1427#include "chrome/browser/defaults.h"
[email protected]74da5bd2011-01-27 22:03:2728#include "chrome/browser/desktop_notification_handler.h"
[email protected]420ae012009-04-24 05:16:3229#include "chrome/browser/dom_operation_notification_details.h"
[email protected]bcef0dc02009-02-28 00:35:0230#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3231#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0132#include "chrome/browser/download/download_request_limiter.h"
[email protected]eaa7dd182010-12-14 11:09:0033#include "chrome/browser/extensions/extension_service.h"
[email protected]3c733bde2010-12-21 19:56:3134#include "chrome/browser/external_protocol_handler.h"
35#include "chrome/browser/favicon_service.h"
36#include "chrome/browser/file_select_helper.h"
37#include "chrome/browser/google/google_util.h"
[email protected]ef0d04c2010-12-15 23:34:2138#include "chrome/browser/history/history.h"
[email protected]ec0b6c42010-08-26 03:16:5839#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4240#include "chrome/browser/history/top_sites.h"
[email protected]8897c382009-05-06 17:53:2641#include "chrome/browser/hung_renderer_dialog.h"
[email protected]420ae012009-04-24 05:16:3242#include "chrome/browser/load_from_memory_cache_details.h"
43#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4444#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]724159a2010-12-30 01:11:1845#include "chrome/browser/metrics/user_metrics.h"
[email protected]ea0e80892009-08-22 00:36:0546#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1047#include "chrome/browser/omnibox_search_hint.h"
[email protected]c8f73ab2011-01-22 00:05:1748#include "chrome/browser/pdf_unsupported_feature.h"
[email protected]14a000d2010-04-29 21:44:2449#include "chrome/browser/platform_util.h"
[email protected]67c052e2011-01-31 16:33:5850#include "chrome/browser/plugin_observer.h"
[email protected]33f74972010-12-08 16:40:3651#include "chrome/browser/prerender/prerender_manager.h"
[email protected]973407b2011-01-26 23:18:2352#include "chrome/browser/prerender/prerender_plt_recorder.h"
[email protected]eb15e24e2011-02-03 22:34:3453#include "chrome/browser/printing/print_preview_message_handler.h"
[email protected]dbeebd52010-11-16 20:34:1654#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0955#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3356#include "chrome/browser/profiles/profile.h"
[email protected]96d185d2009-04-24 03:28:5457#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3258#include "chrome/browser/renderer_preferences_util.h"
[email protected]fa685ff2011-02-17 19:47:1359#include "chrome/browser/safe_browsing/client_side_detection_host.h"
[email protected]c37e3b62010-01-22 00:15:1760#include "chrome/browser/sessions/session_types.h"
[email protected]1f18184a2010-07-21 19:34:4961#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]d54169e92011-01-21 09:19:5262#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1663#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3564#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]54ec6472010-04-09 19:39:5865#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2766#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2167#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4968#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5769#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4870#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1471#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0972#include "chrome/common/extensions/url_pattern.h"
73#include "chrome/common/navigation_types.h"
74#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5675#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2976#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3277#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0278#include "chrome/common/render_messages_params.h"
[email protected]96d185d2009-04-24 03:28:5479#include "chrome/common/url_constants.h"
[email protected]567812d2011-02-24 17:40:5080#include "content/browser/child_process_security_policy.h"
81#include "content/browser/host_zoom_map.h"
82#include "content/browser/in_process_webkit/session_storage_namespace.h"
83#include "content/browser/renderer_host/render_process_host.h"
84#include "content/browser/renderer_host/render_view_host.h"
85#include "content/browser/renderer_host/render_widget_host_view.h"
86#include "content/browser/renderer_host/resource_request_details.h"
87#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4488#include "content/browser/tab_contents/infobar_delegate.h"
89#include "content/browser/tab_contents/interstitial_page.h"
90#include "content/browser/tab_contents/navigation_entry.h"
91#include "content/browser/tab_contents/provisional_load_details.h"
92#include "content/browser/tab_contents/tab_contents_delegate.h"
93#include "content/browser/tab_contents/tab_contents_observer.h"
94#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]67fc0392011-02-25 02:56:5795#include "content/browser/webui/web_ui.h"
[email protected]d686e812009-06-03 19:10:2996#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3297#include "net/base/registry_controlled_domain.h"
[email protected]8bd0fe62011-01-17 06:44:3798#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]42ce29d2011-01-20 23:19:4699#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:38100#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:03101#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:31102#include "webkit/glue/webpreferences.h"
103
104#if defined(OS_MACOSX)
105#include "app/surface/io_surface_support_mac.h"
106#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:00107
[email protected]61d68ef12011-01-13 14:02:56108#if defined(OS_CHROMEOS)
109#include "chrome/browser/chromeos/locale_change_guard.h"
110#endif // defined(OS_CHROMEOS)
111
[email protected]420ae012009-04-24 05:16:32112// Cross-Site Navigations
113//
114// If a TabContents is told to navigate to a different web site (as determined
115// by SiteInstance), it will replace its current RenderViewHost with a new
116// RenderViewHost dedicated to the new SiteInstance. This works as follows:
117//
118// - Navigate determines whether the destination is cross-site, and if so,
119// it creates a pending_render_view_host_ and moves into the PENDING
120// RendererState.
121// - The pending RVH is "suspended," so that no navigation messages are sent to
122// its renderer until the onbeforeunload JavaScript handler has a chance to
123// run in the current RVH.
124// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
125// that it has a pending cross-site request. ResourceDispatcherHost will
126// check for this when the response arrives.
127// - The current RVH runs its onbeforeunload handler. If it returns false, we
128// cancel all the pending logic and go back to NORMAL. Otherwise we allow
129// the pending RVH to send the navigation request to its renderer.
130// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
131// checks CrossSiteRequestManager to see that the RVH responsible has a
132// pending cross-site request, and then installs a CrossSiteEventHandler.
133// - When RDH receives a response, the BufferedEventHandler determines whether
134// it is a download. If so, it sends a message to the new renderer causing
135// it to cancel the request, and the download proceeds in the download
136// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34137// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32138// doesn't affect any functionality.
139// - After RDH receives a response and determines that it is safe and not a
140// download, it pauses the response to first run the old page's onunload
141// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34142// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32143// to the current RVH.
144// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
145// the ResourceDispatcherHost, who unpauses the response. Data is then sent
146// to the pending RVH.
147// - The pending renderer sends a FrameNavigate message that invokes the
148// DidNavigate method. This replaces the current RVH with the
149// pending RVH and goes back to the NORMAL RendererState.
150
151namespace {
152
153// Amount of time we wait between when a key event is received and the renderer
154// is queried for its state and pushed to the NavigationEntry.
155const int kQueryStateDelay = 5000;
156
[email protected]6ebdc9b2010-09-27 16:55:57157const int kSyncWaitDelay = 40;
158
[email protected]420ae012009-04-24 05:16:32159// If another javascript message box is displayed within
160// kJavascriptMessageExpectedDelay of a previous javascript message box being
161// dismissed, display an option to suppress future message boxes from this
162// contents.
163const int kJavascriptMessageExpectedDelay = 1000;
164
[email protected]420ae012009-04-24 05:16:32165// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51166const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32167 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17168 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32169 prefs::kWebKitJavaEnabled,
170 prefs::kWebKitJavascriptEnabled,
171 prefs::kWebKitLoadsImagesAutomatically,
172 prefs::kWebKitPluginsEnabled,
173 prefs::kWebKitUsesUniversalDetector,
174 prefs::kWebKitSerifFontFamily,
175 prefs::kWebKitSansSerifFontFamily,
176 prefs::kWebKitFixedFontFamily,
177 prefs::kWebKitDefaultFontSize,
178 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13179 prefs::kWebKitMinimumFontSize,
180 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36181 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32182 prefs::kDefaultCharset
183 // kWebKitStandardFontIsSerif needs to be added
184 // if we let users pick which font to use, serif or sans-serif when
185 // no font is specified or a CSS generic family (serif or sans-serif)
186 // is not specified.
187};
188
189const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
190
[email protected]420ae012009-04-24 05:16:32191#if defined(OS_WIN)
192
193BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
194 // Note: erase is required to properly paint some widgets borders. This can
195 // be seen with textfields.
196 InvalidateRect(hwnd, NULL, TRUE);
197 return TRUE;
198}
199#endif
200
[email protected]5e369672009-11-03 23:48:30201ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16202 Profile* profile, const NavigationEntry& entry,
203 NavigationController::ReloadType reload_type) {
204 switch (reload_type) {
205 case NavigationController::RELOAD:
206 return ViewMsg_Navigate_Params::RELOAD;
207 case NavigationController::RELOAD_IGNORING_CACHE:
208 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
209 case NavigationController::NO_RELOAD:
210 break; // Fall through to rest of function.
211 }
[email protected]5e369672009-11-03 23:48:30212
213 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
214 profile->DidLastSessionExitCleanly())
215 return ViewMsg_Navigate_Params::RESTORE;
216
217 return ViewMsg_Navigate_Params::NORMAL;
218}
219
[email protected]876bc832010-09-07 16:29:54220void MakeNavigateParams(const NavigationEntry& entry,
221 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16222 NavigationController::ReloadType reload_type,
223 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34224 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54225 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00226 params->current_history_list_offset = controller.last_committed_entry_index();
227 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34228 params->url = entry.url();
229 params->referrer = entry.referrer();
230 params->transition = entry.transition_type();
231 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00232 params->navigation_type =
233 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34234 params->request_time = base::Time::Now();
235}
236
[email protected]420ae012009-04-24 05:16:32237} // namespace
238
[email protected]f4f50ef2011-01-21 19:01:19239
240// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32241
[email protected]420ae012009-04-24 05:16:32242TabContents::TabContents(Profile* profile,
243 SiteInstance* site_instance,
244 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07245 const TabContents* base_tab_contents,
246 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42247 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07248 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
249 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13250 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22251 TabContentsView::Create(this))),
252 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06253 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34254 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23255 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
256 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34257 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34258 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57259 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56260 upload_size_(0),
261 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57262 received_page_title_(false),
[email protected]c65e2f152010-10-14 15:30:40263 blocked_contents_(NULL),
264 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49265 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47266 displayed_insecure_content_(false),
[email protected]98aa0b52010-05-06 17:03:08267 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57268 capturing_contents_(false),
269 is_being_destroyed_(false),
270 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57271#if defined(OS_WIN)
272 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
273#endif
[email protected]c2e74fe82009-09-03 17:57:44274 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01275 is_showing_before_unload_dialog_(false),
[email protected]80a8fad2011-01-29 04:02:38276 opener_web_ui_type_(WebUIFactory::kNoWebUI),
[email protected]777a7b62010-05-11 13:28:16277 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38278 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25279 minimum_zoom_percent_(
280 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
281 maximum_zoom_percent_(
282 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00283 temporary_zoom_settings_(false),
[email protected]f72298c2011-02-22 19:56:14284 content_restrictions_(0),
285 was_prerendered_(false) {
[email protected]7ff431e2010-01-07 18:18:54286 renderer_preferences_util::UpdateFromSystemSettings(
287 &renderer_preferences_, profile);
288
[email protected]9fb83e82010-07-02 18:24:55289 content_settings_delegate_.reset(
290 new TabSpecificContentSettings(this, profile));
291
[email protected]12636df2009-09-28 22:32:21292 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32293
[email protected]34ac70502009-09-25 17:07:23294 // We have the initial size of the view be based on the size of the passed in
295 // tab contents (normally a tab from the same window).
296 view_->CreateView(base_tab_contents ?
297 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32298
299 // Register for notifications about all interested prefs change.
300 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28301 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32302 if (prefs) {
303 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28304 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32305 }
306
[email protected]420ae012009-04-24 05:16:32307 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
308 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09309#if defined(OS_LINUX)
310 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
311 NotificationService::AllSources());
312#endif
[email protected]420ae012009-04-24 05:16:32313
[email protected]6c32ce72010-03-08 05:18:06314 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
315 NotificationService::AllSources());
316
[email protected]79580c62010-02-02 02:36:25317 // Register for notifications about content setting changes.
318 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
319 NotificationService::AllSources());
320
[email protected]a888b29e62010-04-01 13:38:57321 // Listen for extension changes so we can update extension_for_current_page_.
322 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
323 NotificationService::AllSources());
324 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
325 NotificationService::AllSources());
[email protected]a888b29e62010-04-01 13:38:57326
[email protected]88152052010-10-01 04:05:18327 // Listen for Google URL changes
328 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
329 NotificationService::AllSources());
330
[email protected]c8865482009-07-23 20:40:10331 // Set-up the showing of the omnibox search infobar if applicable.
332 if (OmniboxSearchHint::IsEnabled(profile))
333 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53334
[email protected]b5a1d11c2011-02-17 03:09:42335 // Can only add observers after render_manager_.Init() is called, since that's
336 // what sets up the render_view_host which TabContentObserver's constructor
337 // uses to get the routing_id.
338 AddObservers();
[email protected]332af7732009-03-11 13:21:35339}
initial.commit09911bf2008-07-26 23:55:29340
341TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32342 is_being_destroyed_ = true;
343
[email protected]bfe4c1582009-10-02 18:11:09344 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32345 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28346 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32347
[email protected]420ae012009-04-24 05:16:32348 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00349 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32350
[email protected]420ae012009-04-24 05:16:32351 // First cleanly close all child windows.
352 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
353 // some of these to close. CloseWindows is async, so it might get called
354 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49355 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32356
[email protected]c65e2f152010-10-14 15:30:40357 // Close all blocked contents.
358 if (blocked_contents_)
359 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13360
[email protected]420ae012009-04-24 05:16:32361 // Notify any observer that have a reference on this tab contents.
362 NotificationService::current()->Notify(
363 NotificationType::TAB_CONTENTS_DESTROYED,
364 Source<TabContents>(this),
365 NotificationService::NoDetails());
366
[email protected]1e5e74f2009-05-27 20:55:12367 // Notify any lasting InfobarDelegates that have not yet been removed that
368 // whatever infobar they were handling in this TabContents has closed,
369 // because the TabContents is going away entirely.
370 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
371 // notification may trigger infobars calls that access their delegate. (and
372 // some implementations of InfoBarDelegate do delete themselves on
373 // InfoBarClosed()).
[email protected]ec8f51162011-02-08 04:20:40374 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]1e5e74f2009-05-27 20:55:12375 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
376 delegate->InfoBarClosed();
377 }
378 infobar_delegates_.clear();
379
[email protected]420ae012009-04-24 05:16:32380 // TODO(brettw) this should be moved to the view.
381#if defined(OS_WIN)
382 // If we still have a window handle, destroy it. GetNativeView can return
383 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42384 if (GetNativeView()) {
385 RenderViewHost* host = render_view_host();
386 if (host && host->view()) {
387 host->view()->WillWmDestroy();
388 }
[email protected]420ae012009-04-24 05:16:32389 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42390 }
[email protected]420ae012009-04-24 05:16:32391#endif
[email protected]7ab1e7d62009-10-14 23:32:01392
393 // OnCloseStarted isn't called in unit tests.
394 if (!tab_close_start_time_.is_null()) {
395 UMA_HISTOGRAM_TIMES("Tab.Close",
396 base::TimeTicks::Now() - tab_close_start_time_);
397 }
[email protected]b5a1d11c2011-02-17 03:09:42398
399 FOR_EACH_OBSERVER(TabContentsObserver, observers_, set_tab_contents(NULL));
400}
401
402void TabContents::AddObservers() {
403 printing_.reset(new printing::PrintViewManager(this));
404 print_preview_.reset(new printing::PrintPreviewMessageHandler(this));
405 fav_icon_helper_.reset(new FavIconHelper(this));
406 autofill_manager_.reset(new AutoFillManager(this));
407 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
408 prerender_plt_recorder_.reset(new prerender::PrerenderPLTRecorder(this));
409 desktop_notification_handler_.reset(
410 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
411 plugin_observer_.reset(new PluginObserver(this));
[email protected]fa685ff2011-02-17 19:47:13412 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost(
413 this));
initial.commit09911bf2008-07-26 23:55:29414}
415
[email protected]724159a2010-12-30 01:11:18416bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]585b30362011-01-28 02:30:17417 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
418 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10419 while ((observer = it.GetNext()) != NULL)
420 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53421 return true;
[email protected]403415a2011-01-10 18:57:53422
[email protected]724159a2010-12-30 01:11:18423 bool handled = true;
424 bool message_is_ok = true;
425 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
426 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
427 OnDidStartProvisionalLoadForFrame)
428 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
429 OnDidRedirectProvisionalLoad)
430 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
431 OnDidFailProvisionalLoadWithError)
432 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
433 OnDidLoadResourceFromMemoryCache)
434 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
435 OnDidDisplayInsecureContent)
436 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
437 OnDidRunInsecureContent)
438 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
439 OnDocumentLoadedInFrame)
440 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17441 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
442 OnUpdateContentRestrictions)
443 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
444 OnPDFHasUnsupportedFeature)
[email protected]7d472472011-01-22 01:30:25445 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]7d472472011-01-22 01:30:25446 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo,
447 OnDidGetApplicationInfo)
448 IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication,
449 OnInstallApplication)
450 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
451 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated)
[email protected]a6d36cc2011-02-23 00:39:48452 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
453 OnRegisterProtocolHandler)
[email protected]7d472472011-01-22 01:30:25454 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions)
455 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined,
456 OnInstantSupportDetermined)
[email protected]34f128d2011-01-25 19:07:44457 IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser)
[email protected]724159a2010-12-30 01:11:18458 IPC_MESSAGE_UNHANDLED(handled = false)
459 IPC_END_MESSAGE_MAP_EX()
460
461 if (!message_is_ok) {
462 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
463 GetRenderProcessHost()->ReceivedBadMessage();
464 }
465
466 return handled;
467}
468
[email protected]13367f72009-07-08 16:39:02469// Returns true if contains content rendered by an extension.
470bool TabContents::HostsExtension() const {
471 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34472}
473
[email protected]1f18184a2010-07-21 19:34:49474TabContentsSSLHelper* TabContents::GetSSLHelper() {
475 if (ssl_helper_.get() == NULL)
476 ssl_helper_.reset(new TabContentsSSLHelper(this));
477 return ssl_helper_.get();
478}
479
[email protected]8cb5d5b2010-02-09 11:36:16480RenderProcessHost* TabContents::GetRenderProcessHost() const {
481 return render_manager_.current_host()->process();
482}
483
[email protected]9adb9692010-10-29 23:14:02484void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46485 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08486 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10487
[email protected]98aa0b52010-05-06 17:03:08488 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57489
[email protected]fca656c2010-02-10 20:30:10490 NotificationService::current()->Notify(
491 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
492 Source<TabContents>(this),
493 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49494}
495
[email protected]98aa0b52010-05-06 17:03:08496void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
497 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40498 return;
499
[email protected]eaa7dd182010-12-14 11:09:00500 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50501 if (!extension_service || !extension_service->is_ready())
502 return;
503
504 const Extension* extension =
505 extension_service->GetExtensionById(extension_app_id, false);
506 if (extension)
507 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40508}
509
[email protected]98aa0b52010-05-06 17:03:08510SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08511 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51512 return NULL;
513
[email protected]98aa0b52010-05-06 17:03:08514 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51515}
516
[email protected]d5f942ba2008-09-26 19:30:34517const GURL& TabContents::GetURL() const {
518 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57519 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54520 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34521}
522
[email protected]96d185d2009-04-24 03:28:54523const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55524 // Transient entries take precedence. They are used for interstitial pages
525 // that are shown on top of existing pages.
526 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23527 if (entry) {
528 return entry->GetTitleForDisplay(profile()->GetPrefs()->
529 GetString(prefs::kAcceptLanguages));
530 }
[email protected]7ade2732011-02-10 00:13:58531 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
532 render_manager_.pending_web_ui() : render_manager_.web_ui();
533 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54534 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55535 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54536 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35537 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58538 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54539 if (!title.empty())
540 return title;
541 }
542 }
543
544 // We use the title for the last committed entry rather than a pending
545 // navigation entry. For example, when the user types in a URL, we want to
546 // keep the old page's title until the new load has committed and we get a new
547 // title.
[email protected]96d185d2009-04-24 03:28:54548 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23549 if (entry) {
550 return entry->GetTitleForDisplay(profile()->GetPrefs()->
551 GetString(prefs::kAcceptLanguages));
552 }
[email protected]96d185d2009-04-24 03:28:54553 return EmptyString16();
554}
555
[email protected]d5f942ba2008-09-26 19:30:34556int32 TabContents::GetMaxPageID() {
557 if (GetSiteInstance())
558 return GetSiteInstance()->max_page_id();
559 else
560 return max_page_id_;
561}
562
563void TabContents::UpdateMaxPageID(int32 page_id) {
564 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34565 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34566 // testing.
567 if (GetSiteInstance())
568 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16569 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34570}
571
[email protected]96d185d2009-04-24 03:28:54572SiteInstance* TabContents::GetSiteInstance() const {
573 return render_manager_.current_host()->site_instance();
574}
575
[email protected]96d185d2009-04-24 03:28:54576bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15577 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54578 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15579 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01580 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54581 return true;
[email protected]8ab24cc2009-11-13 20:56:15582 }
[email protected]83e3895b2009-06-11 00:07:16583
[email protected]2b9a06402011-02-16 04:57:10584 // We always display the URL for non-WebUI URLs to prevent spoofing.
585 if (entry && !WebUIFactory::HasWebUIScheme(entry->url()))
586 return true;
587
[email protected]d0980792011-02-13 19:41:40588 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58589 if (web_ui)
590 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54591 return true;
592}
593
[email protected]d5f942ba2008-09-26 19:30:34594SkBitmap TabContents::GetFavIcon() const {
595 // Like GetTitle(), we also want to use the favicon for the last committed
596 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57597 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47598 if (entry)
599 return entry->favicon().bitmap();
600
[email protected]ce3fa3c2009-04-20 19:55:57601 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34602 if (entry)
603 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34604 return SkBitmap();
605}
606
[email protected]0b303cc2009-09-28 22:35:15607bool TabContents::FavIconIsValid() const {
608 NavigationEntry* entry = controller_.GetTransientEntry();
609 if (entry)
610 return entry->favicon().is_valid();
611
612 entry = controller_.GetLastCommittedEntry();
613 if (entry)
614 return entry->favicon().is_valid();
615
616 return false;
617}
618
[email protected]96d185d2009-04-24 03:28:54619bool TabContents::ShouldDisplayFavIcon() {
620 // Always display a throbber during pending loads.
621 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
622 return true;
623
[email protected]d0980792011-02-13 19:41:40624 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58625 if (web_ui)
626 return !web_ui->hide_favicon();
[email protected]96d185d2009-04-24 03:28:54627 return true;
628}
629
[email protected]585b30362011-01-28 02:30:17630void TabContents::AddObserver(TabContentsObserver* observer) {
631 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49632}
633
[email protected]585b30362011-01-28 02:30:17634void TabContents::RemoveObserver(TabContentsObserver* observer) {
635 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49636}
637
[email protected]443b80e2010-12-14 00:42:23638void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
639 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34640 return;
641
[email protected]443b80e2010-12-14 00:42:23642 crashed_status_ = status;
643 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50644 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34645}
646
[email protected]744ef172009-10-16 21:53:46647void TabContents::PageActionStateChanged() {
648 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00649}
[email protected]ce5c4502009-05-06 16:46:11650
[email protected]d5f942ba2008-09-26 19:30:34651void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
652 if (delegate_)
653 delegate_->NavigationStateChanged(this, changed_flags);
654}
655
[email protected]96d185d2009-04-24 03:28:54656void TabContents::DidBecomeSelected() {
657 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16658 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
659 if (rwhv) {
660 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43661#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16662 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43663#endif
664 }
[email protected]96d185d2009-04-24 03:28:54665
[email protected]8cb5d5b2010-02-09 11:36:16666 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11667 last_selected_time_ = base::TimeTicks::Now();
[email protected]61d68ef12011-01-13 14:02:56668#if defined(OS_CHROMEOS)
669 chromeos::LocaleChangeGuard::Check(this);
670#endif
[email protected]96d185d2009-04-24 03:28:54671}
672
[email protected]a94454b2010-12-16 04:16:03673void TabContents::FadeForInstant(bool animate) {
[email protected]1b072562010-12-13 19:37:45674 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
675 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
676 if (rwhv)
[email protected]a94454b2010-12-16 04:16:03677 rwhv->SetVisuallyDeemphasized(&whitish, animate);
[email protected]1b072562010-12-13 19:37:45678}
679
680void TabContents::CancelInstantFade() {
681 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
682 if (rwhv)
683 rwhv->SetVisuallyDeemphasized(NULL, false);
684}
685
[email protected]96d185d2009-04-24 03:28:54686void TabContents::WasHidden() {
687 if (!capturing_contents()) {
688 // |render_view_host()| can be NULL if the user middle clicks a link to open
689 // a tab in then background, then closes the tab before selecting it. This
690 // is because closing the tab calls TabContents::Destroy(), which removes
691 // the |render_view_host()|; then when we actually destroy the window,
692 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16693 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
694 if (rwhv)
695 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54696 }
697
698 NotificationService::current()->Notify(
699 NotificationType::TAB_CONTENTS_HIDDEN,
700 Source<TabContents>(this),
701 NotificationService::NoDetails());
702}
703
[email protected]d5f942ba2008-09-26 19:30:34704void TabContents::Activate() {
705 if (delegate_)
706 delegate_->ActivateContents(this);
707}
708
[email protected]ea42e7782010-08-23 23:58:12709void TabContents::Deactivate() {
710 if (delegate_)
711 delegate_->DeactivateContents(this);
712}
713
[email protected]96d185d2009-04-24 03:28:54714void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16715 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
716 if (rwhv)
717 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54718}
719
720void TabContents::HideContents() {
721 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
722 // our superclass HideContents(), because some callers want to be very picky
723 // about the order in which these get called. In addition to making the code
724 // here practically impossible to understand, this also means we end up
725 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34726 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54727 WasHidden();
728}
729
[email protected]5aab5e22010-12-08 22:13:29730bool TabContents::NeedToFireBeforeUnload() {
731 // TODO(creis): Should we fire even for interstitial pages?
732 return notify_disconnection() &&
733 !showing_interstitial_page() &&
734 !render_view_host()->SuddenTerminationAllowed();
735}
736
[email protected]c0588052008-10-27 23:01:50737void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34738 WindowOpenDisposition disposition,
739 PageTransition::Type transition) {
740 if (delegate_)
[email protected]c0588052008-10-27 23:01:50741 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34742}
743
[email protected]1ccb3568d2010-02-19 10:51:16744bool TabContents::NavigateToPendingEntry(
745 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54746 return NavigateToEntry(*controller_.pending_entry(), reload_type);
747}
[email protected]96d185d2009-04-24 03:28:54748
[email protected]876bc832010-09-07 16:29:54749bool TabContents::NavigateToEntry(
750 const NavigationEntry& entry,
751 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54752 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
753 if (!dest_render_view_host)
754 return false; // Unable to create the desired render view host.
755
[email protected]770dd8b2010-05-24 18:11:39756 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
757 dest_render_view_host->EnablePreferredSizeChangedMode(
758 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
759 }
[email protected]9fb325e2010-05-06 18:23:24760
[email protected]80a8fad2011-01-29 04:02:38761 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07762 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58763 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]c09163a2011-02-15 00:05:55764 bool is_allowed_in_web_ui_renderer =
[email protected]80a8fad2011-01-29 04:02:38765 WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url());
[email protected]c09163a2011-02-15 00:05:55766 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
767 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58768
[email protected]96d185d2009-04-24 03:28:54769 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12770 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32771 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00772 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
773 dest_render_view_host,
774 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32775 }
[email protected]96d185d2009-04-24 03:28:54776
777 // Used for page load time metrics.
778 current_load_start_ = base::TimeTicks::Now();
779
780 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34781 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54782 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04783 if (delegate_) {
784 navigate_params.extra_headers =
785 delegate_->GetNavigationHeaders(navigate_params.url);
786 }
[email protected]056de2d2009-06-26 16:41:34787 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54788
789 if (entry.page_id() == -1) {
790 // HACK!! This code suppresses javascript: URLs from being added to
791 // session history, which is what we want to do for javascript: URLs that
792 // do not generate content. What we really need is a message from the
793 // renderer telling us that a new page was not created. The same message
794 // could be used for mailto: URLs and the like.
795 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
796 return false;
797 }
798
[email protected]3c9e1872010-11-18 16:17:49799 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:17800 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54801
[email protected]1ccb3568d2010-02-19 10:51:16802 if (reload_type != NavigationController::NO_RELOAD &&
803 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48804 FaviconService* favicon_service =
805 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
806 if (favicon_service)
807 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54808 }
809
[email protected]d5f942ba2008-09-26 19:30:34810 return true;
811}
812
[email protected]96d185d2009-04-24 03:28:54813void TabContents::Stop() {
814 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09815 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54816}
817
[email protected]96d185d2009-04-24 03:28:54818void TabContents::DisassociateFromPopupCount() {
819 render_view_host()->DisassociateFromPopupCount();
820}
821
822TabContents* TabContents::Clone() {
823 // We create a new SiteInstance so that the new tab won't share processes
824 // with the old one. This can be changed in the future if we need it to share
825 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32826 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54827 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07828 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54829 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08830 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08831 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54832 return tc;
833}
834
[email protected]4d677202009-07-19 07:37:12835void TabContents::ShowPageInfo(const GURL& url,
836 const NavigationEntry::SSLStatus& ssl,
837 bool show_history) {
838 if (!delegate_)
839 return;
840
[email protected]bb678332009-07-21 00:15:50841 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12842}
843
[email protected]ef0d04c2010-12-15 23:34:21844void TabContents::SaveFavicon() {
845 NavigationEntry* entry = controller_.GetActiveEntry();
846 if (!entry || entry->url().is_empty())
847 return;
848
849 // Make sure the page is in history, otherwise adding the favicon does
850 // nothing.
851 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
852 Profile::IMPLICIT_ACCESS);
853 if (!history)
854 return;
855 history->AddPageNoVisitForBookmark(entry->url());
856
857 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
858 Profile::IMPLICIT_ACCESS);
859 if (!service)
860 return;
861 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
862 if (!favicon.is_valid() || favicon.url().is_empty() ||
863 favicon.bitmap().empty()) {
864 return;
865 }
866 std::vector<unsigned char> image_data;
867 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
868 service->SetFavicon(entry->url(), favicon.url(), image_data);
869}
870
initial.commit09911bf2008-07-26 23:55:29871ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28872 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29873 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28874 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29875 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44876
877 if (child_windows_.size() == 1) {
878 window->ShowConstrainedWindow();
879 BlockTabContent(true);
880 }
881
initial.commit09911bf2008-07-26 23:55:29882 return window;
883}
884
[email protected]fa1cf0b82010-01-15 21:49:44885void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55886 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45887 // 70% opaque grey.
888 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55889 if (rwhv)
[email protected]1b072562010-12-13 19:37:45890 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44891 render_view_host()->set_ignore_input_events(blocked);
892 if (delegate_)
893 delegate_->SetTabContentBlocked(this, blocked);
894}
895
initial.commit09911bf2008-07-26 23:55:29896void TabContents::AddNewContents(TabContents* new_contents,
897 WindowOpenDisposition disposition,
898 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29899 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40900 if (all_contents_blocked_) {
901 if (!blocked_contents_)
902 blocked_contents_ = new BlockedContentContainer(this);
903 blocked_contents_->AddTabContents(
904 new_contents, disposition, initial_pos, user_gesture);
905 return;
906 }
907
initial.commit09911bf2008-07-26 23:55:29908 if (!delegate_)
909 return;
910
[email protected]35f7d212009-04-29 21:19:27911 if ((disposition == NEW_POPUP) && !user_gesture &&
912 !CommandLine::ForCurrentProcess()->HasSwitch(
913 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22914 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31915 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29916 delegate_->GetConstrainingContents(this)->AddPopup(
917 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31918 } else {
[email protected]0aa55312008-10-17 21:53:08919 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29920 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
921 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49922 NotificationService::current()->Notify(
923 NotificationType::TAB_ADDED,
924 Source<TabContentsDelegate>(delegate_),
925 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29926 }
initial.commit09911bf2008-07-26 23:55:29927
[email protected]8cc8d492010-02-02 10:40:49928 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:40929 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:29930}
931
[email protected]bcd9dc42010-01-23 16:38:18932bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:20933 bool is_js_code, const std::string& code_string,
934 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51935 RenderViewHost* host = render_view_host();
936 if (!host)
937 return false;
938
939 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:17940 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:51941 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35942}
943
[email protected]96d185d2009-04-24 03:28:54944void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49945 if (is_being_destroyed_)
946 return;
[email protected]9fb83e82010-07-02 18:24:55947 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49948 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40949 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:54950}
951
[email protected]5c9e97a2009-09-09 23:48:30952gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54953 return view_->GetContentNativeView();
954}
955
956gfx::NativeView TabContents::GetNativeView() const {
957 return view_->GetNativeView();
958}
959
960void TabContents::GetContainerBounds(gfx::Rect *out) const {
961 view_->GetContainerBounds(out);
962}
963
964void TabContents::Focus() {
965 view_->Focus();
966}
967
[email protected]90daadb42009-06-08 21:27:28968void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54969 if (showing_interstitial_page()) {
970 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
971 return;
972 }
[email protected]96d185d2009-04-24 03:28:54973 render_view_host()->SetInitialFocus(reverse);
974}
975
976bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40977 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58978 if (web_ui)
979 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43980 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25981 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43982 return true;
[email protected]96d185d2009-04-24 03:28:54983 return false;
984}
985
[email protected]a26dc362010-04-23 01:48:58986void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38987 if (delegate())
[email protected]a26dc362010-04-23 01:48:58988 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38989}
990
[email protected]616ed5a2008-11-21 22:27:24991void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32992 if (delegate_ && !delegate_->infobars_enabled()) {
993 delegate->InfoBarClosed();
994 return;
995 }
996
[email protected]616ed5a2008-11-21 22:27:24997 // Look through the existing InfoBarDelegates we have for a match. If we've
998 // already got one that matches, then we don't add the new one.
[email protected]ec8f51162011-02-08 04:20:40999 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451000 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1001 // Tell the new infobar to close so that it can clean itself up.
1002 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241003 return;
[email protected]6d27a7b2009-12-18 23:25:451004 }
[email protected]616ed5a2008-11-21 22:27:241005 }
1006
1007 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561008 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:191009 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:561010 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241011
1012 // Add ourselves as an observer for navigations the first time a delegate is
1013 // added. We use this notification to expire InfoBars that need to expire on
1014 // page transitions.
1015 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561016 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571017 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241018 }
1019}
1020
1021void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321022 if (delegate_ && !delegate_->infobars_enabled()) {
1023 return;
1024 }
1025
[email protected]616ed5a2008-11-21 22:27:241026 std::vector<InfoBarDelegate*>::iterator it =
1027 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1028 if (it != infobar_delegates_.end()) {
1029 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561030 NotificationService::current()->Notify(
1031 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1032 Source<TabContents>(this),
1033 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241034
[email protected]f4f50ef2011-01-21 19:01:191035 infobar_delegates_.erase(it);
1036 // Remove ourselves as an observer if we are tracking no more InfoBars.
1037 if (infobar_delegates_.empty()) {
1038 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1039 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031040 }
[email protected]616ed5a2008-11-21 22:27:241041 }
1042}
[email protected]3edd9522009-03-04 22:19:411043
[email protected]f81821c2009-08-07 01:29:471044void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1045 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321046 if (delegate_ && !delegate_->infobars_enabled()) {
1047 new_delegate->InfoBarClosed();
1048 return;
1049 }
1050
[email protected]f81821c2009-08-07 01:29:471051 std::vector<InfoBarDelegate*>::iterator it =
1052 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1053 DCHECK(it != infobar_delegates_.end());
1054
1055 // Notify the container about the change of plans.
1056 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1057 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1058 old_delegate, new_delegate));
1059 NotificationService::current()->Notify(
1060 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1061 Source<TabContents>(this),
1062 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1063
[email protected]f4f50ef2011-01-21 19:01:191064 // Remove the old one.
1065 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:471066
1067 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081068 DCHECK(find(infobar_delegates_.begin(),
1069 infobar_delegates_.end(), new_delegate) ==
1070 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471071 infobar_delegates_.push_back(new_delegate);
1072}
1073
[email protected]20ede072009-10-06 00:28:351074bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271075 if (showing_interstitial_page())
1076 return false;
1077
[email protected]c8f74942010-09-03 10:04:141078 // Do not show bookmarks bar if bookmarks aren't enabled.
1079 if (!browser_defaults::bookmarks_enabled)
1080 return false;
1081
[email protected]d0980792011-02-13 19:41:401082 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:541083 // similar, but for non-first loads, we want to use the committed entry. This
1084 // is so the bookmarks bar disappears at the same time the page does.
1085 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:351086 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:581087 return (render_manager_.web_ui() == NULL) ?
1088 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541089 }
1090
1091 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:401092 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:541093 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:581094 if (render_manager_.pending_web_ui())
1095 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
1096 return (render_manager_.web_ui() == NULL) ?
1097 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541098}
1099
[email protected]3edd9522009-03-04 22:19:411100void TabContents::ToolbarSizeChanged(bool is_animating) {
1101 TabContentsDelegate* d = delegate();
1102 if (d)
1103 d->ToolbarSizeChanged(this, is_animating);
1104}
[email protected]616ed5a2008-11-21 22:27:241105
[email protected]fc6fb7fb2009-11-07 02:35:041106bool TabContents::CanDownload(int request_id) {
1107 TabContentsDelegate* d = delegate();
1108 if (d)
1109 return d->CanDownload(request_id);
1110 return true;
1111}
1112
[email protected]d5f942ba2008-09-26 19:30:341113void TabContents::OnStartDownload(DownloadItem* download) {
1114 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341115
1116 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311117 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341118
[email protected]5b928b62010-08-03 11:46:511119 if (tab_contents && tab_contents->delegate())
1120 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411121}
[email protected]3edd9522009-03-04 22:19:411122
[email protected]d5f942ba2008-09-26 19:30:341123void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371124 ConstrainedWindowList::iterator i(
1125 std::find(child_windows_.begin(), child_windows_.end(), window));
1126 bool removed_topmost_window = i == child_windows_.begin();
1127 if (i != child_windows_.end())
1128 child_windows_.erase(i);
1129 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441130 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371131 } else {
1132 if (removed_topmost_window)
1133 child_windows_[0]->ShowConstrainedWindow();
1134 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441135 }
[email protected]66ba4932009-06-04 19:22:131136}
[email protected]d5f942ba2008-09-26 19:30:341137
[email protected]c65e2f152010-10-14 15:30:401138void TabContents::WillCloseBlockedContentContainer(
1139 BlockedContentContainer* container) {
1140 DCHECK(blocked_contents_ == container);
1141 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491142 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341143}
1144
[email protected]d5f942ba2008-09-26 19:30:341145void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351146#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061147 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351148#endif
[email protected]d5f942ba2008-09-26 19:30:341149}
1150
[email protected]420ae012009-04-24 05:16:321151void TabContents::OnSavePage() {
1152 // If we can not save the page, try to download it.
1153 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1154 DownloadManager* dlm = profile()->GetDownloadManager();
1155 const GURL& current_page_url = GetURL();
1156 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221157 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321158 return;
1159 }
1160
1161 Stop();
1162
1163 // Create the save package and possibly prompt the user for the name to save
1164 // the page as. The user prompt is an asynchronous operation that runs on
1165 // another thread.
[email protected]b5a1d11c2011-02-17 03:09:421166 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321167 save_package_->GetSaveInfo();
1168}
1169
1170// Used in automated testing to bypass prompting the user for file names.
1171// Instead, the names and paths are hard coded rather than running them through
1172// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111173bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321174 SavePackage::SavePackageType save_type) {
1175 // Stop the page from navigating.
1176 Stop();
1177
[email protected]b5a1d11c2011-02-17 03:09:421178 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591179 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321180}
1181
[email protected]89d6e6e2009-12-03 23:06:511182void TabContents::EmailPageLocation() {
1183 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1184 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1185 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1186 title + "&body=%0A%0A" + page_url;
1187 platform_util::OpenExternal(GURL(mailto));
1188}
1189
[email protected]420ae012009-04-24 05:16:321190void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161191 if (CommandLine::ForCurrentProcess()->HasSwitch(
1192 switches::kEnablePrintPreview)) {
1193 if (showing_interstitial_page())
1194 return;
[email protected]83a58a22011-02-05 03:44:481195
1196 printing::PrintPreviewTabController* tab_controller =
1197 printing::PrintPreviewTabController::GetInstance();
1198 if (!tab_controller)
1199 return;
1200 tab_controller->GetOrCreatePreviewTab(this, controller().window_id().id());
1201
[email protected]dbeebd52010-11-16 20:34:161202 render_view_host()->PrintPreview();
1203 } else {
1204 PrintNow();
1205 }
[email protected]420ae012009-04-24 05:16:321206}
1207
1208bool TabContents::PrintNow() {
1209 // We can't print interstitial page for now.
1210 if (showing_interstitial_page())
1211 return false;
1212
1213 return render_view_host()->PrintPages();
1214}
1215
[email protected]82270452009-06-19 15:58:011216void TabContents::PrintingDone(int document_cookie, bool success) {
1217 render_view_host()->PrintingDone(document_cookie, success);
1218}
1219
[email protected]420ae012009-04-24 05:16:321220bool TabContents::IsActiveEntry(int32 page_id) {
1221 NavigationEntry* active_entry = controller_.GetActiveEntry();
1222 return (active_entry != NULL &&
1223 active_entry->site_instance() == GetSiteInstance() &&
1224 active_entry->page_id() == page_id);
1225}
1226
[email protected]b2fe07d12010-02-09 14:38:081227void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161228 set_encoding(encoding);
1229 render_view_host()->SetPageEncoding(encoding);
1230}
1231
[email protected]b2fe07d12010-02-09 14:38:081232void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161233 reset_encoding();
1234 render_view_host()->ResetPageEncodingToDefault();
1235}
1236
1237void TabContents::WindowMoveOrResizeStarted() {
1238 render_view_host()->WindowMoveOrResizeStarted();
1239}
1240
[email protected]c65e2f152010-10-14 15:30:401241void TabContents::SetAllContentsBlocked(bool value) {
1242 if (all_contents_blocked_ == value)
1243 return;
1244
1245 all_contents_blocked_ = value;
1246 if (!all_contents_blocked_ && blocked_contents_) {
1247 std::vector<TabContents*> blocked;
1248 blocked_contents_->GetBlockedContents(&blocked);
1249 for (size_t i = 0; i < blocked.size(); ++i)
1250 blocked_contents_->LaunchForContents(blocked[i]);
1251 }
1252}
1253
[email protected]3f8eb7f2009-10-02 23:58:051254void TabContents::LogNewTabTime(const std::string& event_name) {
1255 // Not all new tab pages get timed. In those cases, we don't have a
1256 // new_tab_start_time_.
1257 if (new_tab_start_time_.is_null())
1258 return;
1259
1260 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441261 MetricEventDurationDetails details(event_name,
1262 static_cast<int>(duration.InMilliseconds()));
1263
[email protected]7ab1e7d62009-10-14 23:32:011264 if (event_name == "Tab.NewTabScriptStart") {
1265 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1266 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1267 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1268 } else if (event_name == "Tab.NewTabOnload") {
1269 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051270 // The new tab page has finished loading; reset it.
1271 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441272 } else {
1273 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051274 }
[email protected]84abba62009-10-07 17:01:441275 NotificationService::current()->Notify(
1276 NotificationType::METRIC_EVENT_DURATION,
1277 Source<TabContents>(this),
1278 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051279}
1280
[email protected]7ab1e7d62009-10-14 23:32:011281void TabContents::OnCloseStarted() {
1282 if (tab_close_start_time_.is_null())
1283 tab_close_start_time_ = base::TimeTicks::Now();
1284}
1285
[email protected]46624bf2010-06-09 16:04:191286bool TabContents::ShouldAcceptDragAndDrop() const {
1287#if defined(OS_CHROMEOS)
1288 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1289 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201290 if (delegate() && delegate()->IsPopup(this))
1291 return false;
1292 return true;
[email protected]46624bf2010-06-09 16:04:191293#else
1294 return true;
1295#endif
1296}
1297
[email protected]7813bd72011-02-05 02:19:341298void TabContents::SystemDragEnded() {
1299 if (render_view_host())
1300 render_view_host()->DragSourceSystemDragEnded();
1301 if (delegate())
1302 delegate()->DragEnded();
1303}
1304
[email protected]ec0b6c42010-08-26 03:16:581305void TabContents::UpdateHistoryForNavigation(
1306 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1307 if (profile()->IsOffTheRecord())
1308 return;
1309
1310 // Add to history service.
1311 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1312 if (hs)
1313 hs->AddPage(*add_page_args);
1314}
1315
1316void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1317 if (profile()->IsOffTheRecord())
1318 return;
1319
1320 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1321 if (hs)
1322 hs->SetPageTitle(entry.virtual_url(), entry.title());
1323}
1324
[email protected]d0b8d092010-10-25 04:05:171325double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251326 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1327 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171328 return 0;
[email protected]b75b8292010-10-01 07:28:251329
1330 double zoom_level;
1331 if (temporary_zoom_settings_) {
1332 zoom_level = zoom_map->GetTemporaryZoomLevel(
1333 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1334 } else {
1335 zoom_level = zoom_map->GetZoomLevel(GetURL());
1336 }
[email protected]d0b8d092010-10-25 04:05:171337 return zoom_level;
1338}
[email protected]b75b8292010-10-01 07:28:251339
[email protected]d0b8d092010-10-25 04:05:171340int TabContents::GetZoomPercent(bool* enable_increment,
1341 bool* enable_decrement) {
1342 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251343 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171344 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251345 *enable_decrement = percent > minimum_zoom_percent_;
1346 *enable_increment = percent < maximum_zoom_percent_;
1347 return percent;
1348}
1349
[email protected]3c733bde2010-12-21 19:56:311350void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501351 if (!delegate_)
1352 return;
1353
1354 NavigationEntry* active_entry = controller().GetActiveEntry();
1355 if (!active_entry)
1356 return;
1357
1358 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121359}
1360
[email protected]724159a2010-12-30 01:11:181361void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1362 bool is_main_frame,
1363 const GURL& url) {
1364 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1365 GURL validated_url(url);
1366 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1367 GetRenderProcessHost()->id(), &validated_url);
1368
1369 ProvisionalLoadDetails details(
1370 is_main_frame,
1371 controller_.IsURLInPageNavigation(validated_url),
1372 validated_url, std::string(), false, is_error_page, frame_id);
1373 NotificationService::current()->Notify(
1374 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1375 Source<NavigationController>(&controller_),
1376 Details<ProvisionalLoadDetails>(&details));
1377 if (is_main_frame) {
1378 // If we're displaying a network error page do not reset the content
1379 // settings delegate's cookies so the user has a chance to modify cookie
1380 // settings.
1381 if (!is_error_page)
1382 content_settings_delegate_->ClearCookieSpecificContentSettings();
1383 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]f72298c2011-02-22 19:56:141384 // TODO(cbentzel): Should error pages still show prerendered icon?
1385 set_was_prerendered(false);
[email protected]e7d50892011-01-19 21:47:381386
1387 // Check if the URL we are about to load has been prerendered by any chance,
1388 // and use it if possible.
1389 MaybeUsePreloadedPage(url);
[email protected]724159a2010-12-30 01:11:181390 }
1391}
1392
1393void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1394 const GURL& source_url,
1395 const GURL& target_url) {
1396 NavigationEntry* entry;
1397 if (page_id == -1)
1398 entry = controller_.pending_entry();
1399 else
1400 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1401 if (!entry || entry->url() != source_url)
1402 return;
1403 entry->set_url(target_url);
[email protected]e7d50892011-01-19 21:47:381404
1405 // Check if the URL we are about to load has been prerendered by any chance,
1406 // and use it if possible.
1407 MaybeUsePreloadedPage(target_url);
[email protected]724159a2010-12-30 01:11:181408}
1409
1410void TabContents::OnDidFailProvisionalLoadWithError(
1411 int64 frame_id,
1412 bool is_main_frame,
1413 int error_code,
1414 const GURL& url,
1415 bool showing_repost_interstitial) {
1416 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1417 << ", error_code: " << error_code
1418 << " is_main_frame: " << is_main_frame
1419 << " showing_repost_interstitial: " << showing_repost_interstitial
1420 << " frame_id: " << frame_id;
1421 GURL validated_url(url);
1422 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1423 GetRenderProcessHost()->id(), &validated_url);
1424
1425 if (net::ERR_ABORTED == error_code) {
1426 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1427 // This means that the interstitial won't be torn down properly, which is
1428 // bad. But if we have an interstitial, go back to another tab type, and
1429 // then load the same interstitial again, we could end up getting the first
1430 // interstitial's "failed" message (as a result of the cancel) when we're on
1431 // the second one.
1432 //
1433 // We can't tell this apart, so we think we're tearing down the current page
1434 // which will cause a crash later one. There is also some code in
1435 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1436 // out because of this problem.
1437 //
1438 // http://code.google.com/p/chromium/issues/detail?id=2855
1439 // Because this will not tear down the interstitial properly, if "back" is
1440 // back to another tab type, the interstitial will still be somewhat alive
1441 // in the previous tab type. If you navigate somewhere that activates the
1442 // tab with the interstitial again, you'll see a flash before the new load
1443 // commits of the interstitial page.
1444 if (showing_interstitial_page()) {
1445 LOG(WARNING) << "Discarding message during interstitial.";
1446 return;
1447 }
1448
1449 // This will discard our pending entry if we cancelled the load (e.g., if we
1450 // decided to download the file instead of load it). Only discard the
1451 // pending entry if the URLs match, otherwise the user initiated a navigate
1452 // before the page loaded so that the discard would discard the wrong entry.
1453 NavigationEntry* pending_entry = controller_.pending_entry();
1454 if (pending_entry && pending_entry->url() == validated_url) {
1455 controller_.DiscardNonCommittedEntries();
1456 // Update the URL display.
1457 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1458 }
1459
1460 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1461 }
1462
1463 // Send out a notification that we failed a provisional load with an error.
1464 ProvisionalLoadDetails details(
1465 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
1466 validated_url, std::string(), false, false, frame_id);
1467 details.set_error_code(error_code);
1468
1469 NotificationService::current()->Notify(
1470 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1471 Source<NavigationController>(&controller_),
1472 Details<ProvisionalLoadDetails>(&details));
1473}
1474
1475void TabContents::OnDidLoadResourceFromMemoryCache(
1476 const GURL& url,
[email protected]724159a2010-12-30 01:11:181477 const std::string& security_info) {
1478 static base::StatsCounter cache("WebKit.CacheHit");
1479 cache.Increment();
1480
1481 // Send out a notification that we loaded a resource from our memory cache.
1482 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1483 SSLManager::DeserializeSecurityInfo(security_info,
1484 &cert_id, &cert_status,
1485 &security_bits,
1486 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161487 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1488 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181489
1490 NotificationService::current()->Notify(
1491 NotificationType::LOAD_FROM_MEMORY_CACHE,
1492 Source<NavigationController>(&controller_),
1493 Details<LoadFromMemoryCacheDetails>(&details));
1494}
1495
1496void TabContents::OnDidDisplayInsecureContent() {
1497 displayed_insecure_content_ = true;
1498 SSLManager::NotifySSLInternalStateChanged();
1499}
1500
1501void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021502 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231503 LOG(INFO) << security_origin << " ran insecure content from "
1504 << target_url.possibly_invalid_spec();
[email protected]724159a2010-12-30 01:11:181505 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1506}
1507
1508void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1509 controller_.DocumentLoadedInFrame();
1510 NotificationService::current()->Notify(
1511 NotificationType::FRAME_DOM_CONTENT_LOADED,
1512 Source<NavigationController>(&controller_),
1513 Details<int64>(&frame_id));
1514}
1515
1516void TabContents::OnDidFinishLoad(int64 frame_id) {
1517 NotificationService::current()->Notify(
1518 NotificationType::FRAME_DID_FINISH_LOAD,
1519 Source<NavigationController>(&controller_),
1520 Details<int64>(&frame_id));
1521}
1522
[email protected]c8f73ab2011-01-22 00:05:171523void TabContents::OnUpdateContentRestrictions(int restrictions) {
1524 content_restrictions_ = restrictions;
1525 delegate()->ContentRestrictionsChanged(this);
1526}
1527
1528void TabContents::OnPDFHasUnsupportedFeature() {
1529 PDFHasUnsupportedFeature(this);
1530}
1531
[email protected]96d185d2009-04-24 03:28:541532// Notifies the RenderWidgetHost instance about the fact that the page is
1533// loading, or done loading and calls the base implementation.
1534void TabContents::SetIsLoading(bool is_loading,
1535 LoadNotificationDetails* details) {
1536 if (is_loading == is_loading_)
1537 return;
1538
1539 if (!is_loading) {
1540 load_state_ = net::LOAD_STATE_IDLE;
1541 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561542 upload_size_ = 0;
1543 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541544 }
1545
1546 render_manager_.SetIsLoading(is_loading);
1547
1548 is_loading_ = is_loading;
1549 waiting_for_response_ = is_loading;
1550
[email protected]6ebdc9b2010-09-27 16:55:571551 if (delegate_)
1552 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351553 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541554
1555 NotificationType type = is_loading ? NotificationType::LOAD_START :
1556 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111557 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541558 if (details)
1559 det = Details<LoadNotificationDetails>(details);
1560 NotificationService::current()->Notify(type,
1561 Source<NavigationController>(&controller_),
1562 det);
1563}
1564
[email protected]b6c874582009-05-08 19:38:311565void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291566 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061567 // A page can't spawn popups (or do anything else, either) until its load
1568 // commits, so when we reach here, the popup was spawned by the
1569 // NavigationController's last committed entry, not the active entry. For
1570 // example, if a page opens a popup in an onunload() handler, then the active
1571 // entry is the page to be loaded as we navigate away from the unloading
1572 // page. For this reason, we can't use GetURL() to get the opener URL,
1573 // because it returns the active entry.
1574 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1575 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1576
1577 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491578 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091579 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491580 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1581 } else {
[email protected]c65e2f152010-10-14 15:30:401582 if (!blocked_contents_)
1583 blocked_contents_ = new BlockedContentContainer(this);
1584 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1585 true);
[email protected]55126132010-08-19 14:53:281586 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1587 std::string());
[email protected]8cc8d492010-02-02 10:40:491588 }
[email protected]b9681312008-11-07 00:08:261589}
[email protected]616ed5a2008-11-21 22:27:241590
[email protected]616ed5a2008-11-21 22:27:241591void TabContents::ExpireInfoBars(
1592 const NavigationController::LoadCommittedDetails& details) {
1593 // Only hide InfoBars when the user has done something that makes the main
1594 // frame load. We don't want various automatic or subframe navigations making
1595 // it disappear.
1596 if (!details.is_user_initiated_main_frame_load())
1597 return;
1598
[email protected]ec8f51162011-02-08 04:20:401599 // NOTE: It is not safe to change the following code to count upwards or use
1600 // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
1601 // list.
1602 for (size_t i = infobar_count(); i > 0; --i) {
1603 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
[email protected]f86a07022008-11-25 01:06:051604 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241605 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241606 }
1607}
[email protected]fdd61c62009-04-22 19:22:571608
[email protected]d0980792011-02-13 19:41:401609WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581610 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541611 // that goes along with it to control the basic flags. For example, we want to
1612 // show the pending URL in the URL bar, so we want the display_url flag to
1613 // be from the pending entry.
1614 //
1615 // The confusion comes because there are multiple possibilities for the
1616 // initial load in a tab as a side effect of the way the RenderViewHostManager
1617 // works.
1618 //
[email protected]e0112912011-02-02 22:54:351619 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541620 // the pending one, and we want it to apply here.
1621 //
1622 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1623 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581624 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351625 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541626 //
1627 // This condition handles all of these cases:
1628 //
1629 // - First load in first tab: no committed nav entry + pending nav entry +
1630 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351631 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541632 //
1633 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351634 // no pending Web UI:
1635 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541636 //
1637 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351638 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541639 //
1640 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351641 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541642 if (controller_.pending_entry() &&
1643 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581644 render_manager_.pending_web_ui()))
1645 return render_manager_.pending_web_ui();
1646 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541647}
[email protected]420ae012009-04-24 05:16:321648
1649void TabContents::DidNavigateMainFramePostCommit(
1650 const NavigationController::LoadCommittedDetails& details,
1651 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]80a8fad2011-01-29 04:02:381652 if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) {
1653 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441654 // that opened the window, as long as both renderers have the same
1655 // privileges.
[email protected]80a8fad2011-01-29 04:02:381656 if (opener_web_ui_type_ ==
1657 WebUIFactory::GetWebUIType(profile(), GetURL())) {
[email protected]7ade2732011-02-10 00:13:581658 WebUI* web_ui = WebUIFactory::CreateWebUIForURL(this, GetURL());
1659 // web_ui might be NULL if the URL refers to a non-existent extension.
1660 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401661 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581662 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441663 }
1664 }
[email protected]80a8fad2011-01-29 04:02:381665 opener_web_ui_type_ = WebUIFactory::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441666 }
1667
[email protected]420ae012009-04-24 05:16:321668 if (details.is_user_initiated_main_frame_load()) {
1669 // Clear the status bubble. This is a workaround for a bug where WebKit
1670 // doesn't let us know that the cursor left an element during a
1671 // transition (this is also why the mouse cursor remains as a hand after
1672 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1673 // clear the bubble when a user navigates to a named anchor in the same
1674 // page.
1675 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321676 }
1677
[email protected]420ae012009-04-24 05:16:321678 // Allow the new page to set the title again.
1679 received_page_title_ = false;
1680
1681 // Get the favicon, either from history or request it from the net.
[email protected]b5a1d11c2011-02-17 03:09:421682 fav_icon_helper_->FetchFavIcon(details.entry->url());
[email protected]420ae012009-04-24 05:16:321683
[email protected]0de80162010-02-03 04:52:351684 // Clear all page actions, blocked content notifications and browser actions
1685 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141686 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:001687 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:081688 if (service) {
1689 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571690 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081691 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521692 if (browser_action) {
1693 browser_action->ClearAllValuesForTab(controller().session_id().id());
1694 NotificationService::current()->Notify(
1695 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571696 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521697 NotificationService::NoDetails());
1698 }
[email protected]92c6f9b92009-10-24 04:35:081699
[email protected]5d246db22009-10-27 06:17:571700 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521701 service->extensions()->at(i)->page_action();
1702 if (page_action) {
1703 page_action->ClearAllValuesForTab(controller().session_id().id());
1704 PageActionStateChanged();
1705 }
[email protected]92c6f9b92009-10-24 04:35:081706 }
[email protected]aece2c7f2009-08-27 20:43:171707 }
[email protected]0de80162010-02-03 04:52:351708
1709 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401710 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341711 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401712 blocked_contents_->Destroy();
1713 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351714 }
1715
1716 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411717 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551718 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471719
1720 // Once the main frame is navigated, we're no longer considered to have
1721 // displayed insecure content.
1722 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171723 }
[email protected]ce5c4502009-05-06 16:46:111724
[email protected]8cc8d492010-02-02 10:40:491725 // Close constrained windows if necessary.
1726 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1727 details.previous_url, details.entry->url()))
1728 CloseConstrainedWindows();
1729
[email protected]3c9e1872010-11-18 16:17:491730 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171731 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491732 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321733}
1734
1735void TabContents::DidNavigateAnyFramePostCommit(
1736 RenderViewHost* render_view_host,
1737 const NavigationController::LoadCommittedDetails& details,
1738 const ViewHostMsg_FrameNavigate_Params& params) {
1739 // If we navigate, start showing messages again. This does nothing to prevent
1740 // a malicious script from spamming messages, since the script could just
1741 // reload the page to stop blocking.
1742 suppress_javascript_messages_ = false;
1743
[email protected]3c9e1872010-11-18 16:17:491744 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171745 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491746 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551747
1748 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581749 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321750}
1751
[email protected]8cc8d492010-02-02 10:40:491752void TabContents::CloseConstrainedWindows() {
1753 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321754 // We use indices instead of iterators in case CloseWindow does something
1755 // that may invalidate an iterator.
[email protected]61d68ef12011-01-13 14:02:561756 for (size_t i = 0; i < child_windows_.size(); ++i) {
1757 ConstrainedWindow* window = child_windows_[child_windows_.size() - 1 - i];
[email protected]fa1cf0b82010-01-15 21:49:441758 if (window) {
[email protected]420ae012009-04-24 05:16:321759 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441760 BlockTabContent(false);
1761 }
[email protected]420ae012009-04-24 05:16:321762 }
1763}
1764
[email protected]420ae012009-04-24 05:16:321765void TabContents::UpdateAlternateErrorPageURL() {
1766 GURL url = GetAlternateErrorPageURL();
1767 render_view_host()->SetAlternateErrorPageURL(url);
1768}
1769
1770void TabContents::UpdateWebPreferences() {
1771 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1772}
1773
[email protected]d0b8d092010-10-25 04:05:171774void TabContents::UpdateZoomLevel() {
1775 render_view_host()->SetZoomLevel(GetZoomLevel());
1776}
1777
[email protected]420ae012009-04-24 05:16:321778void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1779 RenderViewHost* rvh) {
1780 // If we are creating a RVH for a restored controller, then we might
1781 // have more page IDs than the SiteInstance's current max page ID. We must
1782 // make sure that the max page ID is larger than any restored page ID.
1783 // Note that it is ok for conflicting page IDs to exist in another tab
1784 // (i.e., NavigationController), but if any page ID is larger than the max,
1785 // the back/forward list will get confused.
1786 int max_restored_page_id = controller_.max_restored_page_id();
1787 if (max_restored_page_id > 0) {
1788 int curr_max_page_id = site_instance->max_page_id();
1789 if (max_restored_page_id > curr_max_page_id) {
1790 // Need to update the site instance immediately.
1791 site_instance->UpdateMaxPageID(max_restored_page_id);
1792
1793 // Also tell the renderer to update its internal representation. We
1794 // need to reserve enough IDs to make all restored page IDs less than
1795 // the max.
1796 if (curr_max_page_id < 0)
1797 curr_max_page_id = 0;
1798 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1799 }
1800 }
1801}
1802
[email protected]ec0b6c42010-08-26 03:16:581803scoped_refptr<history::HistoryAddPageArgs>
1804TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541805 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471806 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321807 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581808 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1809 new history::HistoryAddPageArgs(
1810 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1811 params.redirects, params.transition, history::SOURCE_BROWSED,
1812 details.did_replace_entry));
1813 if (PageTransition::IsMainFrame(params.transition) &&
1814 virtual_url != params.url) {
1815 // Hack on the "virtual" URL so that it will appear in history. For some
1816 // types of URLs, we will display a magic URL that is different from where
1817 // the page is actually navigated. We want the user to see in history what
1818 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1819 // only applies to the main frame, as the virtual URL doesn't apply to
1820 // sub-frames.
1821 add_page_args->url = virtual_url;
1822 if (!add_page_args->redirects.empty())
1823 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321824 }
[email protected]ec0b6c42010-08-26 03:16:581825 return add_page_args;
[email protected]420ae012009-04-24 05:16:321826}
1827
1828bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1829 const std::wstring& title) {
1830 // For file URLs without a title, use the pathname instead. In the case of a
1831 // synthesized title, we don't want the update to count toward the "one set
1832 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251833 string16 final_title;
[email protected]420ae012009-04-24 05:16:321834 bool explicit_set;
1835 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251836 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321837 explicit_set = false; // Don't count synthetic titles toward the set limit.
1838 } else {
[email protected]e53668962010-06-23 15:35:251839 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321840 explicit_set = true;
1841 }
1842
[email protected]e53668962010-06-23 15:35:251843 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321844 return false; // Nothing changed, don't bother.
1845
[email protected]e53668962010-06-23 15:35:251846 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321847
[email protected]ec0b6c42010-08-26 03:16:581848 if (!received_page_title_) {
1849 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321850 received_page_title_ = explicit_set;
1851 }
1852
1853 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251854 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321855
[email protected]cbc0e1b2010-04-12 18:33:041856 NotificationService::current()->Notify(
1857 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1858 Source<TabContents>(this),
1859 NotificationService::NoDetails());
1860
[email protected]420ae012009-04-24 05:16:321861 return true;
1862}
1863
1864void TabContents::NotifySwapped() {
1865 // After sending out a swap notification, we need to send a disconnect
1866 // notification so that clients that pick up a pointer to |this| can NULL the
1867 // pointer. See Bug 1230284.
1868 notify_disconnection_ = true;
1869 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341870 NotificationType::TAB_CONTENTS_SWAPPED,
[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::NotifyConnected() {
1876 notify_disconnection_ = true;
1877 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341878 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221879 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321880 NotificationService::NoDetails());
1881}
1882
1883void TabContents::NotifyDisconnected() {
1884 if (!notify_disconnection_)
1885 return;
1886
1887 notify_disconnection_ = false;
1888 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341889 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221890 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321891 NotificationService::NoDetails());
1892}
1893
[email protected]7d472472011-01-22 01:30:251894void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541895 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1896 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1897 if (!entry)
1898 return;
1899 // Note that we don't call NavigationController::GotToOffset() as we don't
1900 // want to create a pending navigation entry (it might end up lingering
1901 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:521902 entry->set_transition_type(entry->transition_type() |
1903 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:541904 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
1905 }
[email protected]bf5c2ff392009-07-08 16:24:331906}
1907
[email protected]38789d82010-11-17 06:03:441908void TabContents::OnDidGetApplicationInfo(int32 page_id,
1909 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511910 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331911
[email protected]ed5431872009-11-17 08:39:511912 if (delegate())
1913 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331914}
1915
[email protected]bb461532010-11-26 21:50:231916void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
1917 if (delegate())
1918 delegate()->OnInstallApplication(this, info);
1919}
1920
[email protected]a2cf65eb2010-01-18 08:20:381921void TabContents::OnPageContents(const GURL& url,
[email protected]a2cf65eb2010-01-18 08:20:381922 int32 page_id,
[email protected]e5106202010-06-11 21:12:361923 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:101924 const std::string& language,
1925 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:381926 // Don't index any https pages. People generally don't want their bank
1927 // accounts, etc. indexed on their computer, especially since some of these
1928 // things are not marked cachable.
1929 // TODO(brettw) we may want to consider more elaborate heuristics such as
1930 // the cachability of the page. We may also want to consider subframes (this
1931 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271932 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1933 // content indexing for chromeos in some future releases.
1934#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381935 if (!url.SchemeIsSecure()) {
1936 Profile* p = profile();
1937 if (p && !p->IsOffTheRecord()) {
1938 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1939 if (hs)
1940 hs->SetPageContents(url, contents);
1941 }
1942 }
[email protected]ccd40a52010-05-11 16:15:271943#endif
[email protected]a8a81292010-01-21 00:32:451944
[email protected]1c57b7b2010-07-12 17:38:101945 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:451946
1947 std::string lang = language;
1948 NotificationService::current()->Notify(
1949 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151950 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451951 Details<std::string>(&lang));
[email protected]d54169e92011-01-21 09:19:521952
1953 // Generate the thumbnail here if the in-browser thumbnailing is enabled.
1954 if (CommandLine::ForCurrentProcess()->HasSwitch(
1955 switches::kEnableInBrowserThumbnailing)) {
1956 ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url);
1957 }
[email protected]a2cf65eb2010-01-18 08:20:381958}
1959
[email protected]7e0831b2010-02-01 08:45:151960void TabContents::OnPageTranslated(int32 page_id,
1961 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:161962 const std::string& translated_lang,
1963 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:551964 language_state_.set_current_language(translated_lang);
1965 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:161966 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:151967 NotificationService::current()->Notify(
1968 NotificationType::PAGE_TRANSLATED,
1969 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:161970 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:151971}
1972
[email protected]a6d36cc2011-02-23 00:39:481973void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1974 const GURL& url,
1975 const string16& title) {
1976 ProtocolHandlerRegistry* registry = profile()->GetProtocolHandlerRegistry();
1977 ProtocolHandler* handler = ProtocolHandler::CreateProtocolHandler(protocol,
1978 url,
1979 title);
1980 if (handler != NULL) {
1981 RegisterProtocolHandlerInfoBarDelegate::AttemptRegisterProtocolHandler(
1982 this, registry, handler);
1983 }
1984}
1985
[email protected]ce833282010-11-04 15:48:391986void TabContents::OnSetSuggestions(
1987 int32 page_id,
1988 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:261989 if (delegate())
[email protected]ce833282010-11-04 15:48:391990 delegate()->OnSetSuggestions(page_id, suggestions);
1991}
1992
1993void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
1994 if (delegate())
1995 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:261996}
1997
[email protected]34f128d2011-01-25 19:07:441998void TabContents::OnRunFileChooser(
1999 const ViewHostMsg_RunFileChooser_Params& params) {
2000 if (file_select_helper_.get() == NULL)
2001 file_select_helper_.reset(new FileSelectHelper(profile()));
2002 file_select_helper_->RunFileChooser(render_view_host(), params);
2003}
2004
2005
[email protected]dcd5b332010-08-11 08:55:182006void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562007 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242008 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562009}
2010
[email protected]8d3347f2009-07-09 22:00:212011RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322012 return view_.get();
2013}
2014
[email protected]8d3347f2009-07-09 22:00:212015RenderViewHostDelegate::RendererManagement*
2016TabContents::GetRendererManagementDelegate() {
2017 return &render_manager_;
2018}
2019
[email protected]46ba9082010-06-22 10:00:582020RenderViewHostDelegate::ContentSettings*
2021TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552022 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582023}
2024
[email protected]1f18184a2010-07-21 19:34:492025RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2026 return GetSSLHelper();
2027}
2028
[email protected]fd571bb2010-03-19 01:23:542029AutomationResourceRoutingDelegate*
2030TabContents::GetAutomationResourceRoutingDelegate() {
2031 return delegate();
2032}
2033
[email protected]ced90ae12010-02-20 02:06:162034RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2035 return bookmark_drag_;
2036}
2037
2038void TabContents::SetBookmarkDragDelegate(
2039 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2040 bookmark_drag_ = bookmark_drag;
2041}
2042
[email protected]9fb83e82010-07-02 18:24:552043TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2044 return content_settings_delegate_.get();
2045}
2046
[email protected]93623c5d2009-12-10 21:40:322047RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462048 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512049}
2050
[email protected]57c6a652009-05-04 07:58:342051TabContents* TabContents::GetAsTabContents() {
2052 return this;
2053}
2054
[email protected]7b291f92009-08-14 05:43:532055ViewType::Type TabContents::GetRenderViewType() const {
2056 return ViewType::TAB_CONTENTS;
2057}
2058
2059int TabContents::GetBrowserWindowID() const {
2060 return controller().window_id().id();
2061}
2062
[email protected]420ae012009-04-24 05:16:322063void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062064 NotificationService::current()->Notify(
2065 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2066 Source<TabContents>(this),
2067 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322068 NavigationEntry* entry = controller_.GetActiveEntry();
2069 if (!entry)
2070 return;
2071
2072 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352073 // use the pending Web UI rather than any possibly existing committed one.
[email protected]7ade2732011-02-10 00:13:582074 if (render_manager_.pending_web_ui()) {
2075 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322076 }
2077
2078 if (entry->IsViewSourceMode()) {
2079 // Put the renderer in view source mode.
2080 render_view_host->Send(
2081 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2082 }
[email protected]0666aef2009-05-13 19:48:082083
2084 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322085}
2086
2087void TabContents::RenderViewReady(RenderViewHost* rvh) {
2088 if (rvh != render_view_host()) {
2089 // Don't notify the world, since this came from a renderer in the
2090 // background.
2091 return;
2092 }
2093
2094 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302095 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232096 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302097
2098 // Restore the focus to the tab (otherwise the focus will be on the top
2099 // window).
[email protected]484ae5912010-09-29 19:16:142100 if (was_crashed && !FocusLocationBarByDefault() &&
2101 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302102 Focus();
[email protected]484ae5912010-09-29 19:16:142103 }
[email protected]420ae012009-04-24 05:16:322104}
2105
[email protected]443b80e2010-12-14 00:42:232106void TabContents::RenderViewGone(RenderViewHost* rvh,
2107 base::TerminationStatus status,
2108 int error_code) {
[email protected]420ae012009-04-24 05:16:322109 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092110 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322111 return;
2112 if (rvh != render_view_host()) {
2113 // The pending page's RenderViewHost is gone.
2114 return;
2115 }
2116
2117 SetIsLoading(false, NULL);
2118 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232119 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322120
[email protected]ff9efc62010-02-18 22:10:542121 // Remove all infobars.
[email protected]ec8f51162011-02-08 04:20:402122 while (!infobar_delegates_.empty())
2123 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
[email protected]ff9efc62010-02-18 22:10:542124
[email protected]8e537302009-06-10 21:19:582125 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552126 // Only do this if we're not in browser shutdown, so that TabContents
2127 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2128 // visible do not flash a sad tab page.
2129 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:162130 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322131
2132 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002133 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322134}
2135
[email protected]2e4633c2009-07-09 16:58:062136void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2137 NotificationService::current()->Notify(
2138 NotificationType::RENDER_VIEW_HOST_DELETED,
2139 Source<TabContents>(this),
2140 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482141 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062142}
2143
[email protected]420ae012009-04-24 05:16:322144void TabContents::DidNavigate(RenderViewHost* rvh,
2145 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372146 int extra_invalidate_flags = 0;
2147
2148 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]e7d50892011-01-19 21:47:382149 if (MaybeUsePreloadedPage(params.url)) {
2150 return;
[email protected]33f74972010-12-08 16:40:362151 }
2152
[email protected]20ede072009-10-06 00:28:352153 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372154
[email protected]420ae012009-04-24 05:16:322155 render_manager_.DidNavigateMainFrame(rvh);
2156
[email protected]20ede072009-10-06 00:28:352157 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372158 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372159 }
2160
[email protected]420ae012009-04-24 05:16:322161 // Update the site of the SiteInstance if it doesn't have one yet.
2162 if (!GetSiteInstance()->has_site())
2163 GetSiteInstance()->SetSite(params.url);
2164
2165 // Need to update MIME type here because it's referred to in
2166 // UpdateNavigationCommands() called by RendererDidNavigate() to
2167 // determine whether or not to enable the encoding menu.
2168 // It's updated only for the main frame. For a subframe,
2169 // RenderView::UpdateURL does not set params.contents_mime_type.
2170 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2171 // TODO(jungshik): Add a test for the encoding menu to avoid
2172 // regressing it again.
2173 if (PageTransition::IsMainFrame(params.transition))
2174 contents_mime_type_ = params.contents_mime_type;
2175
2176 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372177 bool did_navigate = controller_.RendererDidNavigate(
2178 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392179
[email protected]a9c0bfe2010-09-17 08:35:222180 // Send notification about committed provisional loads. This notification is
2181 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2182 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2183 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072184 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2185 // that is not recorded in the navigation history. For the purpose of
2186 // tracking navigation events, we treat this event as a sub frame navigation
2187 // event.
2188 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2189 ProvisionalLoadDetails load_details(
2190 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412191 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222192 load_details.set_transition_type(params.transition);
2193 // Whether or not a page transition was triggered by going backward or
2194 // forward in the history is only stored in the navigation controller's
2195 // entry list.
2196 if (did_navigate &&
2197 (controller_.GetActiveEntry()->transition_type() &
2198 PageTransition::FORWARD_BACK)) {
2199 load_details.set_transition_type(
2200 params.transition | PageTransition::FORWARD_BACK);
2201 }
2202 NotificationService::current()->Notify(
2203 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2204 Source<NavigationController>(&controller_),
2205 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222206 }
2207
[email protected]3e90d4a2009-07-03 17:38:392208 // Update history. Note that this needs to happen after the entry is complete,
2209 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582210 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392211 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582212 // URLs, we use a data: URL as the real value. We actually want to save the
2213 // about: URL to the history db and keep the data: URL hidden. This is what
2214 // the TabContents' URL getter does.
2215 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2216 CreateHistoryAddPageArgs(GetURL(), details, params));
2217 if (!delegate() ||
2218 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2219 details.type)) {
2220 UpdateHistoryForNavigation(add_page_args);
2221 }
[email protected]3e90d4a2009-07-03 17:38:392222 }
2223
[email protected]76543b92009-08-31 17:27:452224 if (!did_navigate)
2225 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322226
2227 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2228 // for the appropriate notification (best) or you can add it to
2229 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2230 // necessary, please).
2231
2232 // Run post-commit tasks.
2233 if (details.is_main_frame)
2234 DidNavigateMainFramePostCommit(details, params);
2235 DidNavigateAnyFramePostCommit(rvh, details, params);
2236}
2237
2238void TabContents::UpdateState(RenderViewHost* rvh,
2239 int32 page_id,
2240 const std::string& state) {
2241 DCHECK(rvh == render_view_host());
2242
2243 // We must be prepared to handle state updates for any page, these occur
2244 // when the user is scrolling and entering form data, as well as when we're
2245 // leaving a page, in which case our state may have already been moved to
2246 // the next page. The navigation controller will look up the appropriate
2247 // NavigationEntry and update it when it is notified via the delegate.
2248
2249 int entry_index = controller_.GetEntryIndexWithPageID(
2250 GetSiteInstance(), page_id);
2251 if (entry_index < 0)
2252 return;
2253 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2254
2255 if (state == entry->content_state())
2256 return; // Nothing to update.
2257 entry->set_content_state(state);
2258 controller_.NotifyEntryChanged(entry, entry_index);
2259}
2260
2261void TabContents::UpdateTitle(RenderViewHost* rvh,
2262 int32 page_id, const std::wstring& title) {
2263 // If we have a title, that's a pretty good indication that we've started
2264 // getting useful data.
2265 SetNotWaitingForResponse();
2266
2267 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482268 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582269 page_id);
[email protected]420ae012009-04-24 05:16:322270 if (!entry || !UpdateTitleForEntry(entry, title))
2271 return;
2272
2273 // Broadcast notifications when the UI should be updated.
2274 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032275 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322276}
2277
[email protected]420ae012009-04-24 05:16:322278void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402279 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322280 set_encoding(encoding);
2281}
2282
2283void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2284 if (delegate())
2285 delegate()->UpdateTargetURL(this, url);
2286}
2287
2288void TabContents::UpdateThumbnail(const GURL& url,
2289 const SkBitmap& bitmap,
2290 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442291 if (profile()->IsOffTheRecord())
2292 return;
2293
[email protected]420ae012009-04-24 05:16:322294 // Tell History about this thumbnail
[email protected]54097492f2011-01-18 08:32:072295 history::TopSites* ts = profile()->GetTopSites();
2296 if (ts)
2297 ts->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322298}
2299
[email protected]c4e98902010-06-01 10:20:142300void TabContents::UpdateInspectorSetting(const std::string& key,
2301 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052302 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082303}
2304
[email protected]45aafc92010-06-07 14:18:532305void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052306 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532307}
2308
[email protected]420ae012009-04-24 05:16:322309void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292310 // The UI may be in an event-tracking loop, such as between the
2311 // mouse-down and mouse-up in text selection or a button click.
2312 // Defer the close until after tracking is complete, so that we
2313 // don't free objects out from under the UI.
2314 // TODO(shess): This could probably be integrated with the
2315 // IsDoingDrag() test below. Punting for now because I need more
2316 // research to understand how this impacts platforms other than Mac.
2317 // TODO(shess): This could get more fine-grained. For instance,
2318 // closing a tab in another window while selecting text in the
2319 // current window's Omnibox should be just fine.
2320 if (view()->IsEventTracking()) {
2321 view()->CloseTabAfterEventTracking();
2322 return;
2323 }
2324
[email protected]24a4d1062009-07-10 23:10:422325 // If we close the tab while we're in the middle of a drag, we'll crash.
2326 // Instead, cancel the drag and close it as soon as the drag ends.
2327 if (view()->IsDoingDrag()) {
2328 view()->CancelDragAndCloseTab();
2329 return;
2330 }
2331
[email protected]420ae012009-04-24 05:16:322332 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2333 if (delegate() && rvh == render_view_host())
2334 delegate()->CloseContents(this);
2335}
2336
2337void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2338 if (delegate() && delegate()->IsPopup(this))
2339 delegate()->MoveContents(this, new_bounds);
2340}
2341
[email protected]7ab1e7d62009-10-14 23:32:012342void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322343 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492344
[email protected]de4761b2010-12-07 21:05:212345 if (delegate()) {
2346 bool is_print_preview_tab =
2347 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2348 if (content_restrictions_ || is_print_preview_tab) {
2349 content_restrictions_= is_print_preview_tab ?
2350 CONTENT_RESTRICTION_PRINT : 0;
2351 delegate()->ContentRestrictionsChanged(this);
2352 }
[email protected]9e823662010-10-13 23:36:002353 }
[email protected]3c9e1872010-11-18 16:17:492354
2355 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172356 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322357}
2358
[email protected]7ab1e7d62009-10-14 23:32:012359void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322360 scoped_ptr<LoadNotificationDetails> details;
2361
2362 NavigationEntry* entry = controller_.GetActiveEntry();
2363 // An entry may not exist for a stop when loading an initial blank page or
2364 // if an iframe injected by script into a blank page finishes loading.
2365 if (entry) {
[email protected]420ae012009-04-24 05:16:322366 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2367
2368 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542369 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322370 entry->transition_type(),
2371 elapsed,
2372 &controller_,
2373 controller_.GetCurrentEntryIndex()));
2374 }
2375
[email protected]420ae012009-04-24 05:16:322376 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492377
2378 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172379 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322380}
2381
[email protected]1a3c3cb2010-12-16 21:03:402382void TabContents::DidChangeLoadProgress(double progress) {
2383 if (delegate())
2384 delegate()->LoadProgressChanged(progress);
2385}
2386
[email protected]25497492010-09-11 15:15:082387void TabContents::DocumentOnLoadCompletedInMainFrame(
2388 RenderViewHost* render_view_host,
2389 int32 page_id) {
2390 NotificationService::current()->Notify(
2391 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2392 Source<TabContents>(this),
2393 Details<int>(&page_id));
2394}
2395
[email protected]420ae012009-04-24 05:16:322396void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2397 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:582398 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352399 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322400 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2401 // generated suggestions).
2402 //
[email protected]e0112912011-02-02 22:54:352403 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162404 // want web sites to see a referrer of "chrome://blah" (and some
2405 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322406 // send to the site), so we send no referrer.
2407 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:582408 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:322409 } else {
2410 OpenURL(url, referrer, disposition, PageTransition::LINK);
2411 }
2412}
2413
[email protected]1ee614862009-07-06 20:29:182414void TabContents::DomOperationResponse(const std::string& json_string,
2415 int automation_id) {
2416}
2417
[email protected]badcca352011-02-12 01:08:082418void TabContents::ProcessWebUIMessage(
[email protected]8b8e7c92010-08-19 18:05:562419 const ViewHostMsg_DomMessage_Params& params) {
[email protected]7ade2732011-02-10 00:13:582420 if (!render_manager_.web_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442421 // This can happen if someone uses window.open() to open an extension URL
2422 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562423 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322424 return;
2425 }
[email protected]badcca352011-02-12 01:08:082426 render_manager_.web_ui()->ProcessWebUIMessage(params);
[email protected]420ae012009-04-24 05:16:322427}
2428
2429void TabContents::ProcessExternalHostMessage(const std::string& message,
2430 const std::string& origin,
2431 const std::string& target) {
2432 if (delegate())
2433 delegate()->ForwardMessageToExternalHost(message, origin, target);
2434}
2435
[email protected]420ae012009-04-24 05:16:322436void TabContents::RunJavaScriptMessage(
2437 const std::wstring& message,
2438 const std::wstring& default_prompt,
2439 const GURL& frame_url,
2440 const int flags,
2441 IPC::Message* reply_msg,
2442 bool* did_suppress_message) {
2443 // Suppress javascript messages when requested and when inside a constrained
2444 // popup window (because that activates them and breaks them out of the
2445 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552446 // Also suppress messages when showing an interstitial. The interstitial is
2447 // shown over the previous page, we don't want the hidden page dialogs to
2448 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502449 bool suppress_this_message =
2450 suppress_javascript_messages_ ||
2451 showing_interstitial_page() ||
2452 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322453 if (delegate())
2454 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312455 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322456
2457 *did_suppress_message = suppress_this_message;
2458
2459 if (!suppress_this_message) {
2460 base::TimeDelta time_since_last_message(
2461 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2462 bool show_suppress_checkbox = false;
2463 // Show a checkbox offering to suppress further messages if this message is
2464 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2465 if (time_since_last_message <
2466 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2467 show_suppress_checkbox = true;
2468
[email protected]d6ad7442010-09-05 19:06:522469 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2470 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322471 } else {
2472 // If we are suppressing messages, just reply as is if the user immediately
2473 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542474 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322475 }
2476}
2477
2478void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2479 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292480 if (delegate())
2481 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502482 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2483 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2484 std::wstring());
2485 return;
2486 }
[email protected]7ab1e7d62009-10-14 23:32:012487 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222488 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322489}
2490
2491void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2492 const std::string& json_arguments,
2493 IPC::Message* reply_msg) {
2494 if (delegate()) {
2495 HtmlDialogUIDelegate* dialog_delegate =
2496 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222497 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322498 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2499 }
2500}
2501
[email protected]420ae012009-04-24 05:16:322502GURL TabContents::GetAlternateErrorPageURL() const {
2503 GURL url;
2504 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2505 if (profile()->IsOffTheRecord())
2506 return url;
2507
2508 PrefService* prefs = profile()->GetPrefs();
2509 DCHECK(prefs);
2510 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152511 url = google_util::AppendGoogleLocaleParam(
2512 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322513 url = google_util::AppendGoogleTLDParam(url);
2514 }
2515 return url;
2516}
2517
2518WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062519 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:582520 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:082521 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:582522 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:082523
[email protected]9beff752010-09-22 19:35:432524 // Force accelerated compositing and 2d canvas off for chrome: and
2525 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432526 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2527 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082528 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432529 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082530 }
2531
[email protected]39553442010-09-09 00:01:552532#if defined(OS_MACOSX)
2533 // Disable accelerated compositing if IOSurface's are not supported,
2534 // as is the case in 10.5.
2535 if (!IOSurfaceSupport::Initialize())
2536 web_prefs.accelerated_compositing_enabled = false;
2537#endif
2538
[email protected]447021c2010-09-08 21:29:082539 return web_prefs;
[email protected]420ae012009-04-24 05:16:322540}
2541
[email protected]7d472472011-01-22 01:30:252542void TabContents::OnUserGesture() {
2543 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
2544 DownloadRequestLimiter* limiter =
2545 g_browser_process->download_request_limiter();
2546 if (limiter)
2547 limiter->OnUserGesture(this);
2548 ExternalProtocolHandler::PermitLaunchUrl();
2549}
2550
[email protected]fa1cf0b82010-01-15 21:49:442551void TabContents::OnIgnoredUIEvent() {
2552 if (constrained_window_count()) {
2553 ConstrainedWindow* window = *constrained_window_begin();
2554 window->FocusConstrainedWindow();
2555 }
2556}
2557
[email protected]420ae012009-04-24 05:16:322558void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2559 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342560 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322561 // delivered to a pending RenderViewHost. We must first run the onunload
2562 // handler of the old RenderViewHost before we can allow it to proceed.
2563 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2564 new_request_id);
2565}
2566
[email protected]420ae012009-04-24 05:16:322567void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2568 bool is_during_unload) {
2569 if (is_during_unload) {
2570 // Hang occurred while firing the beforeunload/unload handler.
2571 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112572 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322573
2574 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2575 return;
2576
2577 // If the tab hangs in the beforeunload/unload handler there's really
2578 // nothing we can do to recover. Pretend the unload listeners have
2579 // all fired and close the tab. If the hang is in the beforeunload handler
2580 // then the user will not have the option of cancelling the close.
2581 Close(rvh);
2582 return;
2583 }
2584
[email protected]61b50092011-02-03 18:02:192585 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
2586 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]e7b8d832009-11-20 22:41:002587 hung_renderer_dialog::ShowForTabContents(this);
[email protected]61b50092011-02-03 18:02:192588 }
[email protected]420ae012009-04-24 05:16:322589}
2590
2591void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002592 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322593}
2594
2595void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562596 net::LoadState load_state,
2597 uint64 upload_position,
2598 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322599 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562600 upload_position_ = upload_position;
2601 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292602 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192603 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292604 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:422605 load_state_host_ = WideToUTF16Hack(
2606 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:322607 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2608 SetNotWaitingForResponse();
2609 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502610 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322611}
2612
[email protected]1ee614862009-07-06 20:29:182613bool TabContents::IsExternalTabContainer() const {
2614 if (!delegate())
2615 return false;
2616
2617 return delegate()->IsExternalTabContainer();
2618}
2619
[email protected]1ee614862009-07-06 20:29:182620void TabContents::DidInsertCSS() {
2621 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322622}
2623
[email protected]546ae4e02010-12-08 14:57:192624void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:352625 NotificationService::current()->Notify(
2626 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:212627 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:192628 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:352629}
2630
[email protected]b75b8292010-10-01 07:28:252631void TabContents::UpdateZoomLimits(int minimum_percent,
2632 int maximum_percent,
2633 bool remember) {
2634 minimum_zoom_percent_ = minimum_percent;
2635 maximum_zoom_percent_ = maximum_percent;
2636 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382637}
2638
[email protected]7d472472011-01-22 01:30:252639void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:442640 if (delegate())
2641 delegate()->WorkerCrashed();
[email protected]7d472472011-01-22 01:30:252642}
2643
[email protected]420ae012009-04-24 05:16:322644void TabContents::BeforeUnloadFiredFromRenderManager(
2645 bool proceed,
2646 bool* proceed_to_fire_unload) {
2647 if (delegate())
2648 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2649}
2650
[email protected]3a3d47472010-07-15 21:03:542651void TabContents::DidStartLoadingFromRenderManager(
2652 RenderViewHost* render_view_host) {
2653 DidStartLoading();
2654}
2655
2656void TabContents::RenderViewGoneFromRenderManager(
2657 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232658 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2659 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542660}
2661
[email protected]420ae012009-04-24 05:16:322662void TabContents::UpdateRenderViewSizeForRenderManager() {
2663 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262664 gfx::Size size = view_->GetContainerSize();
2665 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2666 // here during container initialization and normal window size will be set
2667 // later. In case of tab duplication this resizing to 0x0 prevents setting
2668 // normal size later so just ignore it.
2669 if (!size.IsEmpty())
2670 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322671}
2672
[email protected]3a3d47472010-07-15 21:03:542673void TabContents::NotifySwappedFromRenderManager() {
2674 NotifySwapped();
2675}
2676
2677NavigationController& TabContents::GetControllerForRenderManager() {
2678 return controller();
2679}
2680
[email protected]d0980792011-02-13 19:41:402681WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]80a8fad2011-01-29 04:02:382682 return WebUIFactory::CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322683}
2684
2685NavigationEntry*
2686TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2687 return controller_.GetLastCommittedEntry();
2688}
2689
2690bool TabContents::CreateRenderViewForRenderManager(
2691 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322692 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522693
[email protected]674b3822010-08-04 04:02:512694 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322695 return false;
2696
2697 // Now that the RenderView has been created, we need to tell it its size.
2698 rwh_view->SetSize(view_->GetContainerSize());
2699
2700 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2701 render_view_host);
2702 return true;
2703}
2704
2705void TabContents::Observe(NotificationType type,
2706 const NotificationSource& source,
2707 const NotificationDetails& details) {
2708 switch (type.value) {
[email protected]420ae012009-04-24 05:16:322709 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512710 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322711 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2712 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2713 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:532714 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
2715 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:322716 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:172717 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
2718 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:322719 } else {
2720 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2721 }
2722 break;
2723 }
2724 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2725 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2726 break;
2727
2728 case NotificationType::NAV_ENTRY_COMMITTED: {
2729 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2730
2731 NavigationController::LoadCommittedDetails& committed_details =
2732 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2733 ExpireInfoBars(committed_details);
2734 break;
2735 }
2736
[email protected]d3ba77272009-09-03 00:06:092737#if defined(OS_LINUX)
2738 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542739 renderer_preferences_util::UpdateFromSystemSettings(
2740 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092741 render_view_host()->SyncRendererPrefs();
2742 break;
2743 }
2744#endif
2745
[email protected]6c32ce72010-03-08 05:18:062746 case NotificationType::USER_STYLE_SHEET_UPDATED:
2747 UpdateWebPreferences();
2748 break;
2749
[email protected]79580c62010-02-02 02:36:252750 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:452751 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:252752 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492753 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292754 if (entry)
[email protected]da0c8e92010-02-09 23:25:492755 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292756 if (settings_details.ptr()->update_all() ||
2757 settings_details.ptr()->pattern().Matches(entry_url)) {
2758 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232759 profile()->GetHostContentSettingsMap()->
2760 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252761 }
2762 break;
2763 }
2764
[email protected]e5adff72010-06-14 18:13:062765 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:572766 break;
[email protected]a888b29e62010-04-01 13:38:572767
2768 case NotificationType::EXTENSION_UNLOADED:
[email protected]a888b29e62010-04-01 13:38:572769 break;
[email protected]a888b29e62010-04-01 13:38:572770
[email protected]88152052010-10-01 04:05:182771 case NotificationType::GOOGLE_URL_UPDATED:
2772 UpdateAlternateErrorPageURL();
2773 break;
2774
[email protected]420ae012009-04-24 05:16:322775 default:
2776 NOTREACHED();
2777 }
2778}
[email protected]aacd7cc2009-09-02 14:51:102779
[email protected]9adb9692010-10-29 23:14:022780void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:082781 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432782
[email protected]a888b29e62010-04-01 13:38:572783 if (extension) {
[email protected]98aa0b52010-05-06 17:03:082784 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
2785 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:572786 extension,
[email protected]807871f2010-09-16 01:04:482787 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
2788 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:572789 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
2790 Extension::EXTENSION_ICON_SMALLISH),
2791 ImageLoadingTracker::CACHE);
2792 } else {
[email protected]98aa0b52010-05-06 17:03:082793 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:572794 }
2795}
2796
[email protected]9adb9692010-10-29 23:14:022797const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:002798 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:572799 if (!extensions_service)
2800 return NULL;
2801
[email protected]9adb9692010-10-29 23:14:022802 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:572803 return extension ?
2804 extension : extensions_service->GetExtensionByWebExtent(url);
2805}
2806
[email protected]a888b29e62010-04-01 13:38:572807void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
2808 int index) {
2809 if (image) {
[email protected]98aa0b52010-05-06 17:03:082810 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:572811 NotifyNavigationStateChanged(INVALIDATE_TAB);
2812 }
2813}
2814
[email protected]beb440c2009-11-06 04:08:542815gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2816 return view_->GetTopLevelNativeWindow();
2817}
2818
2819void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2820 bool success,
2821 const std::wstring& prompt) {
2822 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2823 if (is_showing_before_unload_dialog_ && !success) {
2824 // If a beforeunload dialog is canceled, we need to stop the throbber from
2825 // spinning, since we forced it to start spinning in Navigate.
2826 DidStopLoading();
2827
2828 tab_close_start_time_ = base::TimeTicks();
2829 }
2830 is_showing_before_unload_dialog_ = false;
2831 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2832}
2833
2834void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2835 set_suppress_javascript_messages(suppress_message_boxes);
2836}
2837
[email protected]3a3d47472010-07-15 21:03:542838TabContents* TabContents::AsTabContents() {
2839 return this;
2840}
2841
2842ExtensionHost* TabContents::AsExtensionHost() {
2843 return NULL;
2844}
2845
[email protected]41fc0322009-09-04 22:23:402846void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102847 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2848}
[email protected]f45d2a72010-03-08 23:28:352849
2850void TabContents::SetAppIcon(const SkBitmap& app_icon) {
2851 app_icon_ = app_icon;
2852 NotifyNavigationStateChanged(INVALIDATE_TITLE);
2853}
[email protected]33f74972010-12-08 16:40:362854
2855void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2856 render_manager_.SwapInRenderViewHost(rvh);
2857}
2858
2859void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2860 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2861 rwh_view->SetSize(view()->GetContainerSize());
2862}
[email protected]e7d50892011-01-19 21:47:382863
2864bool TabContents::MaybeUsePreloadedPage(const GURL& url) {
[email protected]4c154ff82011-02-15 11:23:592865 prerender::PrerenderManager* pm = profile()->GetPrerenderManager();
[email protected]e7d50892011-01-19 21:47:382866 if (pm != NULL) {
[email protected]973407b2011-01-26 23:18:232867 if (pm->MaybeUsePreloadedPage(this, url))
[email protected]e7d50892011-01-19 21:47:382868 return true;
[email protected]e7d50892011-01-19 21:47:382869 }
2870 return false;
2871}