blob: bbaf198467c9f2d263c5a34c6b74d22186301798 [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]8dd709fb2012-04-06 00:49:0617#include "content/browser/browser_plugin/browser_plugin_web_contents_observer.h"
[email protected]b9535422012-02-09 01:47:5918#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4419#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4620#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1221#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1622#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3223#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5424#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0525#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0026#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0127#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3028#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3229#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2530#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]48227592012-03-19 13:13:4431#include "content/public/browser/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3332#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1333#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2334#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5635#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2436#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5137#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0238#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5839#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1140#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2041#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4442#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4443#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1744#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4645#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1546#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2747#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0048#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4849#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3850#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4251#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2552#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1053#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5054#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2155#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4856#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1857#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5458#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0359#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1660#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2961#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5462#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3463#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3764#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]ce9751942011-09-21 01:57:2465#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3166#include "webkit/glue/webpreferences.h"
67
[email protected]68b52252012-04-04 19:26:1368#if defined(USE_AURA)
69#include "content/browser/tab_contents/tab_contents_view_aura.h"
70#elif defined(OS_WIN)
[email protected]38b098f2012-03-14 21:11:5771#include "content/browser/tab_contents/tab_contents_view_win.h"
72#elif defined(TOOLKIT_GTK)
73#include "content/browser/tab_contents/tab_contents_view_gtk.h"
74#elif defined(OS_MACOSX)
75#include "content/browser/tab_contents/web_contents_view_mac.h"
[email protected]b9b751f22011-03-25 14:04:1276#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5777#elif defined(OS_ANDROID)
78#include "content/browser/tab_contents/web_contents_view_android.h"
79#endif
[email protected]3e45ba92009-02-20 21:09:0080
[email protected]420ae012009-04-24 05:16:3281// Cross-Site Navigations
82//
83// If a TabContents is told to navigate to a different web site (as determined
84// by SiteInstance), it will replace its current RenderViewHost with a new
85// RenderViewHost dedicated to the new SiteInstance. This works as follows:
86//
87// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4688// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3289// - The pending RVH is "suspended," so that no navigation messages are sent to
90// its renderer until the onbeforeunload JavaScript handler has a chance to
91// run in the current RVH.
92// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
93// that it has a pending cross-site request. ResourceDispatcherHost will
94// check for this when the response arrives.
95// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4696// cancel all the pending logic. Otherwise we allow the pending RVH to send
97// the navigation request to its renderer.
98// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
99// main resource load on the pending RVH. It checks CrossSiteRequestManager
100// to see that it is a cross-site request, and installs a
101// CrossSiteResourceHandler.
102// - When RDH receives a response, the BufferedResourceHandler determines
103// whether it is a download. If so, it sends a message to the new renderer
104// causing it to cancel the request, and the download proceeds. For now, the
105// pending RVH remains until the next DidNavigate event for this TabContents.
106// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32107// - After RDH receives a response and determines that it is safe and not a
108// download, it pauses the response to first run the old page's onunload
109// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15110// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32111// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15112// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32113// the ResourceDispatcherHost, who unpauses the response. Data is then sent
114// to the pending RVH.
115// - The pending renderer sends a FrameNavigate message that invokes the
116// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46117// pending RVH.
[email protected]992db4c2011-05-12 15:37:15118// - The previous renderer is kept swapped out in RenderViewHostManager in case
119// the user goes back. The process only stays live if another tab is using
120// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32121
[email protected]0e12d7d2011-12-01 16:21:44122using content::DevToolsAgentHost;
123using content::DevToolsAgentHostRegistry;
124using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17125using content::DownloadItem;
126using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20127using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56128using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13129using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27130using content::LoadNotificationDetails;
[email protected]c5eed492012-01-04 17:07:50131using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23132using content::NavigationEntry;
133using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20134using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11135using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57136using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27137using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11138using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58139using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04140using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25141using content::ResourceDispatcherHostImpl;
[email protected]adbfb8df2012-02-24 01:19:43142using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33143using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17144using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38145using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09146using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25147using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56148using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22149using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50150using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44151
[email protected]420ae012009-04-24 05:16:32152namespace {
153
154// Amount of time we wait between when a key event is received and the renderer
155// is queried for its state and pushed to the NavigationEntry.
156const int kQueryStateDelay = 5000;
157
[email protected]6ebdc9b2010-09-27 16:55:57158const int kSyncWaitDelay = 40;
159
[email protected]82114f52012-03-20 22:53:41160const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05161
[email protected]420ae012009-04-24 05:16:32162#if defined(OS_WIN)
163
164BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
165 // Note: erase is required to properly paint some widgets borders. This can
166 // be seen with textfields.
167 InvalidateRect(hwnd, NULL, TRUE);
168 return TRUE;
169}
170#endif
171
[email protected]2c5569662011-03-22 20:45:02172ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23173 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50174 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16175 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47176 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02177 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47178 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02179 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47180 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16181 break; // Fall through to rest of function.
182 }
[email protected]5e369672009-11-03 23:48:30183
[email protected]59246c572012-02-10 13:32:13184 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
185 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23186 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13187 browser_context->DidLastSessionExitCleanly()) {
188 if (entry.GetHasPostData())
189 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02190 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13191 }
[email protected]5e369672009-11-03 23:48:30192
[email protected]2c5569662011-03-22 20:45:02193 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30194}
195
[email protected]10f417c52011-12-28 21:04:23196void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47197 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42198 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50199 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16200 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51201 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54202 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55203 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
204 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51205 params->url = entry.GetURL();
206 params->referrer = entry.GetReferrer();
207 params->transition = entry.GetTransitionType();
208 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00209 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55210 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34211 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47212 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48213 params->transferred_request_child_id =
214 entry.transferred_global_request_id().child_id;
215 params->transferred_request_request_id =
216 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47217
218 if (delegate)
219 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34220}
221
[email protected]420ae012009-04-24 05:16:32222} // namespace
223
[email protected]a81343d232011-12-27 07:39:20224namespace content {
225
226WebContents* WebContents::Create(
227 BrowserContext* browser_context,
228 SiteInstance* site_instance,
229 int routing_id,
230 const WebContents* base_tab_contents,
231 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43232 return new TabContents(
233 browser_context,
234 site_instance,
235 routing_id,
236 static_cast<const TabContents*>(base_tab_contents),
237 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20238}
239}
[email protected]f4f50ef2011-01-21 19:01:19240
241// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32242
[email protected]3d7474ff2011-07-27 17:47:37243TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32244 SiteInstance* site_instance,
245 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07246 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43247 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42248 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07249 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37250 this, browser_context, session_storage_namespace)),
[email protected]d82ed61e2009-06-16 02:46:22251 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34252 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23253 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
254 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34255 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21256 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56257 upload_size_(0),
258 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47259 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57260 capturing_contents_(false),
261 is_being_destroyed_(false),
262 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55263 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57264#if defined(OS_WIN)
265 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
266#endif
[email protected]7ab1e7d62009-10-14 23:32:01267 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56268 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38269 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25270 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01271 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25272 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01273 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00274 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43275 content_restrictions_(0),
[email protected]a0358d72012-03-09 14:06:50276 view_type_(content::VIEW_TYPE_TAB_CONTENTS),
[email protected]da8543762012-03-20 08:52:20277 has_opener_(false),
278 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37279 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32280
[email protected]38b098f2012-03-14 21:11:57281 view_.reset(content::GetContentClient()->browser()->
282 OverrideCreateWebContentsView(this));
283 if (!view_.get()) {
284 content::WebContentsViewDelegate* delegate =
285 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
286 this);
[email protected]68b52252012-04-04 19:26:13287#if defined(USE_AURA)
288 view_.reset(new TabContentsViewAura(this, delegate));
289#elif defined(OS_WIN)
[email protected]38b098f2012-03-14 21:11:57290 view_.reset(new TabContentsViewWin(this, delegate));
291#elif defined(TOOLKIT_GTK)
292 view_.reset(new content::TabContentsViewGtk(this, delegate));
293#elif defined(OS_MACOSX)
294 view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate));
295#elif defined(OS_ANDROID)
296 view_.reset(new WebContentsViewAndroid(this));
297#endif
[email protected]dbd407f2012-03-14 21:30:37298 (void)delegate;
[email protected]38b098f2012-03-14 21:11:57299 }
300 CHECK(view_.get());
301
[email protected]34ac70502009-09-25 17:07:23302 // We have the initial size of the view be based on the size of the passed in
303 // tab contents (normally a tab from the same window).
304 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21305 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00306
307#if defined(ENABLE_JAVA_BRIDGE)
308 java_bridge_dispatcher_host_manager_.reset(
309 new JavaBridgeDispatcherHostManager(this));
310#endif
[email protected]8dd709fb2012-04-06 00:49:06311
312 browser_plugin_web_contents_observer_.reset(
313 new content::BrowserPluginWebContentsObserver(this));
[email protected]332af7732009-03-11 13:21:35314}
initial.commit09911bf2008-07-26 23:55:29315
316TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32317 is_being_destroyed_ = true;
318
[email protected]3ab9cb82011-06-03 18:02:07319 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55320 if (dialog_creator_)
321 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07322
[email protected]da8543762012-03-20 08:52:20323 if (color_chooser_)
324 color_chooser_->End();
325
[email protected]420ae012009-04-24 05:16:32326 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32327
[email protected]420ae012009-04-24 05:16:32328 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07329 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09330 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
331 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07332 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32333
334 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07335#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32336 // If we still have a window handle, destroy it. GetNativeView can return
337 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42338 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52339 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58340 if (host && host->GetView())
341 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42342 }
[email protected]420ae012009-04-24 05:16:32343#endif
[email protected]7ab1e7d62009-10-14 23:32:01344
345 // OnCloseStarted isn't called in unit tests.
346 if (!tab_close_start_time_.is_null()) {
347 UMA_HISTOGRAM_TIMES("Tab.Close",
348 base::TimeTicks::Now() - tab_close_start_time_);
349 }
[email protected]b5a1d11c2011-02-17 03:09:42350
[email protected]d8c660432011-12-22 20:51:25351 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08352
[email protected]6934a702011-12-20 00:04:51353 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42354}
355
[email protected]64d69de42012-02-06 00:19:54356WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
357 const GURL& url) {
358 WebPreferences prefs;
359
360 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
361
362 prefs.developer_extras_enabled = true;
363 prefs.javascript_enabled =
364 !command_line.HasSwitch(switches::kDisableJavaScript);
365 prefs.web_security_enabled =
366 !command_line.HasSwitch(switches::kDisableWebSecurity);
367 prefs.plugins_enabled =
368 !command_line.HasSwitch(switches::kDisablePlugins);
369 prefs.java_enabled =
370 !command_line.HasSwitch(switches::kDisableJava);
371
372 prefs.uses_page_cache =
373 command_line.HasSwitch(switches::kEnableFastback);
374 prefs.remote_fonts_enabled =
375 !command_line.HasSwitch(switches::kDisableRemoteFonts);
376 prefs.xss_auditor_enabled =
377 !command_line.HasSwitch(switches::kDisableXSSAuditor);
378 prefs.application_cache_enabled =
379 !command_line.HasSwitch(switches::kDisableApplicationCache);
380
381 prefs.local_storage_enabled =
382 !command_line.HasSwitch(switches::kDisableLocalStorage);
383 prefs.databases_enabled =
384 !command_line.HasSwitch(switches::kDisableDatabases);
385 prefs.webaudio_enabled =
386 !command_line.HasSwitch(switches::kDisableWebAudio);
387
388 prefs.experimental_webgl_enabled =
389 GpuProcessHost::gpu_enabled() &&
390 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
391 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
392
393 prefs.gl_multisampling_enabled =
394 !command_line.HasSwitch(switches::kDisableGLMultisampling);
395 prefs.privileged_webgl_extensions_enabled =
396 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
397 prefs.site_specific_quirks_enabled =
398 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
399 prefs.allow_file_access_from_file_urls =
400 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
401 prefs.show_composited_layer_borders =
402 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
403 prefs.show_composited_layer_tree =
404 command_line.HasSwitch(switches::kShowCompositedLayerTree);
405 prefs.show_fps_counter =
406 command_line.HasSwitch(switches::kShowFPSCounter);
407 prefs.accelerated_compositing_enabled =
408 GpuProcessHost::gpu_enabled() &&
409 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54410 prefs.force_compositing_mode =
411 command_line.HasSwitch(switches::kForceCompositingMode);
412 prefs.fixed_position_compositing_enabled =
413 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
414 prefs.accelerated_2d_canvas_enabled =
415 GpuProcessHost::gpu_enabled() &&
416 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58417 prefs.deferred_2d_canvas_enabled =
418 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36419 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31420 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54421 prefs.accelerated_painting_enabled =
422 GpuProcessHost::gpu_enabled() &&
423 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
424 prefs.accelerated_filters_enabled =
425 GpuProcessHost::gpu_enabled() &&
426 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
427 prefs.accelerated_layers_enabled =
428 prefs.accelerated_animation_enabled =
429 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
430 prefs.composite_to_texture_enabled =
431 command_line.HasSwitch(switches::kEnableCompositeToTexture);
432 prefs.accelerated_plugins_enabled =
433 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
434 prefs.accelerated_video_enabled =
435 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
436 prefs.partial_swap_enabled =
437 command_line.HasSwitch(switches::kEnablePartialSwap);
438 prefs.interactive_form_validation_enabled =
439 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
440 prefs.fullscreen_enabled =
441 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16442 prefs.css_regions_enabled =
443 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29444 prefs.css_shaders_enabled =
445 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]64d69de42012-02-06 00:19:54446
447#if defined(OS_MACOSX)
448 bool default_enable_scroll_animator = true;
449#else
450 // On CrOS, the launcher always passes in the --enable flag.
451 bool default_enable_scroll_animator = false;
452#endif
453 prefs.enable_scroll_animator = default_enable_scroll_animator;
454 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
455 prefs.enable_scroll_animator = true;
456 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
457 prefs.enable_scroll_animator = false;
458
459 prefs.visual_word_movement_enabled =
460 command_line.HasSwitch(switches::kEnableVisualWordMovement);
461 prefs.per_tile_painting_enabled =
462 command_line.HasSwitch(switches::kEnablePerTilePainting);
463
464 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32465 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54466 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11467 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
468 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54469 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11470 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54471 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11472 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54473 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11474 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54475 prefs.gl_multisampling_enabled = false;
476
477 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45478 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32479 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54480 prefs.accelerated_video_enabled = false;
481 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45482 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54483 }
484 }
485
[email protected]b9535422012-02-09 01:47:59486 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58487 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54488 prefs.loads_images_automatically = true;
489 prefs.javascript_enabled = true;
490 }
491
492 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
493
494 // Force accelerated compositing and 2d canvas off for chrome:, about: and
495 // chrome-devtools: pages (unless it's specifically allowed).
496 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54497 url.SchemeIs(chrome::kChromeUIScheme) ||
498 (url.SchemeIs(chrome::kAboutScheme) &&
499 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25500 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54501 prefs.accelerated_compositing_enabled = false;
502 prefs.accelerated_2d_canvas_enabled = false;
503 }
504
[email protected]43d9d782012-03-01 15:40:09505 int default_device_scale_factor;
506 base::StringToInt(command_line.GetSwitchValueASCII(
507 switches::kDefaultDeviceScaleFactor),
508 &default_device_scale_factor);
509
510 prefs.default_device_scale_factor = default_device_scale_factor;
511
[email protected]2e21fe292012-03-02 22:52:32512 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54513
514 return prefs;
515}
516
[email protected]d202a7c2012-01-04 07:53:47517NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20518 return controller_;
519}
520
[email protected]765187182012-01-11 23:59:28521RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
522 return &render_manager_;
523}
524
[email protected]724159a2010-12-30 01:11:18525bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56526 if (GetWebUI() &&
527 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17528 return true;
[email protected]d2353452012-01-19 19:53:56529 }
[email protected]f82d57b52011-04-27 19:13:17530
[email protected]d8c660432011-12-22 20:51:25531 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
532 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10533 while ((observer = it.GetNext()) != NULL)
534 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53535 return true;
[email protected]403415a2011-01-10 18:57:53536
[email protected]724159a2010-12-30 01:11:18537 bool handled = true;
538 bool message_is_ok = true;
539 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58540 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
541 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24542 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
543 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18544 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
545 OnDidStartProvisionalLoadForFrame)
546 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
547 OnDidRedirectProvisionalLoad)
548 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
549 OnDidFailProvisionalLoadWithError)
550 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
551 OnDidLoadResourceFromMemoryCache)
552 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
553 OnDidDisplayInsecureContent)
554 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
555 OnDidRunInsecureContent)
556 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
557 OnDocumentLoadedInFrame)
558 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17559 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
560 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25561 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26562 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59563 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21564 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20565 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
566 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
567 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16568 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45569 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10570 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20571 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
572 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
573 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
574 OnSetSelectedColorInColorChooser)
[email protected]724159a2010-12-30 01:11:18575 IPC_MESSAGE_UNHANDLED(handled = false)
576 IPC_END_MESSAGE_MAP_EX()
577
578 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38579 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18580 GetRenderProcessHost()->ReceivedBadMessage();
581 }
582
583 return handled;
584}
585
[email protected]6c2e472f2011-08-24 23:26:18586void TabContents::RunFileChooser(
587 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23588 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51589 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18590}
591
[email protected]c5eed492012-01-04 17:07:50592NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56593 return controller_;
594}
595
[email protected]c5eed492012-01-04 17:07:50596const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56597 return controller_;
598}
599
[email protected]627e0512011-12-21 22:55:30600content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55601 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30602}
603
[email protected]f5fa20e2011-12-21 22:35:56604void TabContents::SetViewType(content::ViewType type) {
605 view_type_ = type;
606}
607
[email protected]ea049a02011-12-25 21:37:09608content::ViewType TabContents::GetViewType() const {
609 return view_type_;
610}
611
[email protected]be1f56ab2011-12-22 06:55:31612const GURL& TabContents::GetURL() const {
613 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23614 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51615 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31616}
617
618
619const base::PropertyBag* TabContents::GetPropertyBag() const {
620 return &property_bag_;
621}
622
623base::PropertyBag* TabContents::GetPropertyBag() {
624 return &property_bag_;
625}
626
627content::WebContentsDelegate* TabContents::GetDelegate() {
628 return delegate_;
629}
630
631void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
632 // TODO(cbentzel): remove this debugging code?
633 if (delegate == delegate_)
634 return;
635 if (delegate_)
636 delegate_->Detach(this);
637 delegate_ = delegate;
638 if (delegate_)
639 delegate_->Attach(this);
640}
641
[email protected]f3b1a082011-11-18 00:34:30642content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41643 RenderViewHostImpl* host = render_manager_.current_host();
644 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16645}
646
[email protected]be1f56ab2011-12-22 06:55:31647RenderViewHost* TabContents::GetRenderViewHost() const {
648 return render_manager_.current_host();
649}
650
651RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
652 return render_manager_.GetRenderWidgetHostView();
653}
654
[email protected]8643e6d2012-01-18 20:26:10655content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31656 return view_.get();
657}
658
[email protected]01ec4ec2012-01-18 04:13:47659content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50660 WebUIControllerFactory* factory =
661 content::GetContentClient()->browser()->GetWebUIControllerFactory();
662 if (!factory)
663 return NULL;
[email protected]d2353452012-01-19 19:53:56664 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22665 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50666 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22667 if (controller) {
668 web_ui->SetController(controller);
669 return web_ui;
670 }
671
672 delete web_ui;
673 return NULL;
674}
675
[email protected]01ec4ec2012-01-18 04:13:47676content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31677 return render_manager_.web_ui() ? render_manager_.web_ui()
678 : render_manager_.pending_web_ui();
679}
680
[email protected]01ec4ec2012-01-18 04:13:47681content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31682 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34683}
684
[email protected]96d185d2009-04-24 03:28:54685const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55686 // Transient entries take precedence. They are used for interstitial pages
687 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23688 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08689 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20690 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30691 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23692 if (entry) {
[email protected]b5cca982011-05-26 04:42:08693 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23694 }
[email protected]7ade2732011-02-10 00:13:58695 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
696 render_manager_.pending_web_ui() : render_manager_.web_ui();
697 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54698 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55699 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54700 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35701 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22702 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54703 if (!title.empty())
704 return title;
705 }
706 }
707
708 // We use the title for the last committed entry rather than a pending
709 // navigation entry. For example, when the user types in a URL, we want to
710 // keep the old page's title until the new load has committed and we get a new
711 // title.
[email protected]96d185d2009-04-24 03:28:54712 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23713 if (entry) {
[email protected]b5cca982011-05-26 04:42:08714 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23715 }
[email protected]987fc3a2011-05-26 14:18:09716
717 // |page_title_when_no_navigation_entry_| is finally used
718 // if no title cannot be retrieved.
719 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54720}
721
[email protected]d5f942ba2008-09-26 19:30:34722int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46723 return GetMaxPageIDForSiteInstance(GetSiteInstance());
724}
725
726int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33727 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
728 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46729
[email protected]b6583592012-01-25 19:52:33730 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34731}
732
733void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46734 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
735}
736
[email protected]b6583592012-01-25 19:52:33737void TabContents::UpdateMaxPageIDForSiteInstance(
738 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46739 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33740 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34741}
742
[email protected]91854cd2012-01-10 19:43:57743void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
744 max_page_ids_ = tab_contents->max_page_ids_;
745}
746
[email protected]96d185d2009-04-24 03:28:54747SiteInstance* TabContents::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58748 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54749}
750
[email protected]77362eb2011-08-01 17:18:38751SiteInstance* TabContents::GetPendingSiteInstance() const {
752 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
753 render_manager_.pending_render_view_host() :
754 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58755 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38756}
757
[email protected]be1f56ab2011-12-22 06:55:31758bool TabContents::IsLoading() const {
759 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49760}
761
[email protected]be1f56ab2011-12-22 06:55:31762bool TabContents::IsWaitingForResponse() const {
763 return waiting_for_response_;
764}
765
766const net::LoadStateWithParam& TabContents::GetLoadState() const {
767 return load_state_;
768}
769
770const string16& TabContents::GetLoadStateHost() const {
771 return load_state_host_;
772}
773
774uint64 TabContents::GetUploadSize() const {
775 return upload_size_;
776}
777
778uint64 TabContents::GetUploadPosition() const {
779 return upload_position_;
780}
781
782const std::string& TabContents::GetEncoding() const {
783 return encoding_;
784}
785
786bool TabContents::DisplayedInsecureContent() const {
787 return displayed_insecure_content_;
788}
789
790void TabContents::SetCapturingContents(bool cap) {
791 capturing_contents_ = cap;
792}
793
794bool TabContents::IsCrashed() const {
795 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
796 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
797 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49798}
799
[email protected]443b80e2010-12-14 00:42:23800void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
801 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34802 return;
803
[email protected]443b80e2010-12-14 00:42:23804 crashed_status_ = status;
805 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46806 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34807}
808
[email protected]be1f56ab2011-12-22 06:55:31809base::TerminationStatus TabContents::GetCrashedStatus() const {
810 return crashed_status_;
811}
812
813bool TabContents::IsBeingDestroyed() const {
814 return is_being_destroyed_;
815}
816
[email protected]d5f942ba2008-09-26 19:30:34817void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
818 if (delegate_)
819 delegate_->NavigationStateChanged(this, changed_flags);
820}
821
[email protected]96d185d2009-04-24 03:28:54822void TabContents::DidBecomeSelected() {
823 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04824 RenderWidgetHostViewPort* rwhv =
825 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16826 if (rwhv) {
827 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43828#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16829 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43830#endif
831 }
[email protected]96d185d2009-04-24 03:28:54832
[email protected]5ac20162010-11-24 23:33:11833 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38834
[email protected]d8c660432011-12-22 20:51:25835 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59836
837 // The resize rect might have changed while this was inactive -- send the new
838 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58839 RenderViewHostImpl* rvh =
840 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59841 if (rvh) {
842 rvh->ResizeRectChanged(GetRootWindowResizerRect());
843 }
[email protected]96d185d2009-04-24 03:28:54844}
845
[email protected]be1f56ab2011-12-22 06:55:31846
847base::TimeTicks TabContents::GetLastSelectedTime() const {
848 return last_selected_time_;
849}
850
[email protected]96d185d2009-04-24 03:28:54851void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31852 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52853 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
854 // open a tab in then background, then closes the tab before selecting it.
855 // This is because closing the tab calls TabContents::Destroy(), which
856 // removes the |GetRenderViewHost()|; then when we actually destroy the
857 // window, OnWindowPosChanged() notices and calls HideContents() (which
858 // calls us).
[email protected]c30585c2012-02-16 15:02:04859 RenderWidgetHostViewPort* rwhv =
860 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16861 if (rwhv)
862 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54863 }
864
[email protected]ad50def52011-10-19 23:17:07865 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09866 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
867 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07868 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54869}
870
[email protected]be1f56ab2011-12-22 06:55:31871void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04872 RenderWidgetHostViewPort* rwhv =
873 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31874 if (rwhv)
875 rwhv->DidBecomeSelected();
876}
877
878void TabContents::HideContents() {
879 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
880 // our superclass HideContents(), because some callers want to be very picky
881 // about the order in which these get called. In addition to making the code
882 // here practically impossible to understand, this also means we end up
883 // calling TabContents::WasHidden() twice if callers call both versions of
884 // HideContents() on a TabContents.
885 WasHidden();
886}
887
888bool TabContents::NeedToFireBeforeUnload() {
889 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27890 return WillNotifyDisconnection() &&
891 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58892 !static_cast<RenderViewHostImpl*>(
893 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31894}
895
[email protected]0bfbf882011-12-22 18:19:27896void TabContents::Stop() {
897 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25898 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27899}
900
[email protected]d9083482012-01-06 00:38:46901WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27902 // We create a new SiteInstance so that the new tab won't share processes
903 // with the old one. This can be changed in the future if we need it to share
904 // processes for some reason.
905 TabContents* tc = new TabContents(
906 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33907 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27908 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20909 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27910 return tc;
911}
912
[email protected]2a6bc3e2011-12-28 23:51:33913void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27914 WindowOpenDisposition disposition,
915 const gfx::Rect& initial_pos,
916 bool user_gesture) {
917 if (!delegate_)
918 return;
919
920 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
921 user_gesture);
922}
923
924gfx::NativeView TabContents::GetContentNativeView() const {
925 return view_->GetContentNativeView();
926}
927
928gfx::NativeView TabContents::GetNativeView() const {
929 return view_->GetNativeView();
930}
931
932void TabContents::GetContainerBounds(gfx::Rect* out) const {
933 view_->GetContainerBounds(out);
934}
935
936void TabContents::Focus() {
937 view_->Focus();
938}
939
[email protected]d8c660432011-12-22 20:51:25940void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31941 observers_.AddObserver(observer);
942}
943
[email protected]d8c660432011-12-22 20:51:25944void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31945 observers_.RemoveObserver(observer);
946}
947
[email protected]d5f942ba2008-09-26 19:30:34948void TabContents::Activate() {
949 if (delegate_)
950 delegate_->ActivateContents(this);
951}
952
[email protected]ea42e7782010-08-23 23:58:12953void TabContents::Deactivate() {
954 if (delegate_)
955 delegate_->DeactivateContents(this);
956}
957
[email protected]63954792011-07-11 04:17:48958void TabContents::LostCapture() {
959 if (delegate_)
960 delegate_->LostCapture();
961}
962
963bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
964 bool* is_keyboard_shortcut) {
965 return delegate_ &&
966 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
967}
968
969void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
970 if (delegate_)
971 delegate_->HandleKeyboardEvent(event);
972}
973
[email protected]32ded2212011-11-10 18:51:43974void TabContents::HandleMouseDown() {
975 if (delegate_)
976 delegate_->HandleMouseDown();
977}
978
[email protected]63954792011-07-11 04:17:48979void TabContents::HandleMouseUp() {
980 if (delegate_)
981 delegate_->HandleMouseUp();
982}
983
984void TabContents::HandleMouseActivate() {
985 if (delegate_)
986 delegate_->HandleMouseActivate();
987}
988
[email protected]8a5e0ca2011-08-25 06:30:47989void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
990 if (delegate_)
991 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
992}
993
[email protected]5d5f7af2011-10-01 01:38:12994bool TabContents::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:38995 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:12996}
997
[email protected]e9621112011-10-17 05:38:37998void TabContents::RequestToLockMouse() {
999 if (delegate_) {
1000 delegate_->RequestToLockMouse(this);
1001 } else {
1002 GotResponseToLockMouseRequest(false);
1003 }
1004}
1005
1006void TabContents::LostMouseLock() {
1007 if (delegate_)
1008 delegate_->LostMouseLock();
1009}
1010
[email protected]0548c5352011-09-07 00:33:331011void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231012 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331013 if (delegate_)
1014 delegate_->UpdatePreferredSize(this, pref_size);
1015}
1016
[email protected]61e2b3cc2012-03-02 16:13:341017void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
1018 if (delegate_)
1019 delegate_->ResizeDueToAutoResize(this, new_size);
1020}
1021
[email protected]32ded2212011-11-10 18:51:431022void TabContents::WebUISend(RenderViewHost* render_view_host,
1023 const GURL& source_url,
1024 const std::string& name,
1025 const base::ListValue& args) {
1026 if (delegate_)
1027 delegate_->WebUISend(this, source_url, name, args);
1028}
1029
[email protected]e5d549d2011-12-28 01:29:201030WebContents* TabContents::OpenURL(const OpenURLParams& params) {
1031 if (!delegate_)
1032 return NULL;
[email protected]00c37fc2011-08-02 00:22:501033
[email protected]e5d549d2011-12-28 01:29:201034 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1035 // Notify observers.
1036 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1037 DidOpenURL(params.url, params.referrer,
1038 params.disposition, params.transition));
1039 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341040}
1041
[email protected]1ccb3568d2010-02-19 10:51:161042bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501043 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251044 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231045 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251046 reload_type);
[email protected]876bc832010-09-07 16:29:541047}
[email protected]96d185d2009-04-24 03:28:541048
[email protected]876bc832010-09-07 16:29:541049bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231050 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501051 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401052 // The renderer will reject IPC messages with URLs longer than
1053 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511054 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401055 return false;
1056
[email protected]9f76c1e2012-03-05 15:15:581057 RenderViewHostImpl* dest_render_view_host =
1058 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401059 if (!dest_render_view_host)
1060 return false; // Unable to create the desired render view host.
1061
[email protected]80a8fad2011-01-29 04:02:381062 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071063 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581064 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501065 WebUIControllerFactory* factory =
1066 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1067 bool is_allowed_in_web_ui_renderer =
1068 factory &&
1069 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431070#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511071 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431072#endif
[email protected]1684454a2012-03-24 04:12:231073 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1074 !is_allowed_in_web_ui_renderer) {
1075 // Log the URL to help us diagnose http://crbug.com/72235.
1076 content::GetContentClient()->SetActiveURL(entry.GetURL());
1077 CHECK(0);
1078 }
[email protected]54ec6472010-04-09 19:39:581079
[email protected]96d185d2009-04-24 03:28:541080 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441081 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521082 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441083 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511084 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541085
1086 // Used for page load time metrics.
1087 current_load_start_ = base::TimeTicks::Now();
1088
1089 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341090 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271091 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471092 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341093 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541094
[email protected]36fc0392011-12-25 03:59:511095 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541096 // HACK!! This code suppresses javascript: URLs from being added to
1097 // session history, which is what we want to do for javascript: URLs that
1098 // do not generate content. What we really need is a message from the
1099 // renderer telling us that a new page was not created. The same message
1100 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511101 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541102 return false;
1103 }
1104
[email protected]3c9e1872010-11-18 16:17:491105 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251106 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041107 observers_,
[email protected]36fc0392011-12-25 03:59:511108 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541109
[email protected]09b29342011-06-24 19:18:481110 if (delegate_)
1111 delegate_->DidNavigateToPendingEntry(this);
1112
[email protected]d5f942ba2008-09-26 19:30:341113 return true;
1114}
1115
[email protected]b6583592012-01-25 19:52:331116void TabContents::SetHistoryLengthAndPrune(
1117 const SiteInstance* site_instance,
1118 int history_length,
1119 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411120 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1121 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191122 if (render_manager_.pending_render_view_host()) {
1123 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141124 return;
[email protected]9e1ad4b2011-08-14 16:49:191125 }
[email protected]9f76c1e2012-03-05 15:15:581126 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191127 if (!rvh) {
1128 NOTREACHED();
1129 return;
1130 }
[email protected]9f76c1e2012-03-05 15:15:581131 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191132 NOTREACHED();
1133 return;
1134 }
[email protected]9f76c1e2012-03-05 15:15:581135 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191136 history_length,
1137 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141138}
1139
[email protected]90daadb42009-06-08 21:27:281140void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271141 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541142 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1143 return;
1144 }
[email protected]9f76c1e2012-03-05 15:15:581145 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541146}
1147
[email protected]0bfbf882011-12-22 18:19:271148bool TabContents::ShowingInterstitialPage() const {
1149 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541150}
1151
[email protected]0bfbf882011-12-22 18:19:271152InterstitialPage* TabContents::GetInterstitialPage() const {
1153 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221154}
1155
[email protected]a53209b2012-01-20 16:48:161156bool TabContents::IsSavable() {
1157 // WebKit creates Document object when MIME type is application/xhtml+xml,
1158 // so we also support this MIME type.
1159 return contents_mime_type_ == "text/html" ||
1160 contents_mime_type_ == "text/xml" ||
1161 contents_mime_type_ == "application/xhtml+xml" ||
1162 contents_mime_type_ == "text/plain" ||
1163 contents_mime_type_ == "text/css" ||
1164 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1165}
1166
[email protected]c7dd2f62011-07-18 15:57:591167void TabContents::OnSavePage() {
1168 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161169 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481170 download_stats::RecordDownloadSource(
1171 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261172 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141173 return;
[email protected]c7dd2f62011-07-18 15:57:591174 }
1175
1176 Stop();
1177
1178 // Create the save package and possibly prompt the user for the name to save
1179 // the page as. The user prompt is an asynchronous operation that runs on
1180 // another thread.
1181 save_package_ = new SavePackage(this);
1182 save_package_->GetSaveInfo();
1183}
1184
1185// Used in automated testing to bypass prompting the user for file names.
1186// Instead, the names and paths are hard coded rather than running them through
1187// file name sanitation and extension / mime checking.
1188bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161189 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591190 // Stop the page from navigating.
1191 Stop();
1192
1193 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1194 return save_package_->Init();
1195}
1196
[email protected]aa4f3972012-03-01 18:12:121197void TabContents::GenerateMHTML(
1198 const FilePath& file,
1199 const base::Callback<void(const FilePath&, int64)>& callback) {
1200 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1201}
1202
[email protected]420ae012009-04-24 05:16:321203bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231204 NavigationEntryImpl* active_entry =
1205 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321206 return (active_entry != NULL &&
1207 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511208 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321209}
1210
[email protected]0bfbf882011-12-22 18:19:271211const std::string& TabContents::GetContentsMimeType() const {
1212 return contents_mime_type_;
1213}
1214
1215bool TabContents::WillNotifyDisconnection() const {
1216 return notify_disconnection_;
1217}
1218
[email protected]b2fe07d12010-02-09 14:38:081219void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311220 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581221 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1222 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161223}
1224
[email protected]b2fe07d12010-02-09 14:38:081225void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311226 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581227 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1228 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161229}
1230
[email protected]0bfbf882011-12-22 18:19:271231content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1232 return &renderer_preferences_;
1233}
1234
1235void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1236 new_tab_start_time_ = time;
1237}
1238
1239base::TimeTicks TabContents::GetNewTabStartTime() const {
1240 return new_tab_start_time_;
1241}
1242
[email protected]7ab1e7d62009-10-14 23:32:011243void TabContents::OnCloseStarted() {
1244 if (tab_close_start_time_.is_null())
1245 tab_close_start_time_ = base::TimeTicks::Now();
1246}
1247
[email protected]46624bf2010-06-09 16:04:191248bool TabContents::ShouldAcceptDragAndDrop() const {
1249#if defined(OS_CHROMEOS)
1250 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1251 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511252 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201253 return false;
1254 return true;
[email protected]46624bf2010-06-09 16:04:191255#else
1256 return true;
1257#endif
1258}
1259
[email protected]7813bd72011-02-05 02:19:341260void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521261 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581262 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511263 if (delegate_)
1264 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341265}
1266
[email protected]0bfbf882011-12-22 18:19:271267void TabContents::SetClosedByUserGesture(bool value) {
1268 closed_by_user_gesture_ = value;
1269}
1270
1271bool TabContents::GetClosedByUserGesture() const {
1272 return closed_by_user_gesture_;
1273}
1274
[email protected]d0b8d092010-10-25 04:05:171275double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051276 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561277 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251278 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171279 return 0;
[email protected]b75b8292010-10-01 07:28:251280
1281 double zoom_level;
1282 if (temporary_zoom_settings_) {
1283 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581284 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251285 } else {
[email protected]2ae88d12011-10-14 09:11:191286 GURL url;
[email protected]10f417c52011-12-28 21:04:231287 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191288 // Since zoom map is updated using rewritten URL, use rewritten URL
1289 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511290 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191291 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251292 }
[email protected]d0b8d092010-10-25 04:05:171293 return zoom_level;
1294}
[email protected]b75b8292010-10-01 07:28:251295
[email protected]d0b8d092010-10-25 04:05:171296int TabContents::GetZoomPercent(bool* enable_increment,
1297 bool* enable_decrement) {
1298 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011299 // Calculate the zoom percent from the factor. Round up to the nearest whole
1300 // number.
[email protected]b75b8292010-10-01 07:28:251301 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011302 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251303 *enable_decrement = percent > minimum_zoom_percent_;
1304 *enable_increment = percent < maximum_zoom_percent_;
1305 return percent;
1306}
1307
[email protected]3c733bde2010-12-21 19:56:311308void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501309 if (!delegate_)
1310 return;
1311
[email protected]10f417c52011-12-28 21:04:231312 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501313 if (!active_entry)
1314 return;
1315
[email protected]36fc0392011-12-25 03:59:511316 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121317}
1318
[email protected]932b7a12011-03-09 12:50:271319void TabContents::ViewFrameSource(const GURL& url,
1320 const std::string& content_state) {
1321 if (!delegate_)
1322 return;
1323
1324 delegate_->ViewSourceForFrame(this, url, content_state);
1325}
1326
[email protected]0bfbf882011-12-22 18:19:271327int TabContents::GetMinimumZoomPercent() const {
1328 return minimum_zoom_percent_;
1329}
1330
1331int TabContents::GetMaximumZoomPercent() const {
1332 return maximum_zoom_percent_;
1333}
1334
[email protected]bcd2815602012-01-14 18:17:231335gfx::Size TabContents::GetPreferredSize() const {
1336 return preferred_size_;
1337}
1338
[email protected]0bfbf882011-12-22 18:19:271339int TabContents::GetContentRestrictions() const {
1340 return content_restrictions_;
1341}
1342
1343WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501344 WebUIControllerFactory* factory =
1345 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1346 if (!factory)
1347 return WebUI::kNoWebUI;
1348 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271349}
1350
[email protected]01ec4ec2012-01-18 04:13:471351content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271352 // When there is a pending navigation entry, we want to use the pending WebUI
1353 // that goes along with it to control the basic flags. For example, we want to
1354 // show the pending URL in the URL bar, so we want the display_url flag to
1355 // be from the pending entry.
1356 //
1357 // The confusion comes because there are multiple possibilities for the
1358 // initial load in a tab as a side effect of the way the RenderViewHostManager
1359 // works.
1360 //
1361 // - For the very first tab the load looks "normal". The new tab Web UI is
1362 // the pending one, and we want it to apply here.
1363 //
1364 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1365 // get switched to the one previously associated with the new tab pages.
1366 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1367 // have a committed Web UI in this case.
1368 //
1369 // This condition handles all of these cases:
1370 //
1371 // - First load in first tab: no committed nav entry + pending nav entry +
1372 // pending dom ui:
1373 // -> Use pending Web UI if any.
1374 //
1375 // - First load in second tab: no committed nav entry + pending nav entry +
1376 // no pending Web UI:
1377 // -> Use the committed Web UI if any.
1378 //
1379 // - Second navigation in any tab: committed nav entry + pending nav entry:
1380 // -> Use pending Web UI if any.
1381 //
1382 // - Normal state with no load: committed nav entry + no pending nav entry:
1383 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251384 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271385 (controller_.GetLastCommittedEntry() ||
1386 render_manager_.pending_web_ui()))
1387 return render_manager_.pending_web_ui();
1388 return render_manager_.web_ui();
1389}
1390
1391bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1392 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581393 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271394}
1395
[email protected]a0358d72012-03-09 14:06:501396bool TabContents::HasOpener() const {
1397 return has_opener_;
1398}
1399
[email protected]da8543762012-03-20 08:52:201400void TabContents::DidChooseColorInColorChooser(int color_chooser_id,
1401 const SkColor& color) {
1402 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1403 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1404}
1405
1406void TabContents::DidEndColorChooser(int color_chooser_id) {
1407 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1408 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1409 if (delegate_)
1410 delegate_->DidEndColorChooser();
1411 color_chooser_ = NULL;
1412}
1413
[email protected]0bfbf882011-12-22 18:19:271414bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471415 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271416 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221417 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231418 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411419 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271420}
1421
1422void TabContents::SetFocusToLocationBar(bool select_all) {
1423 if (delegate_)
1424 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211425}
1426
[email protected]8b5af492011-11-28 21:50:581427void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301428 const string16& type,
1429 const string16& href,
1430 const string16& title,
1431 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511432 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301433 this, action, type, href, title, disposition);
1434}
1435
[email protected]678105012011-12-09 04:01:211436void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301437 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001438 WebIntentsDispatcherImpl* intents_dispatcher =
1439 new WebIntentsDispatcherImpl(this, intent, intent_id);
1440 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301441}
1442
[email protected]724159a2010-12-30 01:11:181443void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1444 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591445 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181446 const GURL& url) {
1447 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1448 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451449 GURL validated_opener_url(opener_url);
[email protected]9f76c1e2012-03-05 15:15:581450 GetRenderViewHostImpl()->FilterURL(
1451 ChildProcessSecurityPolicyImpl::GetInstance(),
1452 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451453 false,
[email protected]9f76c1e2012-03-05 15:15:581454 &validated_url);
[email protected]6b7cd8f2012-03-21 21:02:451455 GetRenderViewHostImpl()->FilterURL(
1456 ChildProcessSecurityPolicyImpl::GetInstance(),
1457 GetRenderProcessHost()->GetID(),
1458 true,
1459 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181460
[email protected]8093a542011-05-13 07:29:321461 RenderViewHost* rvh =
1462 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521463 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101464 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251465 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101466 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321467 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101468
[email protected]724159a2010-12-30 01:11:181469 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591470 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251471 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451472 ProvisionalChangeToMainFrameUrl(validated_url,
1473 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181474 }
1475}
1476
1477void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591478 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181479 const GURL& source_url,
1480 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491481 // TODO(creis): Remove this method and have the pre-rendering code listen to
1482 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1483 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451484 GURL validated_source_url(source_url);
1485 GURL validated_target_url(target_url);
1486 GURL validated_opener_url(opener_url);
1487 GetRenderViewHostImpl()->FilterURL(
1488 ChildProcessSecurityPolicyImpl::GetInstance(),
1489 GetRenderProcessHost()->GetID(),
1490 false,
1491 &validated_source_url);
1492 GetRenderViewHostImpl()->FilterURL(
1493 ChildProcessSecurityPolicyImpl::GetInstance(),
1494 GetRenderProcessHost()->GetID(),
1495 false,
1496 &validated_target_url);
1497 GetRenderViewHostImpl()->FilterURL(
1498 ChildProcessSecurityPolicyImpl::GetInstance(),
1499 GetRenderProcessHost()->GetID(),
1500 true,
1501 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231502 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181503 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251504 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181505 else
1506 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]6b7cd8f2012-03-21 21:02:451507 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181508 return;
[email protected]e7d50892011-01-19 21:47:381509
[email protected]4850a7f2011-03-08 23:36:591510 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251511 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451512 ProvisionalChangeToMainFrameUrl(validated_target_url,
1513 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181514}
1515
1516void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581517 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1518 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1519 << ", error_code: " << params.error_code
1520 << ", error_description: " << params.error_description
1521 << ", is_main_frame: " << params.is_main_frame
1522 << ", showing_repost_interstitial: " <<
1523 params.showing_repost_interstitial
1524 << ", frame_id: " << params.frame_id;
1525 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581526 GetRenderViewHostImpl()->FilterURL(
1527 ChildProcessSecurityPolicyImpl::GetInstance(),
1528 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451529 false,
[email protected]9f76c1e2012-03-05 15:15:581530 &validated_url);
[email protected]724159a2010-12-30 01:11:181531
[email protected]d7b175e2011-10-11 15:31:581532 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181533 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1534 // This means that the interstitial won't be torn down properly, which is
1535 // bad. But if we have an interstitial, go back to another tab type, and
1536 // then load the same interstitial again, we could end up getting the first
1537 // interstitial's "failed" message (as a result of the cancel) when we're on
1538 // the second one.
1539 //
1540 // We can't tell this apart, so we think we're tearing down the current page
1541 // which will cause a crash later one. There is also some code in
1542 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1543 // out because of this problem.
1544 //
1545 // http://code.google.com/p/chromium/issues/detail?id=2855
1546 // Because this will not tear down the interstitial properly, if "back" is
1547 // back to another tab type, the interstitial will still be somewhat alive
1548 // in the previous tab type. If you navigate somewhere that activates the
1549 // tab with the interstitial again, you'll see a flash before the new load
1550 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271551 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181552 LOG(WARNING) << "Discarding message during interstitial.";
1553 return;
1554 }
1555
[email protected]02102f82011-06-13 20:37:021556 // Discard our pending entry if the load canceled (e.g. if we decided to
1557 // download the file instead of load it). We do not verify that the URL
1558 // being canceled matches the pending entry's URL because they will not
1559 // match if a redirect occurred (in which case we do not want to leave a
1560 // stale redirect URL showing). This means that we also cancel the pending
1561 // entry if the user started a new navigation. As a result, the navigation
1562 // controller may not remember that a load is in progress, but the
1563 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251564 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161565 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181566
[email protected]151a63d2011-12-20 22:32:521567 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181568 }
1569
[email protected]d8c660432011-12-22 20:51:251570 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581571 observers_,
1572 DidFailProvisionalLoad(params.frame_id,
1573 params.is_main_frame,
1574 validated_url,
1575 params.error_code,
1576 params.error_description));
[email protected]724159a2010-12-30 01:11:181577}
1578
1579void TabContents::OnDidLoadResourceFromMemoryCache(
1580 const GURL& url,
[email protected]70435962011-08-02 20:13:281581 const std::string& security_info,
1582 const std::string& http_method,
1583 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191584 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181585 cache.Increment();
1586
1587 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081588 int cert_id = 0;
1589 net::CertStatus cert_status = 0;
1590 int security_bits = -1;
1591 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511592 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1593 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301594 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161595 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181596
[email protected]ad50def52011-10-19 23:17:071597 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271598 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501599 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531600 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181601}
1602
1603void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381604 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181605 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201606 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181607}
1608
1609void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021610 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231611 LOG(INFO) << security_origin << " ran insecure content from "
1612 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381613 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411614 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1615 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181616 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411617 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201618 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181619}
1620
1621void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1622 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251623 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101624 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181625}
1626
[email protected]1a55c5be2011-11-29 11:36:311627void TabContents::OnDidFinishLoad(
1628 int64 frame_id,
1629 const GURL& validated_url,
1630 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251631 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311632 DidFinishLoad(frame_id, validated_url, is_main_frame));
1633}
1634
1635void TabContents::OnDidFailLoadWithError(int64 frame_id,
1636 const GURL& validated_url,
1637 bool is_main_frame,
1638 int error_code,
1639 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251640 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311641 DidFailLoad(frame_id, validated_url, is_main_frame,
1642 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181643}
1644
[email protected]c8f73ab2011-01-22 00:05:171645void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271646 content_restrictions_ = restrictions;
1647 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171648}
1649
[email protected]216813952011-05-19 22:21:261650void TabContents::OnGoToEntryAtOffset(int offset) {
1651 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231652 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251653 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261654 if (!entry)
1655 return;
1656 // Note that we don't call NavigationController::GotToOffset() as we don't
1657 // want to create a pending navigation entry (it might end up lingering
1658 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251659 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581660 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511661 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581662 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471663 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571664
1665 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1666 // it in now that we know. This allows us to find the entry when it commits.
1667 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231668 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331669 entry->set_site_instance(
1670 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571671 }
[email protected]216813952011-05-19 22:21:261672 }
1673}
1674
1675void TabContents::OnUpdateZoomLimits(int minimum_percent,
1676 int maximum_percent,
1677 bool remember) {
1678 minimum_zoom_percent_ = minimum_percent;
1679 maximum_zoom_percent_ = maximum_percent;
1680 temporary_zoom_settings_ = !remember;
1681}
1682
[email protected]0bfbf882011-12-22 18:19:271683void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481684 download_stats::RecordDownloadSource(
1685 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261686 // Check if the URL to save matches the URL of the main frame. Since this
1687 // message originates from Pepper plugins, it may not be the case if the
1688 // plugin is an embedded element.
1689 GURL main_frame_url = GetURL();
1690 if (!main_frame_url.is_valid())
1691 return;
1692 bool is_main_frame = (url == main_frame_url);
1693 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271694}
1695
[email protected]3a29a6e2011-08-24 18:26:211696void TabContents::OnEnumerateDirectory(int request_id,
1697 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591698 ChildProcessSecurityPolicyImpl* policy =
1699 ChildProcessSecurityPolicyImpl::GetInstance();
1700 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1701 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211702}
1703
[email protected]7d189022011-08-25 22:54:201704void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511705 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201706}
1707
1708void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1709 const GURL& url,
1710 const string16& title) {
[email protected]b9535422012-02-09 01:47:591711 ChildProcessSecurityPolicyImpl* policy =
1712 ChildProcessSecurityPolicyImpl::GetInstance();
1713 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1714 return;
[email protected]6934a702011-12-20 00:04:511715 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201716}
1717
[email protected]b888919c2011-09-02 00:32:161718void TabContents::OnFindReply(int request_id,
1719 int number_of_matches,
1720 const gfx::Rect& selection_rect,
1721 int active_match_ordinal,
1722 bool final_update) {
[email protected]6934a702011-12-20 00:04:511723 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1724 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001725 // Send a notification to the renderer that we are ready to receive more
1726 // results from the scoping effort of the Find operation. The FindInPage
1727 // scoping is asynchronous and periodically sends results back up to the
1728 // browser using IPC. In an effort to not spam the browser we have the
1729 // browser send an ACK for each FindReply message and have the renderer
1730 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581731 GetRenderViewHostImpl()->Send(
1732 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161733}
1734
[email protected]d952a052011-09-06 18:42:451735void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511736 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451737}
1738
[email protected]7fc4bbb2011-09-08 21:23:101739void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1740 bool blocked_by_policy) {
1741 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251742 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101743 AppCacheAccessed(manifest_url, blocked_by_policy));
1744}
1745
[email protected]da8543762012-03-20 08:52:201746void TabContents::OnOpenColorChooser(int color_chooser_id,
1747 const SkColor& color) {
1748 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1749}
1750
1751void TabContents::OnEndColorChooser(int color_chooser_id) {
1752 if (color_chooser_ &&
1753 color_chooser_id == color_chooser_->identifier())
1754 color_chooser_->End();
1755}
1756
1757void TabContents::OnSetSelectedColorInColorChooser(int color_chooser_id,
1758 const SkColor& color) {
1759 if (color_chooser_ &&
1760 color_chooser_id == color_chooser_->identifier())
1761 color_chooser_->SetSelectedColor(color);
1762}
1763
[email protected]96d185d2009-04-24 03:28:541764// Notifies the RenderWidgetHost instance about the fact that the page is
1765// loading, or done loading and calls the base implementation.
1766void TabContents::SetIsLoading(bool is_loading,
1767 LoadNotificationDetails* details) {
1768 if (is_loading == is_loading_)
1769 return;
1770
1771 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211772 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541773 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561774 upload_size_ = 0;
1775 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541776 }
1777
1778 render_manager_.SetIsLoading(is_loading);
1779
1780 is_loading_ = is_loading;
1781 waiting_for_response_ = is_loading;
1782
[email protected]6ebdc9b2010-09-27 16:55:571783 if (delegate_)
1784 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461785 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541786
[email protected]432115822011-07-10 15:52:271787 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1788 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071789 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541790 if (details)
[email protected]6c2381d2011-10-19 02:52:531791 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071792 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501793 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541794 det);
1795}
1796
[email protected]420ae012009-04-24 05:16:321797void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131798 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321799 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561800 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381801 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441802 // that opened the window, as long as both renderers have the same
1803 // privileges.
[email protected]1fd1a502011-03-30 16:55:561804 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561805 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581806 // web_ui might be NULL if the URL refers to a non-existent extension.
1807 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401808 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521809 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441810 }
1811 }
[email protected]1fd1a502011-03-30 16:55:561812 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441813 }
1814
[email protected]4e697b042011-07-08 06:44:561815 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321816 // Clear the status bubble. This is a workaround for a bug where WebKit
1817 // doesn't let us know that the cursor left an element during a
1818 // transition (this is also why the mouse cursor remains as a hand after
1819 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1820 // clear the bubble when a user navigates to a named anchor in the same
1821 // page.
[email protected]36fc0392011-12-25 03:59:511822 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321823 }
1824
[email protected]a6e82fc2010-02-24 22:28:141825 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471826 // Once the main frame is navigated, we're no longer considered to have
1827 // displayed insecure content.
1828 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171829 }
[email protected]ce5c4502009-05-06 16:46:111830
[email protected]3c9e1872010-11-18 16:17:491831 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251832 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041833 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321834}
1835
1836void TabContents::DidNavigateAnyFramePostCommit(
1837 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131838 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321839 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061840 // If we navigate off the page, reset JavaScript state. This does nothing
1841 // to prevent a malicious script from spamming messages, since the script
1842 // could just reload the page to stop blocking.
1843 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551844 dialog_creator_->ResetJavaScriptState(this);
1845 dialog_creator_ = NULL;
1846 }
[email protected]420ae012009-04-24 05:16:321847
[email protected]3c9e1872010-11-18 16:17:491848 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251849 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041850 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321851}
1852
[email protected]74ce1ad2011-12-16 21:51:461853void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1854 // If we are creating a RVH for a restored controller, then we need to make
1855 // sure the RenderView starts with a next_page_id_ larger than the number
1856 // of restored entries. This must be called before the RenderView starts
1857 // navigating (to avoid a race between the browser updating max_page_id and
1858 // the renderer updating next_page_id_). Because of this, we only call this
1859 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561860 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581861 if (max_restored_page_id >
1862 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1863 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1864 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321865}
1866
[email protected]10f417c52011-12-28 21:04:231867bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571868 const string16& title) {
[email protected]420ae012009-04-24 05:16:321869 // For file URLs without a title, use the pathname instead. In the case of a
1870 // synthesized title, we don't want the update to count toward the "one set
1871 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511872 string16 final_title;
[email protected]420ae012009-04-24 05:16:321873 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511874 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1875 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321876 explicit_set = false; // Don't count synthetic titles toward the set limit.
1877 } else {
[email protected]acafd272011-07-26 17:35:571878 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321879 explicit_set = true;
1880 }
1881
[email protected]987fc3a2011-05-26 14:18:091882 // If a page is created via window.open and never navigated,
1883 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551884 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091885 if (entry) {
[email protected]36fc0392011-12-25 03:59:511886 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091887 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321888
[email protected]36fc0392011-12-25 03:59:511889 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091890 } else {
1891 if (page_title_when_no_navigation_entry_ == final_title)
1892 return false; // Nothing changed, don't bother.
1893
1894 page_title_when_no_navigation_entry_ = final_title;
1895 }
[email protected]420ae012009-04-24 05:16:321896
[email protected]420ae012009-04-24 05:16:321897 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231898 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321899
[email protected]2bb171882012-03-07 02:09:461900 std::pair<content::NavigationEntry*, bool> details =
1901 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141902
[email protected]ad50def52011-10-19 23:17:071903 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441904 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1905 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461906 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041907
[email protected]420ae012009-04-24 05:16:321908 return true;
1909}
1910
1911void TabContents::NotifySwapped() {
1912 // After sending out a swap notification, we need to send a disconnect
1913 // notification so that clients that pick up a pointer to |this| can NULL the
1914 // pointer. See Bug 1230284.
1915 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071916 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201917 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1918 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071919 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321920}
1921
1922void TabContents::NotifyConnected() {
1923 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071924 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121925 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1926 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071927 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321928}
1929
1930void TabContents::NotifyDisconnected() {
1931 if (!notify_disconnection_)
1932 return;
1933
1934 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071935 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321936 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1937 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071938 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321939}
1940
[email protected]8d3347f2009-07-09 22:00:211941RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321942 return view_.get();
1943}
1944
[email protected]8d3347f2009-07-09 22:00:211945RenderViewHostDelegate::RendererManagement*
1946TabContents::GetRendererManagementDelegate() {
1947 return &render_manager_;
1948}
1949
[email protected]daf82f82011-10-31 22:35:311950content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371951 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461952 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511953}
1954
[email protected]768c5472011-12-26 19:06:171955WebContents* TabContents::GetAsWebContents() {
1956 return this;
1957}
1958
[email protected]da4dfc42011-10-12 15:53:561959content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431960 return view_type_;
[email protected]7b291f92009-08-14 05:43:531961}
1962
[email protected]b7a756d42012-01-23 18:08:171963gfx::Rect TabContents::GetRootWindowResizerRect() const {
1964 if (delegate_)
1965 return delegate_->GetRootWindowResizerRect();
1966 return gfx::Rect();
1967}
1968
[email protected]420ae012009-04-24 05:16:321969void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071970 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271971 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321972 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531973 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231974 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321975 if (!entry)
1976 return;
1977
1978 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351979 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561980 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581981 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321982
1983 if (entry->IsViewSourceMode()) {
1984 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:581985 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
1986 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:321987 }
[email protected]0666aef2009-05-13 19:48:081988
[email protected]d487beefe2011-12-21 05:41:211989 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261990
1991 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251992 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321993}
1994
1995void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521996 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321997 // Don't notify the world, since this came from a renderer in the
1998 // background.
1999 return;
2000 }
2001
2002 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312003 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232004 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302005
2006 // Restore the focus to the tab (otherwise the focus will be on the top
2007 // window).
[email protected]484ae5912010-09-29 19:16:142008 if (was_crashed && !FocusLocationBarByDefault() &&
2009 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302010 Focus();
[email protected]484ae5912010-09-29 19:16:142011 }
[email protected]32ded2212011-11-10 18:51:432012
[email protected]d8c660432011-12-22 20:51:252013 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322014}
2015
[email protected]443b80e2010-12-14 00:42:232016void TabContents::RenderViewGone(RenderViewHost* rvh,
2017 base::TerminationStatus status,
2018 int error_code) {
[email protected]151a63d2011-12-20 22:32:522019 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322020 // The pending page's RenderViewHost is gone.
2021 return;
2022 }
2023
2024 SetIsLoading(false, NULL);
2025 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232026 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312027 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322028
[email protected]d8c660432011-12-22 20:51:252029 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272030 observers_,
[email protected]be1f56ab2011-12-22 06:55:312031 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322032}
2033
[email protected]2e4633c2009-07-09 16:58:062034void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482035 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252036 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062037}
2038
[email protected]420ae012009-04-24 05:16:322039void TabContents::DidNavigate(RenderViewHost* rvh,
2040 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582041 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322042 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372043
[email protected]434f69f2012-02-06 21:56:522044 // Update the site of the SiteInstance if it doesn't have one yet, unless
2045 // this is for about:blank. In that case, the SiteInstance can still be
2046 // considered unused until a navigation to a real page.
2047 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2048 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332049 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522050 }
[email protected]420ae012009-04-24 05:16:322051
2052 // Need to update MIME type here because it's referred to in
2053 // UpdateNavigationCommands() called by RendererDidNavigate() to
2054 // determine whether or not to enable the encoding menu.
2055 // It's updated only for the main frame. For a subframe,
2056 // RenderView::UpdateURL does not set params.contents_mime_type.
2057 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2058 // TODO(jungshik): Add a test for the encoding menu to avoid
2059 // regressing it again.
[email protected]2905f742011-10-13 03:51:582060 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322061 contents_mime_type_ = params.contents_mime_type;
2062
[email protected]8286f51a2011-05-31 17:39:132063 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002064 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392065
[email protected]a9c0bfe2010-09-17 08:35:222066 // Send notification about committed provisional loads. This notification is
2067 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2068 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082069 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072070 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2071 // that is not recorded in the navigation history. For the purpose of
2072 // tracking navigation events, we treat this event as a sub frame navigation
2073 // event.
2074 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582075 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222076 // Whether or not a page transition was triggered by going backward or
2077 // forward in the history is only stored in the navigation controller's
2078 // entry list.
2079 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512080 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582081 content::PAGE_TRANSITION_FORWARD_BACK)) {
2082 transition_type = content::PageTransitionFromInt(
2083 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222084 }
[email protected]0d60f0192011-04-14 12:40:102085 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252086 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102087 DidCommitProvisionalLoadForFrame(params.frame_id,
2088 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222089 }
2090
[email protected]76543b92009-08-31 17:27:452091 if (!did_navigate)
2092 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322093
2094 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2095 // for the appropriate notification (best) or you can add it to
2096 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2097 // necessary, please).
2098
2099 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002100 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322101 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512102 if (delegate_)
2103 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002104 }
[email protected]420ae012009-04-24 05:16:322105 DidNavigateAnyFramePostCommit(rvh, details, params);
2106}
2107
2108void TabContents::UpdateState(RenderViewHost* rvh,
2109 int32 page_id,
2110 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152111 // Ensure that this state update comes from either the active RVH or one of
2112 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522113 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322114
2115 // We must be prepared to handle state updates for any page, these occur
2116 // when the user is scrolling and entering form data, as well as when we're
2117 // leaving a page, in which case our state may have already been moved to
2118 // the next page. The navigation controller will look up the appropriate
2119 // NavigationEntry and update it when it is notified via the delegate.
2120
2121 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582122 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322123 if (entry_index < 0)
2124 return;
[email protected]10f417c52011-12-28 21:04:232125 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322126
[email protected]36fc0392011-12-25 03:59:512127 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322128 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512129 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322130 controller_.NotifyEntryChanged(entry, entry_index);
2131}
2132
2133void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572134 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462135 const string16& title,
2136 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322137 // If we have a title, that's a pretty good indication that we've started
2138 // getting useful data.
2139 SetNotWaitingForResponse();
2140
[email protected]73eb2602012-02-09 19:50:552141 // Try to find the navigation entry, which might not be the current one.
2142 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232143 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582144 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092145
[email protected]73eb2602012-02-09 19:50:552146 // We can handle title updates when we don't have an entry in
2147 // UpdateTitleForEntry, but only if the update is from the current RVH.
2148 if (!entry && rvh != GetRenderViewHost())
2149 return;
2150
[email protected]a49e10b2011-08-01 23:57:462151 // TODO(evan): make use of title_direction.
2152 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092153 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322154 return;
2155
2156 // Broadcast notifications when the UI should be updated.
2157 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462158 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322159}
2160
[email protected]420ae012009-04-24 05:16:322161void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402162 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312163 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322164}
2165
2166void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512167 if (delegate_)
2168 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322169}
2170
[email protected]420ae012009-04-24 05:16:322171void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292172 // The UI may be in an event-tracking loop, such as between the
2173 // mouse-down and mouse-up in text selection or a button click.
2174 // Defer the close until after tracking is complete, so that we
2175 // don't free objects out from under the UI.
2176 // TODO(shess): This could probably be integrated with the
2177 // IsDoingDrag() test below. Punting for now because I need more
2178 // research to understand how this impacts platforms other than Mac.
2179 // TODO(shess): This could get more fine-grained. For instance,
2180 // closing a tab in another window while selecting text in the
2181 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212182 if (GetView()->IsEventTracking()) {
2183 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292184 return;
2185 }
2186
[email protected]24a4d1062009-07-10 23:10:422187 // If we close the tab while we're in the middle of a drag, we'll crash.
2188 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212189 if (GetView()->IsDoingDrag()) {
2190 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422191 return;
2192 }
2193
[email protected]420ae012009-04-24 05:16:322194 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522195 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512196 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322197}
2198
[email protected]cd9ed79d2011-11-15 19:22:572199void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522200 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512201 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572202}
2203
[email protected]420ae012009-04-24 05:16:322204void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512205 if (delegate_ && delegate_->IsPopupOrPanel(this))
2206 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322207}
2208
[email protected]7ab1e7d62009-10-14 23:32:012209void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322210 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492211
[email protected]82114f52012-03-20 22:53:412212 if (delegate_ && content_restrictions_)
2213 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492214
2215 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252216 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322217}
2218
[email protected]7ab1e7d62009-10-14 23:32:012219void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322220 scoped_ptr<LoadNotificationDetails> details;
2221
[email protected]10f417c52011-12-28 21:04:232222 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322223 // An entry may not exist for a stop when loading an initial blank page or
2224 // if an iframe injected by script into a blank page finishes loading.
2225 if (entry) {
[email protected]420ae012009-04-24 05:16:322226 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2227
2228 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512229 entry->GetVirtualURL(),
2230 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322231 elapsed,
2232 &controller_,
2233 controller_.GetCurrentEntryIndex()));
2234 }
2235
[email protected]420ae012009-04-24 05:16:322236 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492237
2238 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252239 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322240}
2241
[email protected]c95fa8b2011-04-28 20:26:162242void TabContents::DidCancelLoading() {
2243 controller_.DiscardNonCommittedEntries();
2244
2245 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462246 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162247}
2248
[email protected]1a3c3cb2010-12-16 21:03:402249void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512250 if (delegate_)
2251 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402252}
2253
[email protected]952a68e2011-11-17 00:36:102254void TabContents::DocumentAvailableInMainFrame(
2255 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252256 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102257 DocumentAvailableInMainFrame());
2258}
2259
[email protected]25497492010-09-11 15:15:082260void TabContents::DocumentOnLoadCompletedInMainFrame(
2261 RenderViewHost* render_view_host,
2262 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072263 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272264 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322265 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532266 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082267}
2268
[email protected]ae5184d62011-10-06 19:25:582269void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152270 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582271 WindowOpenDisposition disposition,
2272 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482273 // Delegate to RequestTransferURL because this is just the generic
2274 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582275 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482276 GlobalRequestID());
2277}
2278
2279void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582280 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482281 WindowOpenDisposition disposition,
2282 int64 source_frame_id,
2283 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202284 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582285 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582286 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352287 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322288 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2289 // generated suggestions).
2290 //
[email protected]e0112912011-02-02 22:54:352291 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162292 // want web sites to see a referrer of "chrome://blah" (and some
2293 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322294 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432295 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222296 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482297 false /* is_renderer_initiated */);
2298 params.transferred_global_request_id = old_request_id;
2299 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222300 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322301 } else {
[email protected]6bf6a6b52012-02-03 15:41:432302 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482303 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2304 params.transferred_global_request_id = old_request_id;
2305 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582306 }
2307 if (new_contents) {
2308 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252309 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582310 DidOpenRequestedURL(new_contents,
2311 url,
2312 referrer,
2313 disposition,
2314 transition_type,
2315 source_frame_id));
[email protected]420ae012009-04-24 05:16:322316 }
2317}
2318
[email protected]420ae012009-04-24 05:16:322319void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342320 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412321 const string16& message,
2322 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322323 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472324 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322325 IPC::Message* reply_msg,
2326 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072327 // Suppress JavaScript dialogs when requested. Also suppress messages when
2328 // showing an interstitial as it's shown over the previous page and we don't
2329 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502330 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582331 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272332 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072333 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522334 delegate_->ShouldSuppressDialogs() ||
2335 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322336
2337 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432338 std::string accept_lang = content::GetContentClient()->browser()->
2339 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552340 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522341 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432342 this,
2343 frame_url.GetOrigin(),
2344 accept_lang,
2345 javascript_message_type,
2346 message,
[email protected]51da7e32012-01-30 19:24:522347 default_prompt,
2348 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432349 reply_msg),
[email protected]51da7e32012-01-30 19:24:522350 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322351 }
[email protected]3ab9cb82011-06-03 18:02:072352
2353 if (suppress_this_message) {
2354 // If we are suppressing messages, just reply as if the user immediately
2355 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342356 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072357 }
2358
2359 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322360}
2361
[email protected]fedec012012-01-28 03:09:342362void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412363 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322364 bool is_reload,
[email protected]420ae012009-04-24 05:16:322365 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582366 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512367 if (delegate_)
2368 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072369
2370 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582371 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072372 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522373 delegate_->ShouldSuppressDialogs() ||
2374 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152375 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342376 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582377 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502378 return;
2379 }
[email protected]3ab9cb82011-06-03 18:02:072380
[email protected]7ab1e7d62009-10-14 23:32:012381 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552382 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522383 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322384 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522385 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2386 reply_msg));
[email protected]420ae012009-04-24 05:16:322387}
2388
[email protected]420ae012009-04-24 05:16:322389WebPreferences TabContents::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332390 // We want to base the page config off of the real URL, rather than the
2391 // display URL.
2392 GURL url = controller_.GetActiveEntry()
2393 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2394 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322395}
2396
[email protected]7d472472011-01-22 01:30:252397void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272398 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252399 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222400
[email protected]ea114722012-03-12 01:11:252401 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172402 if (rdh) // NULL in unittests.
2403 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252404}
2405
[email protected]fa1cf0b82010-01-15 21:49:442406void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442407 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252408 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442409}
2410
[email protected]420ae012009-04-24 05:16:322411void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2412 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152413 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522414 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152415 return;
2416
[email protected]9f76c1e2012-03-05 15:15:582417 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2418
[email protected]e5fc1632011-08-08 07:51:532419 // Ignore renderer unresponsive event if debugger is attached to the tab
2420 // since the event may be a result of the renderer sitting on a breakpoint.
2421 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442422 DevToolsAgentHost* agent =
2423 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2424 if (agent &&
2425 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532426 return;
2427
[email protected]420ae012009-04-24 05:16:322428 if (is_during_unload) {
2429 // Hang occurred while firing the beforeunload/unload handler.
2430 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582431 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322432
2433 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2434 return;
2435
2436 // If the tab hangs in the beforeunload/unload handler there's really
2437 // nothing we can do to recover. Pretend the unload listeners have
2438 // all fired and close the tab. If the hang is in the beforeunload handler
2439 // then the user will not have the option of cancelling the close.
2440 Close(rvh);
2441 return;
2442 }
2443
[email protected]9f76c1e2012-03-05 15:15:582444 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472445 return;
2446
[email protected]6934a702011-12-20 00:04:512447 if (delegate_)
2448 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322449}
2450
2451void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512452 if (delegate_)
2453 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322454}
2455
2456void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212457 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562458 uint64 upload_position,
2459 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322460 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562461 upload_position_ = upload_position;
2462 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502463 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202464 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302465 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212466 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322467 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462468 if (IsLoading()) {
2469 NotifyNavigationStateChanged(
2470 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2471 }
[email protected]420ae012009-04-24 05:16:322472}
2473
[email protected]7d472472011-01-22 01:30:252474void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512475 if (delegate_)
2476 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252477}
2478
[email protected]420ae012009-04-24 05:16:322479void TabContents::BeforeUnloadFiredFromRenderManager(
2480 bool proceed,
2481 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512482 if (delegate_)
2483 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322484}
2485
[email protected]3a3d47472010-07-15 21:03:542486void TabContents::DidStartLoadingFromRenderManager(
2487 RenderViewHost* render_view_host) {
2488 DidStartLoading();
2489}
2490
2491void TabContents::RenderViewGoneFromRenderManager(
2492 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232493 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2494 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542495}
2496
[email protected]420ae012009-04-24 05:16:322497void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102498 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262499 gfx::Size size = view_->GetContainerSize();
2500 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2501 // here during container initialization and normal window size will be set
2502 // later. In case of tab duplication this resizing to 0x0 prevents setting
2503 // normal size later so just ignore it.
2504 if (!size.IsEmpty())
2505 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322506}
2507
[email protected]3a3d47472010-07-15 21:03:542508void TabContents::NotifySwappedFromRenderManager() {
2509 NotifySwapped();
2510}
2511
[email protected]d202a7c2012-01-04 07:53:472512NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202513 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542514}
2515
[email protected]d2353452012-01-19 19:53:562516WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2517 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322518}
2519
[email protected]10f417c52011-12-28 21:04:232520NavigationEntry*
2521 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322522 return controller_.GetLastCommittedEntry();
2523}
2524
2525bool TabContents::CreateRenderViewForRenderManager(
2526 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442527 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322528 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522529
[email protected]420ae012009-04-24 05:16:322530 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442531 if (rwh_view)
2532 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322533
[email protected]74ce1ad2011-12-16 21:51:462534 // Make sure we use the correct starting page_id in the new RenderView.
2535 UpdateMaxPageIDIfNecessary(render_view_host);
2536 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582537 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462538
[email protected]9f76c1e2012-03-05 15:15:582539 if (!static_cast<RenderViewHostImpl*>(
2540 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522541 return false;
2542
[email protected]e60c0232011-11-11 19:56:352543#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502544 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2545 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442546 if (rwh_view) {
2547 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2548 render_widget_host->WasResized();
2549 }
[email protected]f8233cc2011-05-31 20:24:502550#endif
2551
[email protected]420ae012009-04-24 05:16:322552 return true;
2553}
2554
[email protected]fedec012012-01-28 03:09:342555void TabContents::OnDialogClosed(RenderViewHost* rvh,
2556 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072557 bool success,
2558 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542559 if (is_showing_before_unload_dialog_ && !success) {
2560 // If a beforeunload dialog is canceled, we need to stop the throbber from
2561 // spinning, since we forced it to start spinning in Navigate.
2562 DidStopLoading();
2563
2564 tab_close_start_time_ = base::TimeTicks();
2565 }
2566 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582567 static_cast<RenderViewHostImpl*>(
2568 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542569}
2570
[email protected]be1f56ab2011-12-22 06:55:312571void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122572 encoding_ = content::GetContentClient()->browser()->
2573 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102574}
[email protected]f45d2a72010-03-08 23:28:352575
[email protected]e30d68d2012-02-09 00:06:262576void TabContents::SaveURL(const GURL& url,
2577 const GURL& referrer,
2578 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142579 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2580 if (!dlm)
2581 return;
2582 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262583 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142584 const NavigationEntry* entry = controller_.GetActiveEntry();
2585 if (entry)
2586 post_id = entry->GetPostID();
2587 }
[email protected]29a5ffc82012-03-13 19:35:582588 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142589 save_info.prompt_for_save_location = true;
2590 dlm->DownloadUrl(url,
2591 referrer,
2592 "",
2593 true, // prefer_cache
2594 post_id,
2595 save_info,
[email protected]89e6aa72012-03-12 22:51:332596 this,
2597 DownloadManager::OnStartedCallback());
[email protected]27678b2a2012-02-04 22:09:142598}
2599
[email protected]33f74972010-12-08 16:40:362600void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212601 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442602 // Can be NULL during tests.
2603 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212604 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362605}
[email protected]9f76c1e2012-03-05 15:15:582606
2607RenderViewHostImpl* TabContents::GetRenderViewHostImpl() {
2608 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2609}