blob: cd366410897d73ee92f39b24068f817cf47efdfc [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 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]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.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]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]b9535422012-02-09 01:47:5917#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4418#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4619#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1220#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1621#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3222#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5423#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0524#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0025#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0126#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3027#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3228#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2529#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]48227592012-03-19 13:13:4430#include "content/public/browser/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3331#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1332#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2333#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5634#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2435#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5136#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0237#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5838#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1139#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2040#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4441#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4442#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1743#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4644#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1545#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2746#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0047#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4848#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3849#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4250#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2551#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1052#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5053#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2154#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4855#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1856#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5457#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0358#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1659#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2960#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5461#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3462#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3763#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]ce9751942011-09-21 01:57:2464#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3165#include "webkit/glue/webpreferences.h"
66
[email protected]68b52252012-04-04 19:26:1367#if defined(USE_AURA)
68#include "content/browser/tab_contents/tab_contents_view_aura.h"
69#elif defined(OS_WIN)
[email protected]38b098f2012-03-14 21:11:5770#include "content/browser/tab_contents/tab_contents_view_win.h"
71#elif defined(TOOLKIT_GTK)
72#include "content/browser/tab_contents/tab_contents_view_gtk.h"
73#elif defined(OS_MACOSX)
74#include "content/browser/tab_contents/web_contents_view_mac.h"
[email protected]b9b751f22011-03-25 14:04:1275#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5776#elif defined(OS_ANDROID)
77#include "content/browser/tab_contents/web_contents_view_android.h"
78#endif
[email protected]3e45ba92009-02-20 21:09:0079
[email protected]420ae012009-04-24 05:16:3280// Cross-Site Navigations
81//
82// If a TabContents is told to navigate to a different web site (as determined
83// by SiteInstance), it will replace its current RenderViewHost with a new
84// RenderViewHost dedicated to the new SiteInstance. This works as follows:
85//
86// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4687// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3288// - The pending RVH is "suspended," so that no navigation messages are sent to
89// its renderer until the onbeforeunload JavaScript handler has a chance to
90// run in the current RVH.
91// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
92// that it has a pending cross-site request. ResourceDispatcherHost will
93// check for this when the response arrives.
94// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4695// cancel all the pending logic. Otherwise we allow the pending RVH to send
96// the navigation request to its renderer.
97// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
98// main resource load on the pending RVH. It checks CrossSiteRequestManager
99// to see that it is a cross-site request, and installs a
100// CrossSiteResourceHandler.
101// - When RDH receives a response, the BufferedResourceHandler determines
102// whether it is a download. If so, it sends a message to the new renderer
103// causing it to cancel the request, and the download proceeds. For now, the
104// pending RVH remains until the next DidNavigate event for this TabContents.
105// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32106// - After RDH receives a response and determines that it is safe and not a
107// download, it pauses the response to first run the old page's onunload
108// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15109// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32110// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15111// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32112// the ResourceDispatcherHost, who unpauses the response. Data is then sent
113// to the pending RVH.
114// - The pending renderer sends a FrameNavigate message that invokes the
115// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46116// pending RVH.
[email protected]992db4c2011-05-12 15:37:15117// - The previous renderer is kept swapped out in RenderViewHostManager in case
118// the user goes back. The process only stays live if another tab is using
119// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32120
[email protected]0e12d7d2011-12-01 16:21:44121using content::DevToolsAgentHost;
122using content::DevToolsAgentHostRegistry;
123using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17124using content::DownloadItem;
125using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20126using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56127using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13128using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27129using content::LoadNotificationDetails;
[email protected]c5eed492012-01-04 17:07:50130using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23131using content::NavigationEntry;
132using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20133using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11134using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57135using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27136using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11137using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58138using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04139using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25140using content::ResourceDispatcherHostImpl;
[email protected]adbfb8df2012-02-24 01:19:43141using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33142using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17143using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38144using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09145using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25146using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56147using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22148using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50149using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44150
[email protected]420ae012009-04-24 05:16:32151namespace {
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]82114f52012-03-20 22:53:41159const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05160
[email protected]420ae012009-04-24 05:16:32161#if defined(OS_WIN)
162
163BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
164 // Note: erase is required to properly paint some widgets borders. This can
165 // be seen with textfields.
166 InvalidateRect(hwnd, NULL, TRUE);
167 return TRUE;
168}
169#endif
170
[email protected]2c5569662011-03-22 20:45:02171ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23172 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50173 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16174 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47175 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02176 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47177 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02178 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47179 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16180 break; // Fall through to rest of function.
181 }
[email protected]5e369672009-11-03 23:48:30182
[email protected]59246c572012-02-10 13:32:13183 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
184 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23185 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13186 browser_context->DidLastSessionExitCleanly()) {
187 if (entry.GetHasPostData())
188 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02189 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13190 }
[email protected]5e369672009-11-03 23:48:30191
[email protected]2c5569662011-03-22 20:45:02192 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30193}
194
[email protected]10f417c52011-12-28 21:04:23195void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47196 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42197 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50198 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16199 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51200 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54201 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55202 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
203 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51204 params->url = entry.GetURL();
205 params->referrer = entry.GetReferrer();
206 params->transition = entry.GetTransitionType();
207 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00208 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55209 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34210 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47211 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48212 params->transferred_request_child_id =
213 entry.transferred_global_request_id().child_id;
214 params->transferred_request_request_id =
215 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47216
217 if (delegate)
218 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34219}
220
[email protected]420ae012009-04-24 05:16:32221} // namespace
222
[email protected]a81343d232011-12-27 07:39:20223namespace content {
224
225WebContents* WebContents::Create(
226 BrowserContext* browser_context,
227 SiteInstance* site_instance,
228 int routing_id,
229 const WebContents* base_tab_contents,
230 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43231 return new TabContents(
232 browser_context,
233 site_instance,
234 routing_id,
235 static_cast<const TabContents*>(base_tab_contents),
236 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20237}
238}
[email protected]f4f50ef2011-01-21 19:01:19239
240// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32241
[email protected]3d7474ff2011-07-27 17:47:37242TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32243 SiteInstance* site_instance,
244 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07245 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43246 SessionStorageNamespaceImpl* 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_(
[email protected]3d7474ff2011-07-27 17:47:37249 this, browser_context, session_storage_namespace)),
[email protected]d82ed61e2009-06-16 02:46:22250 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34251 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23252 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
253 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34254 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21255 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56256 upload_size_(0),
257 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47258 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57259 capturing_contents_(false),
260 is_being_destroyed_(false),
261 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55262 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57263#if defined(OS_WIN)
264 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
265#endif
[email protected]7ab1e7d62009-10-14 23:32:01266 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56267 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38268 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25269 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01270 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25271 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01272 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00273 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43274 content_restrictions_(0),
[email protected]a0358d72012-03-09 14:06:50275 view_type_(content::VIEW_TYPE_TAB_CONTENTS),
[email protected]da8543762012-03-20 08:52:20276 has_opener_(false),
277 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37278 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32279
[email protected]38b098f2012-03-14 21:11:57280 view_.reset(content::GetContentClient()->browser()->
281 OverrideCreateWebContentsView(this));
282 if (!view_.get()) {
283 content::WebContentsViewDelegate* delegate =
284 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
285 this);
[email protected]68b52252012-04-04 19:26:13286#if defined(USE_AURA)
287 view_.reset(new TabContentsViewAura(this, delegate));
288#elif defined(OS_WIN)
[email protected]38b098f2012-03-14 21:11:57289 view_.reset(new TabContentsViewWin(this, delegate));
290#elif defined(TOOLKIT_GTK)
291 view_.reset(new content::TabContentsViewGtk(this, delegate));
292#elif defined(OS_MACOSX)
293 view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate));
294#elif defined(OS_ANDROID)
295 view_.reset(new WebContentsViewAndroid(this));
296#endif
[email protected]dbd407f2012-03-14 21:30:37297 (void)delegate;
[email protected]38b098f2012-03-14 21:11:57298 }
299 CHECK(view_.get());
300
[email protected]34ac70502009-09-25 17:07:23301 // We have the initial size of the view be based on the size of the passed in
302 // tab contents (normally a tab from the same window).
303 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21304 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00305
306#if defined(ENABLE_JAVA_BRIDGE)
307 java_bridge_dispatcher_host_manager_.reset(
308 new JavaBridgeDispatcherHostManager(this));
309#endif
[email protected]332af7732009-03-11 13:21:35310}
initial.commit09911bf2008-07-26 23:55:29311
312TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32313 is_being_destroyed_ = true;
314
[email protected]3ab9cb82011-06-03 18:02:07315 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55316 if (dialog_creator_)
317 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07318
[email protected]da8543762012-03-20 08:52:20319 if (color_chooser_)
320 color_chooser_->End();
321
[email protected]420ae012009-04-24 05:16:32322 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32323
[email protected]420ae012009-04-24 05:16:32324 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07325 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09326 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
327 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07328 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32329
330 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07331#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32332 // If we still have a window handle, destroy it. GetNativeView can return
333 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42334 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52335 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58336 if (host && host->GetView())
337 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42338 }
[email protected]420ae012009-04-24 05:16:32339#endif
[email protected]7ab1e7d62009-10-14 23:32:01340
341 // OnCloseStarted isn't called in unit tests.
342 if (!tab_close_start_time_.is_null()) {
343 UMA_HISTOGRAM_TIMES("Tab.Close",
344 base::TimeTicks::Now() - tab_close_start_time_);
345 }
[email protected]b5a1d11c2011-02-17 03:09:42346
[email protected]d8c660432011-12-22 20:51:25347 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08348
[email protected]6934a702011-12-20 00:04:51349 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42350}
351
[email protected]64d69de42012-02-06 00:19:54352WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
353 const GURL& url) {
354 WebPreferences prefs;
355
356 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
357
358 prefs.developer_extras_enabled = true;
359 prefs.javascript_enabled =
360 !command_line.HasSwitch(switches::kDisableJavaScript);
361 prefs.web_security_enabled =
362 !command_line.HasSwitch(switches::kDisableWebSecurity);
363 prefs.plugins_enabled =
364 !command_line.HasSwitch(switches::kDisablePlugins);
365 prefs.java_enabled =
366 !command_line.HasSwitch(switches::kDisableJava);
367
368 prefs.uses_page_cache =
369 command_line.HasSwitch(switches::kEnableFastback);
370 prefs.remote_fonts_enabled =
371 !command_line.HasSwitch(switches::kDisableRemoteFonts);
372 prefs.xss_auditor_enabled =
373 !command_line.HasSwitch(switches::kDisableXSSAuditor);
374 prefs.application_cache_enabled =
375 !command_line.HasSwitch(switches::kDisableApplicationCache);
376
377 prefs.local_storage_enabled =
378 !command_line.HasSwitch(switches::kDisableLocalStorage);
379 prefs.databases_enabled =
380 !command_line.HasSwitch(switches::kDisableDatabases);
381 prefs.webaudio_enabled =
382 !command_line.HasSwitch(switches::kDisableWebAudio);
383
384 prefs.experimental_webgl_enabled =
385 GpuProcessHost::gpu_enabled() &&
386 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
387 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
388
389 prefs.gl_multisampling_enabled =
390 !command_line.HasSwitch(switches::kDisableGLMultisampling);
391 prefs.privileged_webgl_extensions_enabled =
392 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
393 prefs.site_specific_quirks_enabled =
394 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
395 prefs.allow_file_access_from_file_urls =
396 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
397 prefs.show_composited_layer_borders =
398 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
399 prefs.show_composited_layer_tree =
400 command_line.HasSwitch(switches::kShowCompositedLayerTree);
401 prefs.show_fps_counter =
402 command_line.HasSwitch(switches::kShowFPSCounter);
403 prefs.accelerated_compositing_enabled =
404 GpuProcessHost::gpu_enabled() &&
405 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54406 prefs.force_compositing_mode =
407 command_line.HasSwitch(switches::kForceCompositingMode);
408 prefs.fixed_position_compositing_enabled =
409 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
410 prefs.accelerated_2d_canvas_enabled =
411 GpuProcessHost::gpu_enabled() &&
412 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58413 prefs.deferred_2d_canvas_enabled =
414 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36415 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31416 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54417 prefs.accelerated_painting_enabled =
418 GpuProcessHost::gpu_enabled() &&
419 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
420 prefs.accelerated_filters_enabled =
421 GpuProcessHost::gpu_enabled() &&
422 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
423 prefs.accelerated_layers_enabled =
424 prefs.accelerated_animation_enabled =
425 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
426 prefs.composite_to_texture_enabled =
427 command_line.HasSwitch(switches::kEnableCompositeToTexture);
428 prefs.accelerated_plugins_enabled =
429 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
430 prefs.accelerated_video_enabled =
431 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
432 prefs.partial_swap_enabled =
433 command_line.HasSwitch(switches::kEnablePartialSwap);
434 prefs.interactive_form_validation_enabled =
435 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
436 prefs.fullscreen_enabled =
437 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16438 prefs.css_regions_enabled =
439 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29440 prefs.css_shaders_enabled =
441 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]64d69de42012-02-06 00:19:54442
443#if defined(OS_MACOSX)
444 bool default_enable_scroll_animator = true;
445#else
446 // On CrOS, the launcher always passes in the --enable flag.
447 bool default_enable_scroll_animator = false;
448#endif
449 prefs.enable_scroll_animator = default_enable_scroll_animator;
450 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
451 prefs.enable_scroll_animator = true;
452 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
453 prefs.enable_scroll_animator = false;
454
455 prefs.visual_word_movement_enabled =
456 command_line.HasSwitch(switches::kEnableVisualWordMovement);
457 prefs.per_tile_painting_enabled =
458 command_line.HasSwitch(switches::kEnablePerTilePainting);
459
460 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32461 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54462 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11463 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
464 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54465 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11466 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54467 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11468 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54469 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11470 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54471 prefs.gl_multisampling_enabled = false;
472
473 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45474 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32475 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54476 prefs.accelerated_video_enabled = false;
477 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45478 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54479 }
480 }
481
[email protected]b9535422012-02-09 01:47:59482 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58483 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54484 prefs.loads_images_automatically = true;
485 prefs.javascript_enabled = true;
486 }
487
488 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
489
490 // Force accelerated compositing and 2d canvas off for chrome:, about: and
491 // chrome-devtools: pages (unless it's specifically allowed).
492 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54493 url.SchemeIs(chrome::kChromeUIScheme) ||
494 (url.SchemeIs(chrome::kAboutScheme) &&
495 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25496 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54497 prefs.accelerated_compositing_enabled = false;
498 prefs.accelerated_2d_canvas_enabled = false;
499 }
500
[email protected]43d9d782012-03-01 15:40:09501 int default_device_scale_factor;
502 base::StringToInt(command_line.GetSwitchValueASCII(
503 switches::kDefaultDeviceScaleFactor),
504 &default_device_scale_factor);
505
506 prefs.default_device_scale_factor = default_device_scale_factor;
507
[email protected]2e21fe292012-03-02 22:52:32508 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54509
510 return prefs;
511}
512
[email protected]d202a7c2012-01-04 07:53:47513NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20514 return controller_;
515}
516
[email protected]765187182012-01-11 23:59:28517RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
518 return &render_manager_;
519}
520
[email protected]724159a2010-12-30 01:11:18521bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56522 if (GetWebUI() &&
523 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17524 return true;
[email protected]d2353452012-01-19 19:53:56525 }
[email protected]f82d57b52011-04-27 19:13:17526
[email protected]d8c660432011-12-22 20:51:25527 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
528 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10529 while ((observer = it.GetNext()) != NULL)
530 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53531 return true;
[email protected]403415a2011-01-10 18:57:53532
[email protected]724159a2010-12-30 01:11:18533 bool handled = true;
534 bool message_is_ok = true;
535 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58536 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
537 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24538 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
539 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18540 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
541 OnDidStartProvisionalLoadForFrame)
542 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
543 OnDidRedirectProvisionalLoad)
544 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
545 OnDidFailProvisionalLoadWithError)
546 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
547 OnDidLoadResourceFromMemoryCache)
548 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
549 OnDidDisplayInsecureContent)
550 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
551 OnDidRunInsecureContent)
552 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
553 OnDocumentLoadedInFrame)
554 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17555 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
556 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25557 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26558 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59559 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21560 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20561 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
562 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
563 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16564 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45565 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10566 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20567 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
568 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
569 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
570 OnSetSelectedColorInColorChooser)
[email protected]724159a2010-12-30 01:11:18571 IPC_MESSAGE_UNHANDLED(handled = false)
572 IPC_END_MESSAGE_MAP_EX()
573
574 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38575 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18576 GetRenderProcessHost()->ReceivedBadMessage();
577 }
578
579 return handled;
580}
581
[email protected]6c2e472f2011-08-24 23:26:18582void TabContents::RunFileChooser(
583 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23584 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51585 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18586}
587
[email protected]c5eed492012-01-04 17:07:50588NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56589 return controller_;
590}
591
[email protected]c5eed492012-01-04 17:07:50592const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56593 return controller_;
594}
595
[email protected]627e0512011-12-21 22:55:30596content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55597 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30598}
599
[email protected]f5fa20e2011-12-21 22:35:56600void TabContents::SetViewType(content::ViewType type) {
601 view_type_ = type;
602}
603
[email protected]ea049a02011-12-25 21:37:09604content::ViewType TabContents::GetViewType() const {
605 return view_type_;
606}
607
[email protected]be1f56ab2011-12-22 06:55:31608const GURL& TabContents::GetURL() const {
609 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23610 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51611 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31612}
613
614
615const base::PropertyBag* TabContents::GetPropertyBag() const {
616 return &property_bag_;
617}
618
619base::PropertyBag* TabContents::GetPropertyBag() {
620 return &property_bag_;
621}
622
623content::WebContentsDelegate* TabContents::GetDelegate() {
624 return delegate_;
625}
626
627void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
628 // TODO(cbentzel): remove this debugging code?
629 if (delegate == delegate_)
630 return;
631 if (delegate_)
632 delegate_->Detach(this);
633 delegate_ = delegate;
634 if (delegate_)
635 delegate_->Attach(this);
636}
637
[email protected]f3b1a082011-11-18 00:34:30638content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41639 RenderViewHostImpl* host = render_manager_.current_host();
640 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16641}
642
[email protected]be1f56ab2011-12-22 06:55:31643RenderViewHost* TabContents::GetRenderViewHost() const {
644 return render_manager_.current_host();
645}
646
647RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
648 return render_manager_.GetRenderWidgetHostView();
649}
650
[email protected]8643e6d2012-01-18 20:26:10651content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31652 return view_.get();
653}
654
[email protected]01ec4ec2012-01-18 04:13:47655content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50656 WebUIControllerFactory* factory =
657 content::GetContentClient()->browser()->GetWebUIControllerFactory();
658 if (!factory)
659 return NULL;
[email protected]d2353452012-01-19 19:53:56660 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22661 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50662 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22663 if (controller) {
664 web_ui->SetController(controller);
665 return web_ui;
666 }
667
668 delete web_ui;
669 return NULL;
670}
671
[email protected]01ec4ec2012-01-18 04:13:47672content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31673 return render_manager_.web_ui() ? render_manager_.web_ui()
674 : render_manager_.pending_web_ui();
675}
676
[email protected]01ec4ec2012-01-18 04:13:47677content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31678 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34679}
680
[email protected]96d185d2009-04-24 03:28:54681const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55682 // Transient entries take precedence. They are used for interstitial pages
683 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23684 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08685 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20686 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30687 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23688 if (entry) {
[email protected]b5cca982011-05-26 04:42:08689 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23690 }
[email protected]7ade2732011-02-10 00:13:58691 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
692 render_manager_.pending_web_ui() : render_manager_.web_ui();
693 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54694 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55695 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54696 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35697 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22698 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54699 if (!title.empty())
700 return title;
701 }
702 }
703
704 // We use the title for the last committed entry rather than a pending
705 // navigation entry. For example, when the user types in a URL, we want to
706 // keep the old page's title until the new load has committed and we get a new
707 // title.
[email protected]96d185d2009-04-24 03:28:54708 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23709 if (entry) {
[email protected]b5cca982011-05-26 04:42:08710 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23711 }
[email protected]987fc3a2011-05-26 14:18:09712
713 // |page_title_when_no_navigation_entry_| is finally used
714 // if no title cannot be retrieved.
715 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54716}
717
[email protected]d5f942ba2008-09-26 19:30:34718int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46719 return GetMaxPageIDForSiteInstance(GetSiteInstance());
720}
721
722int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33723 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
724 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46725
[email protected]b6583592012-01-25 19:52:33726 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34727}
728
729void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46730 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
731}
732
[email protected]b6583592012-01-25 19:52:33733void TabContents::UpdateMaxPageIDForSiteInstance(
734 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46735 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33736 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34737}
738
[email protected]91854cd2012-01-10 19:43:57739void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
740 max_page_ids_ = tab_contents->max_page_ids_;
741}
742
[email protected]96d185d2009-04-24 03:28:54743SiteInstance* TabContents::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58744 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54745}
746
[email protected]77362eb2011-08-01 17:18:38747SiteInstance* TabContents::GetPendingSiteInstance() const {
748 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
749 render_manager_.pending_render_view_host() :
750 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58751 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38752}
753
[email protected]be1f56ab2011-12-22 06:55:31754bool TabContents::IsLoading() const {
755 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49756}
757
[email protected]be1f56ab2011-12-22 06:55:31758bool TabContents::IsWaitingForResponse() const {
759 return waiting_for_response_;
760}
761
762const net::LoadStateWithParam& TabContents::GetLoadState() const {
763 return load_state_;
764}
765
766const string16& TabContents::GetLoadStateHost() const {
767 return load_state_host_;
768}
769
770uint64 TabContents::GetUploadSize() const {
771 return upload_size_;
772}
773
774uint64 TabContents::GetUploadPosition() const {
775 return upload_position_;
776}
777
778const std::string& TabContents::GetEncoding() const {
779 return encoding_;
780}
781
782bool TabContents::DisplayedInsecureContent() const {
783 return displayed_insecure_content_;
784}
785
786void TabContents::SetCapturingContents(bool cap) {
787 capturing_contents_ = cap;
788}
789
790bool TabContents::IsCrashed() const {
791 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
792 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
793 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49794}
795
[email protected]443b80e2010-12-14 00:42:23796void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
797 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34798 return;
799
[email protected]443b80e2010-12-14 00:42:23800 crashed_status_ = status;
801 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46802 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34803}
804
[email protected]be1f56ab2011-12-22 06:55:31805base::TerminationStatus TabContents::GetCrashedStatus() const {
806 return crashed_status_;
807}
808
809bool TabContents::IsBeingDestroyed() const {
810 return is_being_destroyed_;
811}
812
[email protected]d5f942ba2008-09-26 19:30:34813void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
814 if (delegate_)
815 delegate_->NavigationStateChanged(this, changed_flags);
816}
817
[email protected]96d185d2009-04-24 03:28:54818void TabContents::DidBecomeSelected() {
819 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04820 RenderWidgetHostViewPort* rwhv =
821 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16822 if (rwhv) {
823 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43824#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16825 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43826#endif
827 }
[email protected]96d185d2009-04-24 03:28:54828
[email protected]5ac20162010-11-24 23:33:11829 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38830
[email protected]d8c660432011-12-22 20:51:25831 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59832
833 // The resize rect might have changed while this was inactive -- send the new
834 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58835 RenderViewHostImpl* rvh =
836 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59837 if (rvh) {
838 rvh->ResizeRectChanged(GetRootWindowResizerRect());
839 }
[email protected]96d185d2009-04-24 03:28:54840}
841
[email protected]be1f56ab2011-12-22 06:55:31842
843base::TimeTicks TabContents::GetLastSelectedTime() const {
844 return last_selected_time_;
845}
846
[email protected]96d185d2009-04-24 03:28:54847void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31848 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52849 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
850 // open a tab in then background, then closes the tab before selecting it.
851 // This is because closing the tab calls TabContents::Destroy(), which
852 // removes the |GetRenderViewHost()|; then when we actually destroy the
853 // window, OnWindowPosChanged() notices and calls HideContents() (which
854 // calls us).
[email protected]c30585c2012-02-16 15:02:04855 RenderWidgetHostViewPort* rwhv =
856 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16857 if (rwhv)
858 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54859 }
860
[email protected]ad50def52011-10-19 23:17:07861 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09862 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
863 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07864 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54865}
866
[email protected]be1f56ab2011-12-22 06:55:31867void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04868 RenderWidgetHostViewPort* rwhv =
869 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31870 if (rwhv)
871 rwhv->DidBecomeSelected();
872}
873
874void TabContents::HideContents() {
875 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
876 // our superclass HideContents(), because some callers want to be very picky
877 // about the order in which these get called. In addition to making the code
878 // here practically impossible to understand, this also means we end up
879 // calling TabContents::WasHidden() twice if callers call both versions of
880 // HideContents() on a TabContents.
881 WasHidden();
882}
883
884bool TabContents::NeedToFireBeforeUnload() {
885 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27886 return WillNotifyDisconnection() &&
887 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58888 !static_cast<RenderViewHostImpl*>(
889 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31890}
891
[email protected]0bfbf882011-12-22 18:19:27892void TabContents::Stop() {
893 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25894 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27895}
896
[email protected]d9083482012-01-06 00:38:46897WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27898 // We create a new SiteInstance so that the new tab won't share processes
899 // with the old one. This can be changed in the future if we need it to share
900 // processes for some reason.
901 TabContents* tc = new TabContents(
902 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33903 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27904 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20905 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27906 return tc;
907}
908
[email protected]2a6bc3e2011-12-28 23:51:33909void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27910 WindowOpenDisposition disposition,
911 const gfx::Rect& initial_pos,
912 bool user_gesture) {
913 if (!delegate_)
914 return;
915
916 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
917 user_gesture);
918}
919
920gfx::NativeView TabContents::GetContentNativeView() const {
921 return view_->GetContentNativeView();
922}
923
924gfx::NativeView TabContents::GetNativeView() const {
925 return view_->GetNativeView();
926}
927
928void TabContents::GetContainerBounds(gfx::Rect* out) const {
929 view_->GetContainerBounds(out);
930}
931
932void TabContents::Focus() {
933 view_->Focus();
934}
935
[email protected]d8c660432011-12-22 20:51:25936void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31937 observers_.AddObserver(observer);
938}
939
[email protected]d8c660432011-12-22 20:51:25940void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31941 observers_.RemoveObserver(observer);
942}
943
[email protected]d5f942ba2008-09-26 19:30:34944void TabContents::Activate() {
945 if (delegate_)
946 delegate_->ActivateContents(this);
947}
948
[email protected]ea42e7782010-08-23 23:58:12949void TabContents::Deactivate() {
950 if (delegate_)
951 delegate_->DeactivateContents(this);
952}
953
[email protected]63954792011-07-11 04:17:48954void TabContents::LostCapture() {
955 if (delegate_)
956 delegate_->LostCapture();
957}
958
959bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
960 bool* is_keyboard_shortcut) {
961 return delegate_ &&
962 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
963}
964
965void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
966 if (delegate_)
967 delegate_->HandleKeyboardEvent(event);
968}
969
[email protected]32ded2212011-11-10 18:51:43970void TabContents::HandleMouseDown() {
971 if (delegate_)
972 delegate_->HandleMouseDown();
973}
974
[email protected]63954792011-07-11 04:17:48975void TabContents::HandleMouseUp() {
976 if (delegate_)
977 delegate_->HandleMouseUp();
978}
979
980void TabContents::HandleMouseActivate() {
981 if (delegate_)
982 delegate_->HandleMouseActivate();
983}
984
[email protected]8a5e0ca2011-08-25 06:30:47985void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
986 if (delegate_)
987 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
988}
989
[email protected]5d5f7af2011-10-01 01:38:12990bool TabContents::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:38991 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:12992}
993
[email protected]e9621112011-10-17 05:38:37994void TabContents::RequestToLockMouse() {
995 if (delegate_) {
996 delegate_->RequestToLockMouse(this);
997 } else {
998 GotResponseToLockMouseRequest(false);
999 }
1000}
1001
1002void TabContents::LostMouseLock() {
1003 if (delegate_)
1004 delegate_->LostMouseLock();
1005}
1006
[email protected]0548c5352011-09-07 00:33:331007void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231008 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331009 if (delegate_)
1010 delegate_->UpdatePreferredSize(this, pref_size);
1011}
1012
[email protected]61e2b3cc2012-03-02 16:13:341013void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
1014 if (delegate_)
1015 delegate_->ResizeDueToAutoResize(this, new_size);
1016}
1017
[email protected]32ded2212011-11-10 18:51:431018void TabContents::WebUISend(RenderViewHost* render_view_host,
1019 const GURL& source_url,
1020 const std::string& name,
1021 const base::ListValue& args) {
1022 if (delegate_)
1023 delegate_->WebUISend(this, source_url, name, args);
1024}
1025
[email protected]e5d549d2011-12-28 01:29:201026WebContents* TabContents::OpenURL(const OpenURLParams& params) {
1027 if (!delegate_)
1028 return NULL;
[email protected]00c37fc2011-08-02 00:22:501029
[email protected]e5d549d2011-12-28 01:29:201030 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1031 // Notify observers.
1032 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1033 DidOpenURL(params.url, params.referrer,
1034 params.disposition, params.transition));
1035 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341036}
1037
[email protected]1ccb3568d2010-02-19 10:51:161038bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501039 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251040 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231041 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251042 reload_type);
[email protected]876bc832010-09-07 16:29:541043}
[email protected]96d185d2009-04-24 03:28:541044
[email protected]876bc832010-09-07 16:29:541045bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231046 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501047 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401048 // The renderer will reject IPC messages with URLs longer than
1049 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511050 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401051 return false;
1052
[email protected]9f76c1e2012-03-05 15:15:581053 RenderViewHostImpl* dest_render_view_host =
1054 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401055 if (!dest_render_view_host)
1056 return false; // Unable to create the desired render view host.
1057
[email protected]80a8fad2011-01-29 04:02:381058 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071059 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581060 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501061 WebUIControllerFactory* factory =
1062 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1063 bool is_allowed_in_web_ui_renderer =
1064 factory &&
1065 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431066#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511067 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431068#endif
[email protected]1684454a2012-03-24 04:12:231069 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1070 !is_allowed_in_web_ui_renderer) {
1071 // Log the URL to help us diagnose http://crbug.com/72235.
1072 content::GetContentClient()->SetActiveURL(entry.GetURL());
1073 CHECK(0);
1074 }
[email protected]54ec6472010-04-09 19:39:581075
[email protected]96d185d2009-04-24 03:28:541076 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441077 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521078 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441079 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511080 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541081
1082 // Used for page load time metrics.
1083 current_load_start_ = base::TimeTicks::Now();
1084
1085 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341086 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271087 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471088 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341089 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541090
[email protected]36fc0392011-12-25 03:59:511091 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541092 // HACK!! This code suppresses javascript: URLs from being added to
1093 // session history, which is what we want to do for javascript: URLs that
1094 // do not generate content. What we really need is a message from the
1095 // renderer telling us that a new page was not created. The same message
1096 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511097 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541098 return false;
1099 }
1100
[email protected]3c9e1872010-11-18 16:17:491101 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251102 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041103 observers_,
[email protected]36fc0392011-12-25 03:59:511104 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541105
[email protected]09b29342011-06-24 19:18:481106 if (delegate_)
1107 delegate_->DidNavigateToPendingEntry(this);
1108
[email protected]d5f942ba2008-09-26 19:30:341109 return true;
1110}
1111
[email protected]b6583592012-01-25 19:52:331112void TabContents::SetHistoryLengthAndPrune(
1113 const SiteInstance* site_instance,
1114 int history_length,
1115 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411116 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1117 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191118 if (render_manager_.pending_render_view_host()) {
1119 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141120 return;
[email protected]9e1ad4b2011-08-14 16:49:191121 }
[email protected]9f76c1e2012-03-05 15:15:581122 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191123 if (!rvh) {
1124 NOTREACHED();
1125 return;
1126 }
[email protected]9f76c1e2012-03-05 15:15:581127 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191128 NOTREACHED();
1129 return;
1130 }
[email protected]9f76c1e2012-03-05 15:15:581131 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191132 history_length,
1133 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141134}
1135
[email protected]90daadb42009-06-08 21:27:281136void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271137 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541138 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1139 return;
1140 }
[email protected]9f76c1e2012-03-05 15:15:581141 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541142}
1143
[email protected]0bfbf882011-12-22 18:19:271144bool TabContents::ShowingInterstitialPage() const {
1145 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541146}
1147
[email protected]0bfbf882011-12-22 18:19:271148InterstitialPage* TabContents::GetInterstitialPage() const {
1149 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221150}
1151
[email protected]a53209b2012-01-20 16:48:161152bool TabContents::IsSavable() {
1153 // WebKit creates Document object when MIME type is application/xhtml+xml,
1154 // so we also support this MIME type.
1155 return contents_mime_type_ == "text/html" ||
1156 contents_mime_type_ == "text/xml" ||
1157 contents_mime_type_ == "application/xhtml+xml" ||
1158 contents_mime_type_ == "text/plain" ||
1159 contents_mime_type_ == "text/css" ||
1160 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1161}
1162
[email protected]c7dd2f62011-07-18 15:57:591163void TabContents::OnSavePage() {
1164 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161165 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481166 download_stats::RecordDownloadSource(
1167 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261168 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141169 return;
[email protected]c7dd2f62011-07-18 15:57:591170 }
1171
1172 Stop();
1173
1174 // Create the save package and possibly prompt the user for the name to save
1175 // the page as. The user prompt is an asynchronous operation that runs on
1176 // another thread.
1177 save_package_ = new SavePackage(this);
1178 save_package_->GetSaveInfo();
1179}
1180
1181// Used in automated testing to bypass prompting the user for file names.
1182// Instead, the names and paths are hard coded rather than running them through
1183// file name sanitation and extension / mime checking.
1184bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161185 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591186 // Stop the page from navigating.
1187 Stop();
1188
1189 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1190 return save_package_->Init();
1191}
1192
[email protected]aa4f3972012-03-01 18:12:121193void TabContents::GenerateMHTML(
1194 const FilePath& file,
1195 const base::Callback<void(const FilePath&, int64)>& callback) {
1196 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1197}
1198
[email protected]420ae012009-04-24 05:16:321199bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231200 NavigationEntryImpl* active_entry =
1201 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321202 return (active_entry != NULL &&
1203 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511204 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321205}
1206
[email protected]0bfbf882011-12-22 18:19:271207const std::string& TabContents::GetContentsMimeType() const {
1208 return contents_mime_type_;
1209}
1210
1211bool TabContents::WillNotifyDisconnection() const {
1212 return notify_disconnection_;
1213}
1214
[email protected]b2fe07d12010-02-09 14:38:081215void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311216 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581217 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1218 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161219}
1220
[email protected]b2fe07d12010-02-09 14:38:081221void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311222 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581223 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1224 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161225}
1226
[email protected]0bfbf882011-12-22 18:19:271227content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1228 return &renderer_preferences_;
1229}
1230
1231void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1232 new_tab_start_time_ = time;
1233}
1234
1235base::TimeTicks TabContents::GetNewTabStartTime() const {
1236 return new_tab_start_time_;
1237}
1238
[email protected]7ab1e7d62009-10-14 23:32:011239void TabContents::OnCloseStarted() {
1240 if (tab_close_start_time_.is_null())
1241 tab_close_start_time_ = base::TimeTicks::Now();
1242}
1243
[email protected]46624bf2010-06-09 16:04:191244bool TabContents::ShouldAcceptDragAndDrop() const {
1245#if defined(OS_CHROMEOS)
1246 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1247 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511248 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201249 return false;
1250 return true;
[email protected]46624bf2010-06-09 16:04:191251#else
1252 return true;
1253#endif
1254}
1255
[email protected]7813bd72011-02-05 02:19:341256void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521257 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581258 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511259 if (delegate_)
1260 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341261}
1262
[email protected]0bfbf882011-12-22 18:19:271263void TabContents::SetClosedByUserGesture(bool value) {
1264 closed_by_user_gesture_ = value;
1265}
1266
1267bool TabContents::GetClosedByUserGesture() const {
1268 return closed_by_user_gesture_;
1269}
1270
[email protected]d0b8d092010-10-25 04:05:171271double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051272 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561273 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251274 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171275 return 0;
[email protected]b75b8292010-10-01 07:28:251276
1277 double zoom_level;
1278 if (temporary_zoom_settings_) {
1279 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581280 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251281 } else {
[email protected]2ae88d12011-10-14 09:11:191282 GURL url;
[email protected]10f417c52011-12-28 21:04:231283 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191284 // Since zoom map is updated using rewritten URL, use rewritten URL
1285 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511286 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191287 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251288 }
[email protected]d0b8d092010-10-25 04:05:171289 return zoom_level;
1290}
[email protected]b75b8292010-10-01 07:28:251291
[email protected]d0b8d092010-10-25 04:05:171292int TabContents::GetZoomPercent(bool* enable_increment,
1293 bool* enable_decrement) {
1294 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011295 // Calculate the zoom percent from the factor. Round up to the nearest whole
1296 // number.
[email protected]b75b8292010-10-01 07:28:251297 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011298 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251299 *enable_decrement = percent > minimum_zoom_percent_;
1300 *enable_increment = percent < maximum_zoom_percent_;
1301 return percent;
1302}
1303
[email protected]3c733bde2010-12-21 19:56:311304void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501305 if (!delegate_)
1306 return;
1307
[email protected]10f417c52011-12-28 21:04:231308 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501309 if (!active_entry)
1310 return;
1311
[email protected]36fc0392011-12-25 03:59:511312 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121313}
1314
[email protected]932b7a12011-03-09 12:50:271315void TabContents::ViewFrameSource(const GURL& url,
1316 const std::string& content_state) {
1317 if (!delegate_)
1318 return;
1319
1320 delegate_->ViewSourceForFrame(this, url, content_state);
1321}
1322
[email protected]0bfbf882011-12-22 18:19:271323int TabContents::GetMinimumZoomPercent() const {
1324 return minimum_zoom_percent_;
1325}
1326
1327int TabContents::GetMaximumZoomPercent() const {
1328 return maximum_zoom_percent_;
1329}
1330
[email protected]bcd2815602012-01-14 18:17:231331gfx::Size TabContents::GetPreferredSize() const {
1332 return preferred_size_;
1333}
1334
[email protected]0bfbf882011-12-22 18:19:271335int TabContents::GetContentRestrictions() const {
1336 return content_restrictions_;
1337}
1338
1339WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501340 WebUIControllerFactory* factory =
1341 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1342 if (!factory)
1343 return WebUI::kNoWebUI;
1344 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271345}
1346
[email protected]01ec4ec2012-01-18 04:13:471347content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271348 // When there is a pending navigation entry, we want to use the pending WebUI
1349 // that goes along with it to control the basic flags. For example, we want to
1350 // show the pending URL in the URL bar, so we want the display_url flag to
1351 // be from the pending entry.
1352 //
1353 // The confusion comes because there are multiple possibilities for the
1354 // initial load in a tab as a side effect of the way the RenderViewHostManager
1355 // works.
1356 //
1357 // - For the very first tab the load looks "normal". The new tab Web UI is
1358 // the pending one, and we want it to apply here.
1359 //
1360 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1361 // get switched to the one previously associated with the new tab pages.
1362 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1363 // have a committed Web UI in this case.
1364 //
1365 // This condition handles all of these cases:
1366 //
1367 // - First load in first tab: no committed nav entry + pending nav entry +
1368 // pending dom ui:
1369 // -> Use pending Web UI if any.
1370 //
1371 // - First load in second tab: no committed nav entry + pending nav entry +
1372 // no pending Web UI:
1373 // -> Use the committed Web UI if any.
1374 //
1375 // - Second navigation in any tab: committed nav entry + pending nav entry:
1376 // -> Use pending Web UI if any.
1377 //
1378 // - Normal state with no load: committed nav entry + no pending nav entry:
1379 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251380 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271381 (controller_.GetLastCommittedEntry() ||
1382 render_manager_.pending_web_ui()))
1383 return render_manager_.pending_web_ui();
1384 return render_manager_.web_ui();
1385}
1386
1387bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1388 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581389 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271390}
1391
[email protected]a0358d72012-03-09 14:06:501392bool TabContents::HasOpener() const {
1393 return has_opener_;
1394}
1395
[email protected]da8543762012-03-20 08:52:201396void TabContents::DidChooseColorInColorChooser(int color_chooser_id,
1397 const SkColor& color) {
1398 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1399 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1400}
1401
1402void TabContents::DidEndColorChooser(int color_chooser_id) {
1403 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1404 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1405 if (delegate_)
1406 delegate_->DidEndColorChooser();
1407 color_chooser_ = NULL;
1408}
1409
[email protected]0bfbf882011-12-22 18:19:271410bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471411 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271412 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221413 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231414 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411415 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271416}
1417
1418void TabContents::SetFocusToLocationBar(bool select_all) {
1419 if (delegate_)
1420 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211421}
1422
[email protected]8b5af492011-11-28 21:50:581423void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301424 const string16& type,
1425 const string16& href,
1426 const string16& title,
1427 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511428 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301429 this, action, type, href, title, disposition);
1430}
1431
[email protected]678105012011-12-09 04:01:211432void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301433 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001434 WebIntentsDispatcherImpl* intents_dispatcher =
1435 new WebIntentsDispatcherImpl(this, intent, intent_id);
1436 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301437}
1438
[email protected]724159a2010-12-30 01:11:181439void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1440 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591441 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181442 const GURL& url) {
1443 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1444 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451445 GURL validated_opener_url(opener_url);
[email protected]9f76c1e2012-03-05 15:15:581446 GetRenderViewHostImpl()->FilterURL(
1447 ChildProcessSecurityPolicyImpl::GetInstance(),
1448 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451449 false,
[email protected]9f76c1e2012-03-05 15:15:581450 &validated_url);
[email protected]6b7cd8f2012-03-21 21:02:451451 GetRenderViewHostImpl()->FilterURL(
1452 ChildProcessSecurityPolicyImpl::GetInstance(),
1453 GetRenderProcessHost()->GetID(),
1454 true,
1455 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181456
[email protected]8093a542011-05-13 07:29:321457 RenderViewHost* rvh =
1458 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521459 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101460 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251461 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101462 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321463 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101464
[email protected]724159a2010-12-30 01:11:181465 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591466 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251467 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451468 ProvisionalChangeToMainFrameUrl(validated_url,
1469 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181470 }
1471}
1472
1473void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591474 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181475 const GURL& source_url,
1476 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491477 // TODO(creis): Remove this method and have the pre-rendering code listen to
1478 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1479 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451480 GURL validated_source_url(source_url);
1481 GURL validated_target_url(target_url);
1482 GURL validated_opener_url(opener_url);
1483 GetRenderViewHostImpl()->FilterURL(
1484 ChildProcessSecurityPolicyImpl::GetInstance(),
1485 GetRenderProcessHost()->GetID(),
1486 false,
1487 &validated_source_url);
1488 GetRenderViewHostImpl()->FilterURL(
1489 ChildProcessSecurityPolicyImpl::GetInstance(),
1490 GetRenderProcessHost()->GetID(),
1491 false,
1492 &validated_target_url);
1493 GetRenderViewHostImpl()->FilterURL(
1494 ChildProcessSecurityPolicyImpl::GetInstance(),
1495 GetRenderProcessHost()->GetID(),
1496 true,
1497 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231498 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181499 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251500 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181501 else
1502 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]6b7cd8f2012-03-21 21:02:451503 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181504 return;
[email protected]e7d50892011-01-19 21:47:381505
[email protected]4850a7f2011-03-08 23:36:591506 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251507 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451508 ProvisionalChangeToMainFrameUrl(validated_target_url,
1509 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181510}
1511
1512void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581513 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1514 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1515 << ", error_code: " << params.error_code
1516 << ", error_description: " << params.error_description
1517 << ", is_main_frame: " << params.is_main_frame
1518 << ", showing_repost_interstitial: " <<
1519 params.showing_repost_interstitial
1520 << ", frame_id: " << params.frame_id;
1521 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581522 GetRenderViewHostImpl()->FilterURL(
1523 ChildProcessSecurityPolicyImpl::GetInstance(),
1524 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451525 false,
[email protected]9f76c1e2012-03-05 15:15:581526 &validated_url);
[email protected]724159a2010-12-30 01:11:181527
[email protected]d7b175e2011-10-11 15:31:581528 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181529 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1530 // This means that the interstitial won't be torn down properly, which is
1531 // bad. But if we have an interstitial, go back to another tab type, and
1532 // then load the same interstitial again, we could end up getting the first
1533 // interstitial's "failed" message (as a result of the cancel) when we're on
1534 // the second one.
1535 //
1536 // We can't tell this apart, so we think we're tearing down the current page
1537 // which will cause a crash later one. There is also some code in
1538 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1539 // out because of this problem.
1540 //
1541 // http://code.google.com/p/chromium/issues/detail?id=2855
1542 // Because this will not tear down the interstitial properly, if "back" is
1543 // back to another tab type, the interstitial will still be somewhat alive
1544 // in the previous tab type. If you navigate somewhere that activates the
1545 // tab with the interstitial again, you'll see a flash before the new load
1546 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271547 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181548 LOG(WARNING) << "Discarding message during interstitial.";
1549 return;
1550 }
1551
[email protected]02102f82011-06-13 20:37:021552 // Discard our pending entry if the load canceled (e.g. if we decided to
1553 // download the file instead of load it). We do not verify that the URL
1554 // being canceled matches the pending entry's URL because they will not
1555 // match if a redirect occurred (in which case we do not want to leave a
1556 // stale redirect URL showing). This means that we also cancel the pending
1557 // entry if the user started a new navigation. As a result, the navigation
1558 // controller may not remember that a load is in progress, but the
1559 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251560 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161561 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181562
[email protected]151a63d2011-12-20 22:32:521563 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181564 }
1565
[email protected]d8c660432011-12-22 20:51:251566 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581567 observers_,
1568 DidFailProvisionalLoad(params.frame_id,
1569 params.is_main_frame,
1570 validated_url,
1571 params.error_code,
1572 params.error_description));
[email protected]724159a2010-12-30 01:11:181573}
1574
1575void TabContents::OnDidLoadResourceFromMemoryCache(
1576 const GURL& url,
[email protected]70435962011-08-02 20:13:281577 const std::string& security_info,
1578 const std::string& http_method,
1579 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191580 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181581 cache.Increment();
1582
1583 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081584 int cert_id = 0;
1585 net::CertStatus cert_status = 0;
1586 int security_bits = -1;
1587 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511588 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1589 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301590 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161591 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181592
[email protected]ad50def52011-10-19 23:17:071593 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271594 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501595 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531596 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181597}
1598
1599void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381600 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181601 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201602 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181603}
1604
1605void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021606 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231607 LOG(INFO) << security_origin << " ran insecure content from "
1608 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381609 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411610 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1611 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181612 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411613 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201614 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181615}
1616
1617void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1618 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251619 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101620 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181621}
1622
[email protected]1a55c5be2011-11-29 11:36:311623void TabContents::OnDidFinishLoad(
1624 int64 frame_id,
1625 const GURL& validated_url,
1626 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251627 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311628 DidFinishLoad(frame_id, validated_url, is_main_frame));
1629}
1630
1631void TabContents::OnDidFailLoadWithError(int64 frame_id,
1632 const GURL& validated_url,
1633 bool is_main_frame,
1634 int error_code,
1635 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251636 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311637 DidFailLoad(frame_id, validated_url, is_main_frame,
1638 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181639}
1640
[email protected]c8f73ab2011-01-22 00:05:171641void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271642 content_restrictions_ = restrictions;
1643 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171644}
1645
[email protected]216813952011-05-19 22:21:261646void TabContents::OnGoToEntryAtOffset(int offset) {
1647 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231648 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251649 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261650 if (!entry)
1651 return;
1652 // Note that we don't call NavigationController::GotToOffset() as we don't
1653 // want to create a pending navigation entry (it might end up lingering
1654 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251655 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581656 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511657 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581658 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471659 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571660
1661 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1662 // it in now that we know. This allows us to find the entry when it commits.
1663 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231664 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331665 entry->set_site_instance(
1666 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571667 }
[email protected]216813952011-05-19 22:21:261668 }
1669}
1670
1671void TabContents::OnUpdateZoomLimits(int minimum_percent,
1672 int maximum_percent,
1673 bool remember) {
1674 minimum_zoom_percent_ = minimum_percent;
1675 maximum_zoom_percent_ = maximum_percent;
1676 temporary_zoom_settings_ = !remember;
1677}
1678
[email protected]0bfbf882011-12-22 18:19:271679void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481680 download_stats::RecordDownloadSource(
1681 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261682 // Check if the URL to save matches the URL of the main frame. Since this
1683 // message originates from Pepper plugins, it may not be the case if the
1684 // plugin is an embedded element.
1685 GURL main_frame_url = GetURL();
1686 if (!main_frame_url.is_valid())
1687 return;
1688 bool is_main_frame = (url == main_frame_url);
1689 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271690}
1691
[email protected]3a29a6e2011-08-24 18:26:211692void TabContents::OnEnumerateDirectory(int request_id,
1693 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591694 ChildProcessSecurityPolicyImpl* policy =
1695 ChildProcessSecurityPolicyImpl::GetInstance();
1696 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1697 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211698}
1699
[email protected]7d189022011-08-25 22:54:201700void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511701 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201702}
1703
1704void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1705 const GURL& url,
1706 const string16& title) {
[email protected]b9535422012-02-09 01:47:591707 ChildProcessSecurityPolicyImpl* policy =
1708 ChildProcessSecurityPolicyImpl::GetInstance();
1709 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1710 return;
[email protected]6934a702011-12-20 00:04:511711 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201712}
1713
[email protected]b888919c2011-09-02 00:32:161714void TabContents::OnFindReply(int request_id,
1715 int number_of_matches,
1716 const gfx::Rect& selection_rect,
1717 int active_match_ordinal,
1718 bool final_update) {
[email protected]6934a702011-12-20 00:04:511719 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1720 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001721 // Send a notification to the renderer that we are ready to receive more
1722 // results from the scoping effort of the Find operation. The FindInPage
1723 // scoping is asynchronous and periodically sends results back up to the
1724 // browser using IPC. In an effort to not spam the browser we have the
1725 // browser send an ACK for each FindReply message and have the renderer
1726 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581727 GetRenderViewHostImpl()->Send(
1728 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161729}
1730
[email protected]d952a052011-09-06 18:42:451731void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511732 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451733}
1734
[email protected]7fc4bbb2011-09-08 21:23:101735void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1736 bool blocked_by_policy) {
1737 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251738 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101739 AppCacheAccessed(manifest_url, blocked_by_policy));
1740}
1741
[email protected]da8543762012-03-20 08:52:201742void TabContents::OnOpenColorChooser(int color_chooser_id,
1743 const SkColor& color) {
1744 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1745}
1746
1747void TabContents::OnEndColorChooser(int color_chooser_id) {
1748 if (color_chooser_ &&
1749 color_chooser_id == color_chooser_->identifier())
1750 color_chooser_->End();
1751}
1752
1753void TabContents::OnSetSelectedColorInColorChooser(int color_chooser_id,
1754 const SkColor& color) {
1755 if (color_chooser_ &&
1756 color_chooser_id == color_chooser_->identifier())
1757 color_chooser_->SetSelectedColor(color);
1758}
1759
[email protected]96d185d2009-04-24 03:28:541760// Notifies the RenderWidgetHost instance about the fact that the page is
1761// loading, or done loading and calls the base implementation.
1762void TabContents::SetIsLoading(bool is_loading,
1763 LoadNotificationDetails* details) {
1764 if (is_loading == is_loading_)
1765 return;
1766
1767 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211768 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541769 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561770 upload_size_ = 0;
1771 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541772 }
1773
1774 render_manager_.SetIsLoading(is_loading);
1775
1776 is_loading_ = is_loading;
1777 waiting_for_response_ = is_loading;
1778
[email protected]6ebdc9b2010-09-27 16:55:571779 if (delegate_)
1780 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461781 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541782
[email protected]432115822011-07-10 15:52:271783 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1784 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071785 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541786 if (details)
[email protected]6c2381d2011-10-19 02:52:531787 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071788 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501789 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541790 det);
1791}
1792
[email protected]420ae012009-04-24 05:16:321793void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131794 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321795 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561796 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381797 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441798 // that opened the window, as long as both renderers have the same
1799 // privileges.
[email protected]1fd1a502011-03-30 16:55:561800 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561801 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581802 // web_ui might be NULL if the URL refers to a non-existent extension.
1803 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401804 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521805 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441806 }
1807 }
[email protected]1fd1a502011-03-30 16:55:561808 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441809 }
1810
[email protected]4e697b042011-07-08 06:44:561811 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321812 // Clear the status bubble. This is a workaround for a bug where WebKit
1813 // doesn't let us know that the cursor left an element during a
1814 // transition (this is also why the mouse cursor remains as a hand after
1815 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1816 // clear the bubble when a user navigates to a named anchor in the same
1817 // page.
[email protected]36fc0392011-12-25 03:59:511818 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321819 }
1820
[email protected]a6e82fc2010-02-24 22:28:141821 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471822 // Once the main frame is navigated, we're no longer considered to have
1823 // displayed insecure content.
1824 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171825 }
[email protected]ce5c4502009-05-06 16:46:111826
[email protected]3c9e1872010-11-18 16:17:491827 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251828 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041829 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321830}
1831
1832void TabContents::DidNavigateAnyFramePostCommit(
1833 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131834 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321835 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061836 // If we navigate off the page, reset JavaScript state. This does nothing
1837 // to prevent a malicious script from spamming messages, since the script
1838 // could just reload the page to stop blocking.
1839 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551840 dialog_creator_->ResetJavaScriptState(this);
1841 dialog_creator_ = NULL;
1842 }
[email protected]420ae012009-04-24 05:16:321843
[email protected]3c9e1872010-11-18 16:17:491844 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251845 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041846 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321847}
1848
[email protected]74ce1ad2011-12-16 21:51:461849void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1850 // If we are creating a RVH for a restored controller, then we need to make
1851 // sure the RenderView starts with a next_page_id_ larger than the number
1852 // of restored entries. This must be called before the RenderView starts
1853 // navigating (to avoid a race between the browser updating max_page_id and
1854 // the renderer updating next_page_id_). Because of this, we only call this
1855 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561856 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581857 if (max_restored_page_id >
1858 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1859 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1860 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321861}
1862
[email protected]10f417c52011-12-28 21:04:231863bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571864 const string16& title) {
[email protected]420ae012009-04-24 05:16:321865 // For file URLs without a title, use the pathname instead. In the case of a
1866 // synthesized title, we don't want the update to count toward the "one set
1867 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511868 string16 final_title;
[email protected]420ae012009-04-24 05:16:321869 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511870 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1871 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321872 explicit_set = false; // Don't count synthetic titles toward the set limit.
1873 } else {
[email protected]acafd272011-07-26 17:35:571874 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321875 explicit_set = true;
1876 }
1877
[email protected]987fc3a2011-05-26 14:18:091878 // If a page is created via window.open and never navigated,
1879 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551880 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091881 if (entry) {
[email protected]36fc0392011-12-25 03:59:511882 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091883 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321884
[email protected]36fc0392011-12-25 03:59:511885 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091886 } else {
1887 if (page_title_when_no_navigation_entry_ == final_title)
1888 return false; // Nothing changed, don't bother.
1889
1890 page_title_when_no_navigation_entry_ = final_title;
1891 }
[email protected]420ae012009-04-24 05:16:321892
[email protected]420ae012009-04-24 05:16:321893 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231894 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321895
[email protected]2bb171882012-03-07 02:09:461896 std::pair<content::NavigationEntry*, bool> details =
1897 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141898
[email protected]ad50def52011-10-19 23:17:071899 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441900 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1901 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461902 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041903
[email protected]420ae012009-04-24 05:16:321904 return true;
1905}
1906
1907void TabContents::NotifySwapped() {
1908 // After sending out a swap notification, we need to send a disconnect
1909 // notification so that clients that pick up a pointer to |this| can NULL the
1910 // pointer. See Bug 1230284.
1911 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071912 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201913 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1914 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071915 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321916}
1917
1918void TabContents::NotifyConnected() {
1919 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071920 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121921 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1922 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071923 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321924}
1925
1926void TabContents::NotifyDisconnected() {
1927 if (!notify_disconnection_)
1928 return;
1929
1930 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071931 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321932 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1933 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071934 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321935}
1936
[email protected]8d3347f2009-07-09 22:00:211937RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321938 return view_.get();
1939}
1940
[email protected]8d3347f2009-07-09 22:00:211941RenderViewHostDelegate::RendererManagement*
1942TabContents::GetRendererManagementDelegate() {
1943 return &render_manager_;
1944}
1945
[email protected]daf82f82011-10-31 22:35:311946content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371947 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461948 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511949}
1950
[email protected]768c5472011-12-26 19:06:171951WebContents* TabContents::GetAsWebContents() {
1952 return this;
1953}
1954
[email protected]da4dfc42011-10-12 15:53:561955content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431956 return view_type_;
[email protected]7b291f92009-08-14 05:43:531957}
1958
[email protected]b7a756d42012-01-23 18:08:171959gfx::Rect TabContents::GetRootWindowResizerRect() const {
1960 if (delegate_)
1961 return delegate_->GetRootWindowResizerRect();
1962 return gfx::Rect();
1963}
1964
[email protected]420ae012009-04-24 05:16:321965void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071966 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271967 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321968 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531969 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231970 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321971 if (!entry)
1972 return;
1973
1974 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351975 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561976 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581977 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321978
1979 if (entry->IsViewSourceMode()) {
1980 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:581981 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
1982 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:321983 }
[email protected]0666aef2009-05-13 19:48:081984
[email protected]d487beefe2011-12-21 05:41:211985 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261986
1987 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251988 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321989}
1990
1991void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521992 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321993 // Don't notify the world, since this came from a renderer in the
1994 // background.
1995 return;
1996 }
1997
1998 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311999 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232000 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302001
2002 // Restore the focus to the tab (otherwise the focus will be on the top
2003 // window).
[email protected]484ae5912010-09-29 19:16:142004 if (was_crashed && !FocusLocationBarByDefault() &&
2005 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302006 Focus();
[email protected]484ae5912010-09-29 19:16:142007 }
[email protected]32ded2212011-11-10 18:51:432008
[email protected]d8c660432011-12-22 20:51:252009 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322010}
2011
[email protected]443b80e2010-12-14 00:42:232012void TabContents::RenderViewGone(RenderViewHost* rvh,
2013 base::TerminationStatus status,
2014 int error_code) {
[email protected]151a63d2011-12-20 22:32:522015 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322016 // The pending page's RenderViewHost is gone.
2017 return;
2018 }
2019
2020 SetIsLoading(false, NULL);
2021 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232022 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312023 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322024
[email protected]d8c660432011-12-22 20:51:252025 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272026 observers_,
[email protected]be1f56ab2011-12-22 06:55:312027 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322028}
2029
[email protected]2e4633c2009-07-09 16:58:062030void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482031 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252032 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062033}
2034
[email protected]420ae012009-04-24 05:16:322035void TabContents::DidNavigate(RenderViewHost* rvh,
2036 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582037 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322038 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372039
[email protected]434f69f2012-02-06 21:56:522040 // Update the site of the SiteInstance if it doesn't have one yet, unless
2041 // this is for about:blank. In that case, the SiteInstance can still be
2042 // considered unused until a navigation to a real page.
2043 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2044 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332045 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522046 }
[email protected]420ae012009-04-24 05:16:322047
2048 // Need to update MIME type here because it's referred to in
2049 // UpdateNavigationCommands() called by RendererDidNavigate() to
2050 // determine whether or not to enable the encoding menu.
2051 // It's updated only for the main frame. For a subframe,
2052 // RenderView::UpdateURL does not set params.contents_mime_type.
2053 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2054 // TODO(jungshik): Add a test for the encoding menu to avoid
2055 // regressing it again.
[email protected]2905f742011-10-13 03:51:582056 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322057 contents_mime_type_ = params.contents_mime_type;
2058
[email protected]8286f51a2011-05-31 17:39:132059 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002060 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392061
[email protected]a9c0bfe2010-09-17 08:35:222062 // Send notification about committed provisional loads. This notification is
2063 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2064 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082065 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072066 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2067 // that is not recorded in the navigation history. For the purpose of
2068 // tracking navigation events, we treat this event as a sub frame navigation
2069 // event.
2070 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582071 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222072 // Whether or not a page transition was triggered by going backward or
2073 // forward in the history is only stored in the navigation controller's
2074 // entry list.
2075 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512076 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582077 content::PAGE_TRANSITION_FORWARD_BACK)) {
2078 transition_type = content::PageTransitionFromInt(
2079 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222080 }
[email protected]0d60f0192011-04-14 12:40:102081 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252082 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102083 DidCommitProvisionalLoadForFrame(params.frame_id,
2084 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222085 }
2086
[email protected]76543b92009-08-31 17:27:452087 if (!did_navigate)
2088 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322089
2090 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2091 // for the appropriate notification (best) or you can add it to
2092 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2093 // necessary, please).
2094
2095 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002096 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322097 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512098 if (delegate_)
2099 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002100 }
[email protected]420ae012009-04-24 05:16:322101 DidNavigateAnyFramePostCommit(rvh, details, params);
2102}
2103
2104void TabContents::UpdateState(RenderViewHost* rvh,
2105 int32 page_id,
2106 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152107 // Ensure that this state update comes from either the active RVH or one of
2108 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522109 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322110
2111 // We must be prepared to handle state updates for any page, these occur
2112 // when the user is scrolling and entering form data, as well as when we're
2113 // leaving a page, in which case our state may have already been moved to
2114 // the next page. The navigation controller will look up the appropriate
2115 // NavigationEntry and update it when it is notified via the delegate.
2116
2117 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582118 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322119 if (entry_index < 0)
2120 return;
[email protected]10f417c52011-12-28 21:04:232121 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322122
[email protected]36fc0392011-12-25 03:59:512123 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322124 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512125 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322126 controller_.NotifyEntryChanged(entry, entry_index);
2127}
2128
2129void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572130 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462131 const string16& title,
2132 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322133 // If we have a title, that's a pretty good indication that we've started
2134 // getting useful data.
2135 SetNotWaitingForResponse();
2136
[email protected]73eb2602012-02-09 19:50:552137 // Try to find the navigation entry, which might not be the current one.
2138 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232139 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582140 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092141
[email protected]73eb2602012-02-09 19:50:552142 // We can handle title updates when we don't have an entry in
2143 // UpdateTitleForEntry, but only if the update is from the current RVH.
2144 if (!entry && rvh != GetRenderViewHost())
2145 return;
2146
[email protected]a49e10b2011-08-01 23:57:462147 // TODO(evan): make use of title_direction.
2148 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092149 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322150 return;
2151
2152 // Broadcast notifications when the UI should be updated.
2153 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462154 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322155}
2156
[email protected]420ae012009-04-24 05:16:322157void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402158 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312159 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322160}
2161
2162void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512163 if (delegate_)
2164 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322165}
2166
[email protected]420ae012009-04-24 05:16:322167void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292168 // The UI may be in an event-tracking loop, such as between the
2169 // mouse-down and mouse-up in text selection or a button click.
2170 // Defer the close until after tracking is complete, so that we
2171 // don't free objects out from under the UI.
2172 // TODO(shess): This could probably be integrated with the
2173 // IsDoingDrag() test below. Punting for now because I need more
2174 // research to understand how this impacts platforms other than Mac.
2175 // TODO(shess): This could get more fine-grained. For instance,
2176 // closing a tab in another window while selecting text in the
2177 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212178 if (GetView()->IsEventTracking()) {
2179 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292180 return;
2181 }
2182
[email protected]24a4d1062009-07-10 23:10:422183 // If we close the tab while we're in the middle of a drag, we'll crash.
2184 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212185 if (GetView()->IsDoingDrag()) {
2186 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422187 return;
2188 }
2189
[email protected]420ae012009-04-24 05:16:322190 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522191 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512192 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322193}
2194
[email protected]cd9ed79d2011-11-15 19:22:572195void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522196 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512197 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572198}
2199
[email protected]420ae012009-04-24 05:16:322200void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512201 if (delegate_ && delegate_->IsPopupOrPanel(this))
2202 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322203}
2204
[email protected]7ab1e7d62009-10-14 23:32:012205void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322206 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492207
[email protected]82114f52012-03-20 22:53:412208 if (delegate_ && content_restrictions_)
2209 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492210
2211 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252212 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322213}
2214
[email protected]7ab1e7d62009-10-14 23:32:012215void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322216 scoped_ptr<LoadNotificationDetails> details;
2217
[email protected]10f417c52011-12-28 21:04:232218 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322219 // An entry may not exist for a stop when loading an initial blank page or
2220 // if an iframe injected by script into a blank page finishes loading.
2221 if (entry) {
[email protected]420ae012009-04-24 05:16:322222 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2223
2224 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512225 entry->GetVirtualURL(),
2226 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322227 elapsed,
2228 &controller_,
2229 controller_.GetCurrentEntryIndex()));
2230 }
2231
[email protected]420ae012009-04-24 05:16:322232 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492233
2234 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252235 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322236}
2237
[email protected]c95fa8b2011-04-28 20:26:162238void TabContents::DidCancelLoading() {
2239 controller_.DiscardNonCommittedEntries();
2240
2241 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462242 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162243}
2244
[email protected]1a3c3cb2010-12-16 21:03:402245void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512246 if (delegate_)
2247 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402248}
2249
[email protected]952a68e2011-11-17 00:36:102250void TabContents::DocumentAvailableInMainFrame(
2251 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252252 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102253 DocumentAvailableInMainFrame());
2254}
2255
[email protected]25497492010-09-11 15:15:082256void TabContents::DocumentOnLoadCompletedInMainFrame(
2257 RenderViewHost* render_view_host,
2258 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072259 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272260 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322261 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532262 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082263}
2264
[email protected]ae5184d62011-10-06 19:25:582265void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152266 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582267 WindowOpenDisposition disposition,
2268 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482269 // Delegate to RequestTransferURL because this is just the generic
2270 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582271 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482272 GlobalRequestID());
2273}
2274
2275void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582276 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482277 WindowOpenDisposition disposition,
2278 int64 source_frame_id,
2279 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202280 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582281 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582282 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352283 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322284 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2285 // generated suggestions).
2286 //
[email protected]e0112912011-02-02 22:54:352287 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162288 // want web sites to see a referrer of "chrome://blah" (and some
2289 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322290 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432291 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222292 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482293 false /* is_renderer_initiated */);
2294 params.transferred_global_request_id = old_request_id;
2295 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222296 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322297 } else {
[email protected]6bf6a6b52012-02-03 15:41:432298 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482299 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2300 params.transferred_global_request_id = old_request_id;
2301 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582302 }
2303 if (new_contents) {
2304 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252305 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582306 DidOpenRequestedURL(new_contents,
2307 url,
2308 referrer,
2309 disposition,
2310 transition_type,
2311 source_frame_id));
[email protected]420ae012009-04-24 05:16:322312 }
2313}
2314
[email protected]420ae012009-04-24 05:16:322315void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342316 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412317 const string16& message,
2318 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322319 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472320 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322321 IPC::Message* reply_msg,
2322 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072323 // Suppress JavaScript dialogs when requested. Also suppress messages when
2324 // showing an interstitial as it's shown over the previous page and we don't
2325 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502326 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582327 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272328 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072329 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522330 delegate_->ShouldSuppressDialogs() ||
2331 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322332
2333 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432334 std::string accept_lang = content::GetContentClient()->browser()->
2335 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552336 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522337 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432338 this,
2339 frame_url.GetOrigin(),
2340 accept_lang,
2341 javascript_message_type,
2342 message,
[email protected]51da7e32012-01-30 19:24:522343 default_prompt,
2344 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432345 reply_msg),
[email protected]51da7e32012-01-30 19:24:522346 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322347 }
[email protected]3ab9cb82011-06-03 18:02:072348
2349 if (suppress_this_message) {
2350 // If we are suppressing messages, just reply as if the user immediately
2351 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342352 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072353 }
2354
2355 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322356}
2357
[email protected]fedec012012-01-28 03:09:342358void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412359 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322360 bool is_reload,
[email protected]420ae012009-04-24 05:16:322361 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582362 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512363 if (delegate_)
2364 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072365
2366 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582367 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072368 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522369 delegate_->ShouldSuppressDialogs() ||
2370 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152371 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342372 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582373 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502374 return;
2375 }
[email protected]3ab9cb82011-06-03 18:02:072376
[email protected]7ab1e7d62009-10-14 23:32:012377 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552378 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522379 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322380 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522381 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2382 reply_msg));
[email protected]420ae012009-04-24 05:16:322383}
2384
[email protected]420ae012009-04-24 05:16:322385WebPreferences TabContents::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332386 // We want to base the page config off of the real URL, rather than the
2387 // display URL.
2388 GURL url = controller_.GetActiveEntry()
2389 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2390 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322391}
2392
[email protected]7d472472011-01-22 01:30:252393void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272394 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252395 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222396
[email protected]ea114722012-03-12 01:11:252397 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172398 if (rdh) // NULL in unittests.
2399 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252400}
2401
[email protected]fa1cf0b82010-01-15 21:49:442402void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442403 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252404 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442405}
2406
[email protected]420ae012009-04-24 05:16:322407void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2408 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152409 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522410 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152411 return;
2412
[email protected]9f76c1e2012-03-05 15:15:582413 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2414
[email protected]e5fc1632011-08-08 07:51:532415 // Ignore renderer unresponsive event if debugger is attached to the tab
2416 // since the event may be a result of the renderer sitting on a breakpoint.
2417 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442418 DevToolsAgentHost* agent =
2419 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2420 if (agent &&
2421 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532422 return;
2423
[email protected]420ae012009-04-24 05:16:322424 if (is_during_unload) {
2425 // Hang occurred while firing the beforeunload/unload handler.
2426 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582427 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322428
2429 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2430 return;
2431
2432 // If the tab hangs in the beforeunload/unload handler there's really
2433 // nothing we can do to recover. Pretend the unload listeners have
2434 // all fired and close the tab. If the hang is in the beforeunload handler
2435 // then the user will not have the option of cancelling the close.
2436 Close(rvh);
2437 return;
2438 }
2439
[email protected]9f76c1e2012-03-05 15:15:582440 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472441 return;
2442
[email protected]6934a702011-12-20 00:04:512443 if (delegate_)
2444 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322445}
2446
2447void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512448 if (delegate_)
2449 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322450}
2451
2452void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212453 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562454 uint64 upload_position,
2455 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322456 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562457 upload_position_ = upload_position;
2458 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502459 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202460 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302461 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212462 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322463 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462464 if (IsLoading()) {
2465 NotifyNavigationStateChanged(
2466 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2467 }
[email protected]420ae012009-04-24 05:16:322468}
2469
[email protected]7d472472011-01-22 01:30:252470void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512471 if (delegate_)
2472 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252473}
2474
[email protected]420ae012009-04-24 05:16:322475void TabContents::BeforeUnloadFiredFromRenderManager(
2476 bool proceed,
2477 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512478 if (delegate_)
2479 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322480}
2481
[email protected]3a3d47472010-07-15 21:03:542482void TabContents::DidStartLoadingFromRenderManager(
2483 RenderViewHost* render_view_host) {
2484 DidStartLoading();
2485}
2486
2487void TabContents::RenderViewGoneFromRenderManager(
2488 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232489 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2490 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542491}
2492
[email protected]420ae012009-04-24 05:16:322493void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102494 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262495 gfx::Size size = view_->GetContainerSize();
2496 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2497 // here during container initialization and normal window size will be set
2498 // later. In case of tab duplication this resizing to 0x0 prevents setting
2499 // normal size later so just ignore it.
2500 if (!size.IsEmpty())
2501 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322502}
2503
[email protected]3a3d47472010-07-15 21:03:542504void TabContents::NotifySwappedFromRenderManager() {
2505 NotifySwapped();
2506}
2507
[email protected]d202a7c2012-01-04 07:53:472508NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202509 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542510}
2511
[email protected]d2353452012-01-19 19:53:562512WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2513 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322514}
2515
[email protected]10f417c52011-12-28 21:04:232516NavigationEntry*
2517 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322518 return controller_.GetLastCommittedEntry();
2519}
2520
2521bool TabContents::CreateRenderViewForRenderManager(
2522 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442523 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322524 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522525
[email protected]420ae012009-04-24 05:16:322526 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442527 if (rwh_view)
2528 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322529
[email protected]74ce1ad2011-12-16 21:51:462530 // Make sure we use the correct starting page_id in the new RenderView.
2531 UpdateMaxPageIDIfNecessary(render_view_host);
2532 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582533 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462534
[email protected]9f76c1e2012-03-05 15:15:582535 if (!static_cast<RenderViewHostImpl*>(
2536 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522537 return false;
2538
[email protected]e60c0232011-11-11 19:56:352539#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502540 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2541 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442542 if (rwh_view) {
2543 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2544 render_widget_host->WasResized();
2545 }
[email protected]f8233cc2011-05-31 20:24:502546#endif
2547
[email protected]420ae012009-04-24 05:16:322548 return true;
2549}
2550
[email protected]fedec012012-01-28 03:09:342551void TabContents::OnDialogClosed(RenderViewHost* rvh,
2552 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072553 bool success,
2554 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542555 if (is_showing_before_unload_dialog_ && !success) {
2556 // If a beforeunload dialog is canceled, we need to stop the throbber from
2557 // spinning, since we forced it to start spinning in Navigate.
2558 DidStopLoading();
2559
2560 tab_close_start_time_ = base::TimeTicks();
2561 }
2562 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582563 static_cast<RenderViewHostImpl*>(
2564 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542565}
2566
[email protected]be1f56ab2011-12-22 06:55:312567void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122568 encoding_ = content::GetContentClient()->browser()->
2569 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102570}
[email protected]f45d2a72010-03-08 23:28:352571
[email protected]e30d68d2012-02-09 00:06:262572void TabContents::SaveURL(const GURL& url,
2573 const GURL& referrer,
2574 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142575 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2576 if (!dlm)
2577 return;
2578 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262579 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142580 const NavigationEntry* entry = controller_.GetActiveEntry();
2581 if (entry)
2582 post_id = entry->GetPostID();
2583 }
[email protected]29a5ffc82012-03-13 19:35:582584 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142585 save_info.prompt_for_save_location = true;
2586 dlm->DownloadUrl(url,
2587 referrer,
2588 "",
2589 true, // prefer_cache
2590 post_id,
2591 save_info,
[email protected]89e6aa72012-03-12 22:51:332592 this,
2593 DownloadManager::OnStartedCallback());
[email protected]27678b2a2012-02-04 22:09:142594}
2595
[email protected]33f74972010-12-08 16:40:362596void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212597 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442598 // Can be NULL during tests.
2599 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212600 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362601}
[email protected]9f76c1e2012-03-05 15:15:582602
2603RenderViewHostImpl* TabContents::GetRenderViewHostImpl() {
2604 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2605}