blob: bf9f813d53e8d60967e8b9b3aafc20ea317449e2 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]0dd3a0ab2011-02-18 08:17:445#include "content/browser/tab_contents/tab_contents.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]b9535422012-02-09 01:47:5917#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4418#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]8bd9e562011-08-16 23:55:4619#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1220#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1621#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3222#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5423#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0524#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0025#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0126#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3027#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3228#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]ea114722012-03-12 01:11:2529#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]48227592012-03-19 13:13:4430#include "content/public/browser/resource_request_details.h"
[email protected]b6583592012-01-25 19:52:3331#include "content/browser/site_instance_impl.h"
[email protected]cadaec52012-02-08 21:53:1332#include "content/browser/tab_contents/interstitial_page_impl.h"
[email protected]10f417c52011-12-28 21:04:2333#include "content/browser/tab_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5634#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2435#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5136#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0237#include "content/common/view_messages.h"
[email protected]5626b0892012-02-20 14:46:5838#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1139#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2040#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4441#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4442#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1743#include "content/public/browser/download_manager.h"
[email protected]d9083482012-01-06 00:38:4644#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1545#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2746#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0047#include "content/public/browser/navigation_details.h"
[email protected]54087fe2011-10-28 22:02:4848#include "content/public/browser/notification_service.h"
[email protected]7f6f44c2011-12-14 13:23:3849#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4250#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2551#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1052#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5053#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2154#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4855#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1856#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5457#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0358#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1659#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2960#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5461#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3462#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3763#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]ce9751942011-09-21 01:57:2464#include "webkit/glue/web_intent_data.h"
[email protected]3c733bde2010-12-21 19:56:3165#include "webkit/glue/webpreferences.h"
66
[email protected]38b098f2012-03-14 21:11:5767#if defined(OS_WIN) && !defined(USE_AURA)
68#include "content/browser/tab_contents/tab_contents_view_win.h"
69#elif defined(TOOLKIT_GTK)
70#include "content/browser/tab_contents/tab_contents_view_gtk.h"
71#elif defined(OS_MACOSX)
72#include "content/browser/tab_contents/web_contents_view_mac.h"
[email protected]b9b751f22011-03-25 14:04:1273#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5774#elif defined(OS_ANDROID)
75#include "content/browser/tab_contents/web_contents_view_android.h"
76#endif
[email protected]3e45ba92009-02-20 21:09:0077
[email protected]420ae012009-04-24 05:16:3278// Cross-Site Navigations
79//
80// If a TabContents is told to navigate to a different web site (as determined
81// by SiteInstance), it will replace its current RenderViewHost with a new
82// RenderViewHost dedicated to the new SiteInstance. This works as follows:
83//
84// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4685// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3286// - The pending RVH is "suspended," so that no navigation messages are sent to
87// its renderer until the onbeforeunload JavaScript handler has a chance to
88// run in the current RVH.
89// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
90// that it has a pending cross-site request. ResourceDispatcherHost will
91// check for this when the response arrives.
92// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4693// cancel all the pending logic. Otherwise we allow the pending RVH to send
94// the navigation request to its renderer.
95// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
96// main resource load on the pending RVH. It checks CrossSiteRequestManager
97// to see that it is a cross-site request, and installs a
98// CrossSiteResourceHandler.
99// - When RDH receives a response, the BufferedResourceHandler determines
100// whether it is a download. If so, it sends a message to the new renderer
101// causing it to cancel the request, and the download proceeds. For now, the
102// pending RVH remains until the next DidNavigate event for this TabContents.
103// This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32104// - After RDH receives a response and determines that it is safe and not a
105// download, it pauses the response to first run the old page's onunload
106// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]992db4c2011-05-12 15:37:15107// method of TabContents on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32108// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15109// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32110// the ResourceDispatcherHost, who unpauses the response. Data is then sent
111// to the pending RVH.
112// - The pending renderer sends a FrameNavigate message that invokes the
113// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46114// pending RVH.
[email protected]992db4c2011-05-12 15:37:15115// - The previous renderer is kept swapped out in RenderViewHostManager in case
116// the user goes back. The process only stays live if another tab is using
117// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32118
[email protected]0e12d7d2011-12-01 16:21:44119using content::DevToolsAgentHost;
120using content::DevToolsAgentHostRegistry;
121using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17122using content::DownloadItem;
123using content::DownloadManager;
[email protected]e5d549d2011-12-28 01:29:20124using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56125using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13126using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27127using content::LoadNotificationDetails;
[email protected]c5eed492012-01-04 17:07:50128using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23129using content::NavigationEntry;
130using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20131using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11132using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57133using content::RenderViewHostDelegate;
[email protected]09d31d52012-03-11 22:30:27134using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11135using content::RenderWidgetHost;
[email protected]5626b0892012-02-20 14:46:58136using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04137using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25138using content::ResourceDispatcherHostImpl;
[email protected]adbfb8df2012-02-24 01:19:43139using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33140using content::SiteInstance;
[email protected]d583e3f22011-12-27 21:38:17141using content::SSLStatus;
[email protected]7f6f44c2011-12-14 13:23:38142using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09143using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25144using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56145using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22146using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50147using content::WebUIControllerFactory;
[email protected]0e12d7d2011-12-01 16:21:44148
[email protected]420ae012009-04-24 05:16:32149namespace {
150
151// Amount of time we wait between when a key event is received and the renderer
152// is queried for its state and pushed to the NavigationEntry.
153const int kQueryStateDelay = 5000;
154
[email protected]6ebdc9b2010-09-27 16:55:57155const int kSyncWaitDelay = 40;
156
[email protected]82114f52012-03-20 22:53:41157const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05158
[email protected]420ae012009-04-24 05:16:32159#if defined(OS_WIN)
160
161BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
162 // Note: erase is required to properly paint some widgets borders. This can
163 // be seen with textfields.
164 InvalidateRect(hwnd, NULL, TRUE);
165 return TRUE;
166}
167#endif
168
[email protected]2c5569662011-03-22 20:45:02169ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23170 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50171 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16172 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47173 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02174 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47175 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02176 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47177 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16178 break; // Fall through to rest of function.
179 }
[email protected]5e369672009-11-03 23:48:30180
[email protected]59246c572012-02-10 13:32:13181 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
182 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23183 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13184 browser_context->DidLastSessionExitCleanly()) {
185 if (entry.GetHasPostData())
186 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02187 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13188 }
[email protected]5e369672009-11-03 23:48:30189
[email protected]2c5569662011-03-22 20:45:02190 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30191}
192
[email protected]10f417c52011-12-28 21:04:23193void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47194 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42195 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50196 NavigationController::ReloadType reload_type,
[email protected]1ccb3568d2010-02-19 10:51:16197 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51198 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54199 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55200 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
201 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51202 params->url = entry.GetURL();
203 params->referrer = entry.GetReferrer();
204 params->transition = entry.GetTransitionType();
205 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00206 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55207 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34208 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47209 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48210 params->transferred_request_child_id =
211 entry.transferred_global_request_id().child_id;
212 params->transferred_request_request_id =
213 entry.transferred_global_request_id().request_id;
[email protected]6c6b02d2011-09-02 03:36:47214
215 if (delegate)
216 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34217}
218
[email protected]420ae012009-04-24 05:16:32219} // namespace
220
[email protected]a81343d232011-12-27 07:39:20221namespace content {
222
223WebContents* WebContents::Create(
224 BrowserContext* browser_context,
225 SiteInstance* site_instance,
226 int routing_id,
227 const WebContents* base_tab_contents,
228 SessionStorageNamespace* session_storage_namespace) {
[email protected]adbfb8df2012-02-24 01:19:43229 return new TabContents(
230 browser_context,
231 site_instance,
232 routing_id,
233 static_cast<const TabContents*>(base_tab_contents),
234 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20235}
236}
[email protected]f4f50ef2011-01-21 19:01:19237
238// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32239
[email protected]3d7474ff2011-07-27 17:47:37240TabContents::TabContents(content::BrowserContext* browser_context,
[email protected]420ae012009-04-24 05:16:32241 SiteInstance* site_instance,
242 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07243 const TabContents* base_tab_contents,
[email protected]adbfb8df2012-02-24 01:19:43244 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42245 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07246 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37247 this, browser_context, session_storage_namespace)),
[email protected]d82ed61e2009-06-16 02:46:22248 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]d5f942ba2008-09-26 19:30:34249 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23250 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
251 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34252 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21253 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56254 upload_size_(0),
255 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47256 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57257 capturing_contents_(false),
258 is_being_destroyed_(false),
259 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55260 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57261#if defined(OS_WIN)
262 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
263#endif
[email protected]7ab1e7d62009-10-14 23:32:01264 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56265 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38266 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25267 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01268 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25269 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01270 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00271 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43272 content_restrictions_(0),
[email protected]a0358d72012-03-09 14:06:50273 view_type_(content::VIEW_TYPE_TAB_CONTENTS),
[email protected]da8543762012-03-20 08:52:20274 has_opener_(false),
275 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37276 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32277
[email protected]38b098f2012-03-14 21:11:57278 view_.reset(content::GetContentClient()->browser()->
279 OverrideCreateWebContentsView(this));
280 if (!view_.get()) {
281 content::WebContentsViewDelegate* delegate =
282 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
283 this);
284#if defined(OS_WIN) && !defined(USE_AURA)
285 view_.reset(new TabContentsViewWin(this, delegate));
286#elif defined(TOOLKIT_GTK)
287 view_.reset(new content::TabContentsViewGtk(this, delegate));
288#elif defined(OS_MACOSX)
289 view_.reset(web_contents_view_mac::CreateWebContentsView(this, delegate));
290#elif defined(OS_ANDROID)
291 view_.reset(new WebContentsViewAndroid(this));
292#endif
[email protected]dbd407f2012-03-14 21:30:37293 (void)delegate;
[email protected]38b098f2012-03-14 21:11:57294 }
295 CHECK(view_.get());
296
[email protected]34ac70502009-09-25 17:07:23297 // We have the initial size of the view be based on the size of the passed in
298 // tab contents (normally a tab from the same window).
299 view_->CreateView(base_tab_contents ?
[email protected]d487beefe2011-12-21 05:41:21300 base_tab_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00301
302#if defined(ENABLE_JAVA_BRIDGE)
303 java_bridge_dispatcher_host_manager_.reset(
304 new JavaBridgeDispatcherHostManager(this));
305#endif
[email protected]332af7732009-03-11 13:21:35306}
initial.commit09911bf2008-07-26 23:55:29307
308TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32309 is_being_destroyed_ = true;
310
[email protected]3ab9cb82011-06-03 18:02:07311 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55312 if (dialog_creator_)
313 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07314
[email protected]da8543762012-03-20 08:52:20315 if (color_chooser_)
316 color_chooser_->End();
317
[email protected]420ae012009-04-24 05:16:32318 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32319
[email protected]420ae012009-04-24 05:16:32320 // Notify any observer that have a reference on this tab contents.
[email protected]ad50def52011-10-19 23:17:07321 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09322 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
323 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07324 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32325
326 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07327#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32328 // If we still have a window handle, destroy it. GetNativeView can return
329 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42330 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52331 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58332 if (host && host->GetView())
333 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42334 }
[email protected]420ae012009-04-24 05:16:32335#endif
[email protected]7ab1e7d62009-10-14 23:32:01336
337 // OnCloseStarted isn't called in unit tests.
338 if (!tab_close_start_time_.is_null()) {
339 UMA_HISTOGRAM_TIMES("Tab.Close",
340 base::TimeTicks::Now() - tab_close_start_time_);
341 }
[email protected]b5a1d11c2011-02-17 03:09:42342
[email protected]d8c660432011-12-22 20:51:25343 FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08344
[email protected]6934a702011-12-20 00:04:51345 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42346}
347
[email protected]64d69de42012-02-06 00:19:54348WebPreferences TabContents::GetWebkitPrefs(RenderViewHost* rvh,
349 const GURL& url) {
350 WebPreferences prefs;
351
352 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
353
354 prefs.developer_extras_enabled = true;
355 prefs.javascript_enabled =
356 !command_line.HasSwitch(switches::kDisableJavaScript);
357 prefs.web_security_enabled =
358 !command_line.HasSwitch(switches::kDisableWebSecurity);
359 prefs.plugins_enabled =
360 !command_line.HasSwitch(switches::kDisablePlugins);
361 prefs.java_enabled =
362 !command_line.HasSwitch(switches::kDisableJava);
363
364 prefs.uses_page_cache =
365 command_line.HasSwitch(switches::kEnableFastback);
366 prefs.remote_fonts_enabled =
367 !command_line.HasSwitch(switches::kDisableRemoteFonts);
368 prefs.xss_auditor_enabled =
369 !command_line.HasSwitch(switches::kDisableXSSAuditor);
370 prefs.application_cache_enabled =
371 !command_line.HasSwitch(switches::kDisableApplicationCache);
372
373 prefs.local_storage_enabled =
374 !command_line.HasSwitch(switches::kDisableLocalStorage);
375 prefs.databases_enabled =
376 !command_line.HasSwitch(switches::kDisableDatabases);
377 prefs.webaudio_enabled =
378 !command_line.HasSwitch(switches::kDisableWebAudio);
379
380 prefs.experimental_webgl_enabled =
381 GpuProcessHost::gpu_enabled() &&
382 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
383 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
384
385 prefs.gl_multisampling_enabled =
386 !command_line.HasSwitch(switches::kDisableGLMultisampling);
387 prefs.privileged_webgl_extensions_enabled =
388 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
389 prefs.site_specific_quirks_enabled =
390 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
391 prefs.allow_file_access_from_file_urls =
392 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
393 prefs.show_composited_layer_borders =
394 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
395 prefs.show_composited_layer_tree =
396 command_line.HasSwitch(switches::kShowCompositedLayerTree);
397 prefs.show_fps_counter =
398 command_line.HasSwitch(switches::kShowFPSCounter);
399 prefs.accelerated_compositing_enabled =
400 GpuProcessHost::gpu_enabled() &&
401 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
402 prefs.threaded_compositing_enabled =
403 command_line.HasSwitch(switches::kEnableThreadedCompositing);
404 prefs.force_compositing_mode =
405 command_line.HasSwitch(switches::kForceCompositingMode);
406 prefs.fixed_position_compositing_enabled =
407 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
408 prefs.accelerated_2d_canvas_enabled =
409 GpuProcessHost::gpu_enabled() &&
410 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58411 prefs.deferred_2d_canvas_enabled =
412 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36413 prefs.threaded_animation_enabled =
414 command_line.HasSwitch(switches::kEnableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54415 prefs.accelerated_painting_enabled =
416 GpuProcessHost::gpu_enabled() &&
417 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
418 prefs.accelerated_filters_enabled =
419 GpuProcessHost::gpu_enabled() &&
420 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
421 prefs.accelerated_layers_enabled =
422 prefs.accelerated_animation_enabled =
423 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
424 prefs.composite_to_texture_enabled =
425 command_line.HasSwitch(switches::kEnableCompositeToTexture);
426 prefs.accelerated_plugins_enabled =
427 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
428 prefs.accelerated_video_enabled =
429 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
430 prefs.partial_swap_enabled =
431 command_line.HasSwitch(switches::kEnablePartialSwap);
432 prefs.interactive_form_validation_enabled =
433 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
434 prefs.fullscreen_enabled =
435 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16436 prefs.css_regions_enabled =
437 command_line.HasSwitch(switches::kEnableCssRegions);
438
[email protected]64d69de42012-02-06 00:19:54439
440#if defined(OS_MACOSX)
441 bool default_enable_scroll_animator = true;
442#else
443 // On CrOS, the launcher always passes in the --enable flag.
444 bool default_enable_scroll_animator = false;
445#endif
446 prefs.enable_scroll_animator = default_enable_scroll_animator;
447 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
448 prefs.enable_scroll_animator = true;
449 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
450 prefs.enable_scroll_animator = false;
451
452 prefs.visual_word_movement_enabled =
453 command_line.HasSwitch(switches::kEnableVisualWordMovement);
454 prefs.per_tile_painting_enabled =
455 command_line.HasSwitch(switches::kEnablePerTilePainting);
456
457 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32458 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54459 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11460 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
461 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54462 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11463 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54464 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11465 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54466 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11467 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54468 prefs.gl_multisampling_enabled = false;
469
470 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45471 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32472 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54473 prefs.accelerated_video_enabled = false;
474 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45475 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54476 }
477 }
478
[email protected]b9535422012-02-09 01:47:59479 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58480 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54481 prefs.loads_images_automatically = true;
482 prefs.javascript_enabled = true;
483 }
484
485 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
486
487 // Force accelerated compositing and 2d canvas off for chrome:, about: and
488 // chrome-devtools: pages (unless it's specifically allowed).
489 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54490 url.SchemeIs(chrome::kChromeUIScheme) ||
491 (url.SchemeIs(chrome::kAboutScheme) &&
492 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25493 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54494 prefs.accelerated_compositing_enabled = false;
495 prefs.accelerated_2d_canvas_enabled = false;
496 }
497
[email protected]43d9d782012-03-01 15:40:09498 int default_device_scale_factor;
499 base::StringToInt(command_line.GetSwitchValueASCII(
500 switches::kDefaultDeviceScaleFactor),
501 &default_device_scale_factor);
502
503 prefs.default_device_scale_factor = default_device_scale_factor;
504
[email protected]2e21fe292012-03-02 22:52:32505 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54506
507 return prefs;
508}
509
[email protected]d202a7c2012-01-04 07:53:47510NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20511 return controller_;
512}
513
[email protected]765187182012-01-11 23:59:28514RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
515 return &render_manager_;
516}
517
[email protected]724159a2010-12-30 01:11:18518bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56519 if (GetWebUI() &&
520 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17521 return true;
[email protected]d2353452012-01-19 19:53:56522 }
[email protected]f82d57b52011-04-27 19:13:17523
[email protected]d8c660432011-12-22 20:51:25524 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
525 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10526 while ((observer = it.GetNext()) != NULL)
527 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53528 return true;
[email protected]403415a2011-01-10 18:57:53529
[email protected]724159a2010-12-30 01:11:18530 bool handled = true;
531 bool message_is_ok = true;
532 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58533 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
534 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24535 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
536 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18537 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
538 OnDidStartProvisionalLoadForFrame)
539 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
540 OnDidRedirectProvisionalLoad)
541 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
542 OnDidFailProvisionalLoadWithError)
543 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
544 OnDidLoadResourceFromMemoryCache)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
546 OnDidDisplayInsecureContent)
547 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
548 OnDidRunInsecureContent)
549 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
550 OnDocumentLoadedInFrame)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17552 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
553 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25554 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26555 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59556 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21557 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20558 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
559 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
560 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16561 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45562 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10563 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20564 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
565 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
566 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
567 OnSetSelectedColorInColorChooser)
[email protected]724159a2010-12-30 01:11:18568 IPC_MESSAGE_UNHANDLED(handled = false)
569 IPC_END_MESSAGE_MAP_EX()
570
571 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38572 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18573 GetRenderProcessHost()->ReceivedBadMessage();
574 }
575
576 return handled;
577}
578
[email protected]6c2e472f2011-08-24 23:26:18579void TabContents::RunFileChooser(
580 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23581 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51582 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18583}
584
[email protected]c5eed492012-01-04 17:07:50585NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56586 return controller_;
587}
588
[email protected]c5eed492012-01-04 17:07:50589const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56590 return controller_;
591}
592
[email protected]627e0512011-12-21 22:55:30593content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55594 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30595}
596
[email protected]f5fa20e2011-12-21 22:35:56597void TabContents::SetViewType(content::ViewType type) {
598 view_type_ = type;
599}
600
[email protected]ea049a02011-12-25 21:37:09601content::ViewType TabContents::GetViewType() const {
602 return view_type_;
603}
604
[email protected]be1f56ab2011-12-22 06:55:31605const GURL& TabContents::GetURL() const {
606 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23607 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51608 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31609}
610
611
612const base::PropertyBag* TabContents::GetPropertyBag() const {
613 return &property_bag_;
614}
615
616base::PropertyBag* TabContents::GetPropertyBag() {
617 return &property_bag_;
618}
619
620content::WebContentsDelegate* TabContents::GetDelegate() {
621 return delegate_;
622}
623
624void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
625 // TODO(cbentzel): remove this debugging code?
626 if (delegate == delegate_)
627 return;
628 if (delegate_)
629 delegate_->Detach(this);
630 delegate_ = delegate;
631 if (delegate_)
632 delegate_->Attach(this);
633}
634
[email protected]f3b1a082011-11-18 00:34:30635content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41636 RenderViewHostImpl* host = render_manager_.current_host();
637 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16638}
639
[email protected]be1f56ab2011-12-22 06:55:31640RenderViewHost* TabContents::GetRenderViewHost() const {
641 return render_manager_.current_host();
642}
643
644RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
645 return render_manager_.GetRenderWidgetHostView();
646}
647
[email protected]8643e6d2012-01-18 20:26:10648content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31649 return view_.get();
650}
651
[email protected]01ec4ec2012-01-18 04:13:47652content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50653 WebUIControllerFactory* factory =
654 content::GetContentClient()->browser()->GetWebUIControllerFactory();
655 if (!factory)
656 return NULL;
[email protected]d2353452012-01-19 19:53:56657 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22658 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50659 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22660 if (controller) {
661 web_ui->SetController(controller);
662 return web_ui;
663 }
664
665 delete web_ui;
666 return NULL;
667}
668
[email protected]01ec4ec2012-01-18 04:13:47669content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31670 return render_manager_.web_ui() ? render_manager_.web_ui()
671 : render_manager_.pending_web_ui();
672}
673
[email protected]01ec4ec2012-01-18 04:13:47674content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31675 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34676}
677
[email protected]96d185d2009-04-24 03:28:54678const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55679 // Transient entries take precedence. They are used for interstitial pages
680 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23681 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08682 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20683 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30684 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23685 if (entry) {
[email protected]b5cca982011-05-26 04:42:08686 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23687 }
[email protected]7ade2732011-02-10 00:13:58688 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
689 render_manager_.pending_web_ui() : render_manager_.web_ui();
690 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54691 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55692 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54693 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35694 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22695 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54696 if (!title.empty())
697 return title;
698 }
699 }
700
701 // We use the title for the last committed entry rather than a pending
702 // navigation entry. For example, when the user types in a URL, we want to
703 // keep the old page's title until the new load has committed and we get a new
704 // title.
[email protected]96d185d2009-04-24 03:28:54705 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23706 if (entry) {
[email protected]b5cca982011-05-26 04:42:08707 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23708 }
[email protected]987fc3a2011-05-26 14:18:09709
710 // |page_title_when_no_navigation_entry_| is finally used
711 // if no title cannot be retrieved.
712 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54713}
714
[email protected]d5f942ba2008-09-26 19:30:34715int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46716 return GetMaxPageIDForSiteInstance(GetSiteInstance());
717}
718
719int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33720 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
721 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46722
[email protected]b6583592012-01-25 19:52:33723 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34724}
725
726void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46727 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
728}
729
[email protected]b6583592012-01-25 19:52:33730void TabContents::UpdateMaxPageIDForSiteInstance(
731 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46732 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33733 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34734}
735
[email protected]91854cd2012-01-10 19:43:57736void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
737 max_page_ids_ = tab_contents->max_page_ids_;
738}
739
[email protected]96d185d2009-04-24 03:28:54740SiteInstance* TabContents::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58741 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54742}
743
[email protected]77362eb2011-08-01 17:18:38744SiteInstance* TabContents::GetPendingSiteInstance() const {
745 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
746 render_manager_.pending_render_view_host() :
747 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58748 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38749}
750
[email protected]be1f56ab2011-12-22 06:55:31751bool TabContents::IsLoading() const {
752 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49753}
754
[email protected]be1f56ab2011-12-22 06:55:31755bool TabContents::IsWaitingForResponse() const {
756 return waiting_for_response_;
757}
758
759const net::LoadStateWithParam& TabContents::GetLoadState() const {
760 return load_state_;
761}
762
763const string16& TabContents::GetLoadStateHost() const {
764 return load_state_host_;
765}
766
767uint64 TabContents::GetUploadSize() const {
768 return upload_size_;
769}
770
771uint64 TabContents::GetUploadPosition() const {
772 return upload_position_;
773}
774
775const std::string& TabContents::GetEncoding() const {
776 return encoding_;
777}
778
779bool TabContents::DisplayedInsecureContent() const {
780 return displayed_insecure_content_;
781}
782
783void TabContents::SetCapturingContents(bool cap) {
784 capturing_contents_ = cap;
785}
786
787bool TabContents::IsCrashed() const {
788 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
789 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
790 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49791}
792
[email protected]443b80e2010-12-14 00:42:23793void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
794 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34795 return;
796
[email protected]443b80e2010-12-14 00:42:23797 crashed_status_ = status;
798 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46799 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34800}
801
[email protected]be1f56ab2011-12-22 06:55:31802base::TerminationStatus TabContents::GetCrashedStatus() const {
803 return crashed_status_;
804}
805
806bool TabContents::IsBeingDestroyed() const {
807 return is_being_destroyed_;
808}
809
[email protected]d5f942ba2008-09-26 19:30:34810void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
811 if (delegate_)
812 delegate_->NavigationStateChanged(this, changed_flags);
813}
814
[email protected]96d185d2009-04-24 03:28:54815void TabContents::DidBecomeSelected() {
816 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04817 RenderWidgetHostViewPort* rwhv =
818 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16819 if (rwhv) {
820 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43821#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16822 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43823#endif
824 }
[email protected]96d185d2009-04-24 03:28:54825
[email protected]5ac20162010-11-24 23:33:11826 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38827
[email protected]d8c660432011-12-22 20:51:25828 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59829
830 // The resize rect might have changed while this was inactive -- send the new
831 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58832 RenderViewHostImpl* rvh =
833 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59834 if (rvh) {
835 rvh->ResizeRectChanged(GetRootWindowResizerRect());
836 }
[email protected]96d185d2009-04-24 03:28:54837}
838
[email protected]be1f56ab2011-12-22 06:55:31839
840base::TimeTicks TabContents::GetLastSelectedTime() const {
841 return last_selected_time_;
842}
843
[email protected]96d185d2009-04-24 03:28:54844void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31845 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52846 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
847 // open a tab in then background, then closes the tab before selecting it.
848 // This is because closing the tab calls TabContents::Destroy(), which
849 // removes the |GetRenderViewHost()|; then when we actually destroy the
850 // window, OnWindowPosChanged() notices and calls HideContents() (which
851 // calls us).
[email protected]c30585c2012-02-16 15:02:04852 RenderWidgetHostViewPort* rwhv =
853 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16854 if (rwhv)
855 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54856 }
857
[email protected]ad50def52011-10-19 23:17:07858 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09859 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
860 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07861 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54862}
863
[email protected]be1f56ab2011-12-22 06:55:31864void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04865 RenderWidgetHostViewPort* rwhv =
866 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31867 if (rwhv)
868 rwhv->DidBecomeSelected();
869}
870
871void TabContents::HideContents() {
872 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
873 // our superclass HideContents(), because some callers want to be very picky
874 // about the order in which these get called. In addition to making the code
875 // here practically impossible to understand, this also means we end up
876 // calling TabContents::WasHidden() twice if callers call both versions of
877 // HideContents() on a TabContents.
878 WasHidden();
879}
880
881bool TabContents::NeedToFireBeforeUnload() {
882 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27883 return WillNotifyDisconnection() &&
884 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58885 !static_cast<RenderViewHostImpl*>(
886 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31887}
888
[email protected]0bfbf882011-12-22 18:19:27889void TabContents::Stop() {
890 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25891 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27892}
893
[email protected]d9083482012-01-06 00:38:46894WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27895 // We create a new SiteInstance so that the new tab won't share processes
896 // with the old one. This can be changed in the future if we need it to share
897 // processes for some reason.
898 TabContents* tc = new TabContents(
899 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33900 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27901 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20902 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27903 return tc;
904}
905
[email protected]2a6bc3e2011-12-28 23:51:33906void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27907 WindowOpenDisposition disposition,
908 const gfx::Rect& initial_pos,
909 bool user_gesture) {
910 if (!delegate_)
911 return;
912
913 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
914 user_gesture);
915}
916
917gfx::NativeView TabContents::GetContentNativeView() const {
918 return view_->GetContentNativeView();
919}
920
921gfx::NativeView TabContents::GetNativeView() const {
922 return view_->GetNativeView();
923}
924
925void TabContents::GetContainerBounds(gfx::Rect* out) const {
926 view_->GetContainerBounds(out);
927}
928
929void TabContents::Focus() {
930 view_->Focus();
931}
932
[email protected]d8c660432011-12-22 20:51:25933void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31934 observers_.AddObserver(observer);
935}
936
[email protected]d8c660432011-12-22 20:51:25937void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31938 observers_.RemoveObserver(observer);
939}
940
[email protected]d5f942ba2008-09-26 19:30:34941void TabContents::Activate() {
942 if (delegate_)
943 delegate_->ActivateContents(this);
944}
945
[email protected]ea42e7782010-08-23 23:58:12946void TabContents::Deactivate() {
947 if (delegate_)
948 delegate_->DeactivateContents(this);
949}
950
[email protected]63954792011-07-11 04:17:48951void TabContents::LostCapture() {
952 if (delegate_)
953 delegate_->LostCapture();
954}
955
956bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
957 bool* is_keyboard_shortcut) {
958 return delegate_ &&
959 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
960}
961
962void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
963 if (delegate_)
964 delegate_->HandleKeyboardEvent(event);
965}
966
[email protected]32ded2212011-11-10 18:51:43967void TabContents::HandleMouseDown() {
968 if (delegate_)
969 delegate_->HandleMouseDown();
970}
971
[email protected]63954792011-07-11 04:17:48972void TabContents::HandleMouseUp() {
973 if (delegate_)
974 delegate_->HandleMouseUp();
975}
976
977void TabContents::HandleMouseActivate() {
978 if (delegate_)
979 delegate_->HandleMouseActivate();
980}
981
[email protected]8a5e0ca2011-08-25 06:30:47982void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
983 if (delegate_)
984 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
985}
986
[email protected]5d5f7af2011-10-01 01:38:12987bool TabContents::IsFullscreenForCurrentTab() const {
988 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
989}
990
[email protected]e9621112011-10-17 05:38:37991void TabContents::RequestToLockMouse() {
992 if (delegate_) {
993 delegate_->RequestToLockMouse(this);
994 } else {
995 GotResponseToLockMouseRequest(false);
996 }
997}
998
999void TabContents::LostMouseLock() {
1000 if (delegate_)
1001 delegate_->LostMouseLock();
1002}
1003
[email protected]0548c5352011-09-07 00:33:331004void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231005 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331006 if (delegate_)
1007 delegate_->UpdatePreferredSize(this, pref_size);
1008}
1009
[email protected]61e2b3cc2012-03-02 16:13:341010void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
1011 if (delegate_)
1012 delegate_->ResizeDueToAutoResize(this, new_size);
1013}
1014
[email protected]32ded2212011-11-10 18:51:431015void TabContents::WebUISend(RenderViewHost* render_view_host,
1016 const GURL& source_url,
1017 const std::string& name,
1018 const base::ListValue& args) {
1019 if (delegate_)
1020 delegate_->WebUISend(this, source_url, name, args);
1021}
1022
[email protected]e5d549d2011-12-28 01:29:201023WebContents* TabContents::OpenURL(const OpenURLParams& params) {
1024 if (!delegate_)
1025 return NULL;
[email protected]00c37fc2011-08-02 00:22:501026
[email protected]e5d549d2011-12-28 01:29:201027 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1028 // Notify observers.
1029 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1030 DidOpenURL(params.url, params.referrer,
1031 params.disposition, params.transition));
1032 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341033}
1034
[email protected]1ccb3568d2010-02-19 10:51:161035bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501036 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251037 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231038 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251039 reload_type);
[email protected]876bc832010-09-07 16:29:541040}
[email protected]96d185d2009-04-24 03:28:541041
[email protected]876bc832010-09-07 16:29:541042bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231043 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501044 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401045 // The renderer will reject IPC messages with URLs longer than
1046 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511047 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401048 return false;
1049
[email protected]9f76c1e2012-03-05 15:15:581050 RenderViewHostImpl* dest_render_view_host =
1051 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401052 if (!dest_render_view_host)
1053 return false; // Unable to create the desired render view host.
1054
[email protected]80a8fad2011-01-29 04:02:381055 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071056 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581057 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501058 WebUIControllerFactory* factory =
1059 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1060 bool is_allowed_in_web_ui_renderer =
1061 factory &&
1062 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431063#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511064 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431065#endif
[email protected]e091df82011-10-11 18:13:211066 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551067 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581068
[email protected]96d185d2009-04-24 03:28:541069 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441070 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521071 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441072 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511073 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541074
1075 // Used for page load time metrics.
1076 current_load_start_ = base::TimeTicks::Now();
1077
1078 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341079 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271080 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471081 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341082 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541083
[email protected]36fc0392011-12-25 03:59:511084 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541085 // HACK!! This code suppresses javascript: URLs from being added to
1086 // session history, which is what we want to do for javascript: URLs that
1087 // do not generate content. What we really need is a message from the
1088 // renderer telling us that a new page was not created. The same message
1089 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511090 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541091 return false;
1092 }
1093
[email protected]3c9e1872010-11-18 16:17:491094 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251095 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041096 observers_,
[email protected]36fc0392011-12-25 03:59:511097 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541098
[email protected]09b29342011-06-24 19:18:481099 if (delegate_)
1100 delegate_->DidNavigateToPendingEntry(this);
1101
[email protected]d5f942ba2008-09-26 19:30:341102 return true;
1103}
1104
[email protected]b6583592012-01-25 19:52:331105void TabContents::SetHistoryLengthAndPrune(
1106 const SiteInstance* site_instance,
1107 int history_length,
1108 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411109 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1110 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191111 if (render_manager_.pending_render_view_host()) {
1112 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141113 return;
[email protected]9e1ad4b2011-08-14 16:49:191114 }
[email protected]9f76c1e2012-03-05 15:15:581115 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191116 if (!rvh) {
1117 NOTREACHED();
1118 return;
1119 }
[email protected]9f76c1e2012-03-05 15:15:581120 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191121 NOTREACHED();
1122 return;
1123 }
[email protected]9f76c1e2012-03-05 15:15:581124 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191125 history_length,
1126 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141127}
1128
[email protected]90daadb42009-06-08 21:27:281129void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271130 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541131 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1132 return;
1133 }
[email protected]9f76c1e2012-03-05 15:15:581134 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541135}
1136
[email protected]0bfbf882011-12-22 18:19:271137bool TabContents::ShowingInterstitialPage() const {
1138 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541139}
1140
[email protected]0bfbf882011-12-22 18:19:271141InterstitialPage* TabContents::GetInterstitialPage() const {
1142 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221143}
1144
[email protected]a53209b2012-01-20 16:48:161145bool TabContents::IsSavable() {
1146 // WebKit creates Document object when MIME type is application/xhtml+xml,
1147 // so we also support this MIME type.
1148 return contents_mime_type_ == "text/html" ||
1149 contents_mime_type_ == "text/xml" ||
1150 contents_mime_type_ == "application/xhtml+xml" ||
1151 contents_mime_type_ == "text/plain" ||
1152 contents_mime_type_ == "text/css" ||
1153 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1154}
1155
[email protected]c7dd2f62011-07-18 15:57:591156void TabContents::OnSavePage() {
1157 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161158 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481159 download_stats::RecordDownloadSource(
1160 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261161 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141162 return;
[email protected]c7dd2f62011-07-18 15:57:591163 }
1164
1165 Stop();
1166
1167 // Create the save package and possibly prompt the user for the name to save
1168 // the page as. The user prompt is an asynchronous operation that runs on
1169 // another thread.
1170 save_package_ = new SavePackage(this);
1171 save_package_->GetSaveInfo();
1172}
1173
1174// Used in automated testing to bypass prompting the user for file names.
1175// Instead, the names and paths are hard coded rather than running them through
1176// file name sanitation and extension / mime checking.
1177bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161178 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591179 // Stop the page from navigating.
1180 Stop();
1181
1182 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1183 return save_package_->Init();
1184}
1185
[email protected]aa4f3972012-03-01 18:12:121186void TabContents::GenerateMHTML(
1187 const FilePath& file,
1188 const base::Callback<void(const FilePath&, int64)>& callback) {
1189 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1190}
1191
[email protected]420ae012009-04-24 05:16:321192bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231193 NavigationEntryImpl* active_entry =
1194 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321195 return (active_entry != NULL &&
1196 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511197 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321198}
1199
[email protected]0bfbf882011-12-22 18:19:271200const std::string& TabContents::GetContentsMimeType() const {
1201 return contents_mime_type_;
1202}
1203
1204bool TabContents::WillNotifyDisconnection() const {
1205 return notify_disconnection_;
1206}
1207
[email protected]b2fe07d12010-02-09 14:38:081208void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311209 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581210 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1211 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161212}
1213
[email protected]b2fe07d12010-02-09 14:38:081214void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311215 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581216 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1217 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161218}
1219
[email protected]0bfbf882011-12-22 18:19:271220content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1221 return &renderer_preferences_;
1222}
1223
1224void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1225 new_tab_start_time_ = time;
1226}
1227
1228base::TimeTicks TabContents::GetNewTabStartTime() const {
1229 return new_tab_start_time_;
1230}
1231
[email protected]7ab1e7d62009-10-14 23:32:011232void TabContents::OnCloseStarted() {
1233 if (tab_close_start_time_.is_null())
1234 tab_close_start_time_ = base::TimeTicks::Now();
1235}
1236
[email protected]46624bf2010-06-09 16:04:191237bool TabContents::ShouldAcceptDragAndDrop() const {
1238#if defined(OS_CHROMEOS)
1239 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1240 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511241 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201242 return false;
1243 return true;
[email protected]46624bf2010-06-09 16:04:191244#else
1245 return true;
1246#endif
1247}
1248
[email protected]7813bd72011-02-05 02:19:341249void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521250 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581251 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511252 if (delegate_)
1253 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341254}
1255
[email protected]0bfbf882011-12-22 18:19:271256void TabContents::SetClosedByUserGesture(bool value) {
1257 closed_by_user_gesture_ = value;
1258}
1259
1260bool TabContents::GetClosedByUserGesture() const {
1261 return closed_by_user_gesture_;
1262}
1263
[email protected]d0b8d092010-10-25 04:05:171264double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051265 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561266 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251267 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171268 return 0;
[email protected]b75b8292010-10-01 07:28:251269
1270 double zoom_level;
1271 if (temporary_zoom_settings_) {
1272 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581273 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251274 } else {
[email protected]2ae88d12011-10-14 09:11:191275 GURL url;
[email protected]10f417c52011-12-28 21:04:231276 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191277 // Since zoom map is updated using rewritten URL, use rewritten URL
1278 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511279 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191280 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251281 }
[email protected]d0b8d092010-10-25 04:05:171282 return zoom_level;
1283}
[email protected]b75b8292010-10-01 07:28:251284
[email protected]d0b8d092010-10-25 04:05:171285int TabContents::GetZoomPercent(bool* enable_increment,
1286 bool* enable_decrement) {
1287 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011288 // Calculate the zoom percent from the factor. Round up to the nearest whole
1289 // number.
[email protected]b75b8292010-10-01 07:28:251290 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011291 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251292 *enable_decrement = percent > minimum_zoom_percent_;
1293 *enable_increment = percent < maximum_zoom_percent_;
1294 return percent;
1295}
1296
[email protected]3c733bde2010-12-21 19:56:311297void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501298 if (!delegate_)
1299 return;
1300
[email protected]10f417c52011-12-28 21:04:231301 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501302 if (!active_entry)
1303 return;
1304
[email protected]36fc0392011-12-25 03:59:511305 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121306}
1307
[email protected]932b7a12011-03-09 12:50:271308void TabContents::ViewFrameSource(const GURL& url,
1309 const std::string& content_state) {
1310 if (!delegate_)
1311 return;
1312
1313 delegate_->ViewSourceForFrame(this, url, content_state);
1314}
1315
[email protected]0bfbf882011-12-22 18:19:271316int TabContents::GetMinimumZoomPercent() const {
1317 return minimum_zoom_percent_;
1318}
1319
1320int TabContents::GetMaximumZoomPercent() const {
1321 return maximum_zoom_percent_;
1322}
1323
[email protected]bcd2815602012-01-14 18:17:231324gfx::Size TabContents::GetPreferredSize() const {
1325 return preferred_size_;
1326}
1327
[email protected]0bfbf882011-12-22 18:19:271328int TabContents::GetContentRestrictions() const {
1329 return content_restrictions_;
1330}
1331
1332WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501333 WebUIControllerFactory* factory =
1334 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1335 if (!factory)
1336 return WebUI::kNoWebUI;
1337 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271338}
1339
[email protected]01ec4ec2012-01-18 04:13:471340content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271341 // When there is a pending navigation entry, we want to use the pending WebUI
1342 // that goes along with it to control the basic flags. For example, we want to
1343 // show the pending URL in the URL bar, so we want the display_url flag to
1344 // be from the pending entry.
1345 //
1346 // The confusion comes because there are multiple possibilities for the
1347 // initial load in a tab as a side effect of the way the RenderViewHostManager
1348 // works.
1349 //
1350 // - For the very first tab the load looks "normal". The new tab Web UI is
1351 // the pending one, and we want it to apply here.
1352 //
1353 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1354 // get switched to the one previously associated with the new tab pages.
1355 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1356 // have a committed Web UI in this case.
1357 //
1358 // This condition handles all of these cases:
1359 //
1360 // - First load in first tab: no committed nav entry + pending nav entry +
1361 // pending dom ui:
1362 // -> Use pending Web UI if any.
1363 //
1364 // - First load in second tab: no committed nav entry + pending nav entry +
1365 // no pending Web UI:
1366 // -> Use the committed Web UI if any.
1367 //
1368 // - Second navigation in any tab: committed nav entry + pending nav entry:
1369 // -> Use pending Web UI if any.
1370 //
1371 // - Normal state with no load: committed nav entry + no pending nav entry:
1372 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251373 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271374 (controller_.GetLastCommittedEntry() ||
1375 render_manager_.pending_web_ui()))
1376 return render_manager_.pending_web_ui();
1377 return render_manager_.web_ui();
1378}
1379
1380bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1381 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581382 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271383}
1384
[email protected]a0358d72012-03-09 14:06:501385bool TabContents::HasOpener() const {
1386 return has_opener_;
1387}
1388
[email protected]da8543762012-03-20 08:52:201389void TabContents::DidChooseColorInColorChooser(int color_chooser_id,
1390 const SkColor& color) {
1391 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1392 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1393}
1394
1395void TabContents::DidEndColorChooser(int color_chooser_id) {
1396 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1397 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1398 if (delegate_)
1399 delegate_->DidEndColorChooser();
1400 color_chooser_ = NULL;
1401}
1402
[email protected]0bfbf882011-12-22 18:19:271403bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471404 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271405 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221406 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231407 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411408 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271409}
1410
1411void TabContents::SetFocusToLocationBar(bool select_all) {
1412 if (delegate_)
1413 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211414}
1415
[email protected]8b5af492011-11-28 21:50:581416void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301417 const string16& type,
1418 const string16& href,
1419 const string16& title,
1420 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511421 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301422 this, action, type, href, title, disposition);
1423}
1424
[email protected]678105012011-12-09 04:01:211425void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301426 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001427 WebIntentsDispatcherImpl* intents_dispatcher =
1428 new WebIntentsDispatcherImpl(this, intent, intent_id);
1429 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301430}
1431
[email protected]724159a2010-12-30 01:11:181432void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1433 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591434 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181435 const GURL& url) {
1436 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1437 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451438 GURL validated_opener_url(opener_url);
[email protected]9f76c1e2012-03-05 15:15:581439 GetRenderViewHostImpl()->FilterURL(
1440 ChildProcessSecurityPolicyImpl::GetInstance(),
1441 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451442 false,
[email protected]9f76c1e2012-03-05 15:15:581443 &validated_url);
[email protected]6b7cd8f2012-03-21 21:02:451444 GetRenderViewHostImpl()->FilterURL(
1445 ChildProcessSecurityPolicyImpl::GetInstance(),
1446 GetRenderProcessHost()->GetID(),
1447 true,
1448 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181449
[email protected]8093a542011-05-13 07:29:321450 RenderViewHost* rvh =
1451 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521452 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101453 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251454 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101455 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321456 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101457
[email protected]724159a2010-12-30 01:11:181458 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591459 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251460 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451461 ProvisionalChangeToMainFrameUrl(validated_url,
1462 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181463 }
1464}
1465
1466void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591467 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181468 const GURL& source_url,
1469 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491470 // TODO(creis): Remove this method and have the pre-rendering code listen to
1471 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1472 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451473 GURL validated_source_url(source_url);
1474 GURL validated_target_url(target_url);
1475 GURL validated_opener_url(opener_url);
1476 GetRenderViewHostImpl()->FilterURL(
1477 ChildProcessSecurityPolicyImpl::GetInstance(),
1478 GetRenderProcessHost()->GetID(),
1479 false,
1480 &validated_source_url);
1481 GetRenderViewHostImpl()->FilterURL(
1482 ChildProcessSecurityPolicyImpl::GetInstance(),
1483 GetRenderProcessHost()->GetID(),
1484 false,
1485 &validated_target_url);
1486 GetRenderViewHostImpl()->FilterURL(
1487 ChildProcessSecurityPolicyImpl::GetInstance(),
1488 GetRenderProcessHost()->GetID(),
1489 true,
1490 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231491 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181492 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251493 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181494 else
1495 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]6b7cd8f2012-03-21 21:02:451496 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181497 return;
[email protected]e7d50892011-01-19 21:47:381498
[email protected]4850a7f2011-03-08 23:36:591499 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251500 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451501 ProvisionalChangeToMainFrameUrl(validated_target_url,
1502 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181503}
1504
1505void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581506 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1507 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1508 << ", error_code: " << params.error_code
1509 << ", error_description: " << params.error_description
1510 << ", is_main_frame: " << params.is_main_frame
1511 << ", showing_repost_interstitial: " <<
1512 params.showing_repost_interstitial
1513 << ", frame_id: " << params.frame_id;
1514 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581515 GetRenderViewHostImpl()->FilterURL(
1516 ChildProcessSecurityPolicyImpl::GetInstance(),
1517 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451518 false,
[email protected]9f76c1e2012-03-05 15:15:581519 &validated_url);
[email protected]724159a2010-12-30 01:11:181520
[email protected]d7b175e2011-10-11 15:31:581521 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181522 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1523 // This means that the interstitial won't be torn down properly, which is
1524 // bad. But if we have an interstitial, go back to another tab type, and
1525 // then load the same interstitial again, we could end up getting the first
1526 // interstitial's "failed" message (as a result of the cancel) when we're on
1527 // the second one.
1528 //
1529 // We can't tell this apart, so we think we're tearing down the current page
1530 // which will cause a crash later one. There is also some code in
1531 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1532 // out because of this problem.
1533 //
1534 // http://code.google.com/p/chromium/issues/detail?id=2855
1535 // Because this will not tear down the interstitial properly, if "back" is
1536 // back to another tab type, the interstitial will still be somewhat alive
1537 // in the previous tab type. If you navigate somewhere that activates the
1538 // tab with the interstitial again, you'll see a flash before the new load
1539 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271540 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181541 LOG(WARNING) << "Discarding message during interstitial.";
1542 return;
1543 }
1544
[email protected]02102f82011-06-13 20:37:021545 // Discard our pending entry if the load canceled (e.g. if we decided to
1546 // download the file instead of load it). We do not verify that the URL
1547 // being canceled matches the pending entry's URL because they will not
1548 // match if a redirect occurred (in which case we do not want to leave a
1549 // stale redirect URL showing). This means that we also cancel the pending
1550 // entry if the user started a new navigation. As a result, the navigation
1551 // controller may not remember that a load is in progress, but the
1552 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251553 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161554 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181555
[email protected]151a63d2011-12-20 22:32:521556 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181557 }
1558
[email protected]d8c660432011-12-22 20:51:251559 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581560 observers_,
1561 DidFailProvisionalLoad(params.frame_id,
1562 params.is_main_frame,
1563 validated_url,
1564 params.error_code,
1565 params.error_description));
[email protected]724159a2010-12-30 01:11:181566}
1567
1568void TabContents::OnDidLoadResourceFromMemoryCache(
1569 const GURL& url,
[email protected]70435962011-08-02 20:13:281570 const std::string& security_info,
1571 const std::string& http_method,
1572 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191573 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181574 cache.Increment();
1575
1576 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081577 int cert_id = 0;
1578 net::CertStatus cert_status = 0;
1579 int security_bits = -1;
1580 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511581 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1582 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301583 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161584 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181585
[email protected]ad50def52011-10-19 23:17:071586 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271587 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501588 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531589 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181590}
1591
1592void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381593 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181594 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201595 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181596}
1597
1598void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021599 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231600 LOG(INFO) << security_origin << " ran insecure content from "
1601 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381602 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411603 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1604 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181605 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411606 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201607 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181608}
1609
1610void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1611 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251612 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101613 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181614}
1615
[email protected]1a55c5be2011-11-29 11:36:311616void TabContents::OnDidFinishLoad(
1617 int64 frame_id,
1618 const GURL& validated_url,
1619 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251620 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311621 DidFinishLoad(frame_id, validated_url, is_main_frame));
1622}
1623
1624void TabContents::OnDidFailLoadWithError(int64 frame_id,
1625 const GURL& validated_url,
1626 bool is_main_frame,
1627 int error_code,
1628 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251629 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311630 DidFailLoad(frame_id, validated_url, is_main_frame,
1631 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181632}
1633
[email protected]c8f73ab2011-01-22 00:05:171634void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271635 content_restrictions_ = restrictions;
1636 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171637}
1638
[email protected]216813952011-05-19 22:21:261639void TabContents::OnGoToEntryAtOffset(int offset) {
1640 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231641 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251642 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261643 if (!entry)
1644 return;
1645 // Note that we don't call NavigationController::GotToOffset() as we don't
1646 // want to create a pending navigation entry (it might end up lingering
1647 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251648 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581649 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511650 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581651 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471652 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571653
1654 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1655 // it in now that we know. This allows us to find the entry when it commits.
1656 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231657 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331658 entry->set_site_instance(
1659 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571660 }
[email protected]216813952011-05-19 22:21:261661 }
1662}
1663
1664void TabContents::OnUpdateZoomLimits(int minimum_percent,
1665 int maximum_percent,
1666 bool remember) {
1667 minimum_zoom_percent_ = minimum_percent;
1668 maximum_zoom_percent_ = maximum_percent;
1669 temporary_zoom_settings_ = !remember;
1670}
1671
[email protected]0bfbf882011-12-22 18:19:271672void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481673 download_stats::RecordDownloadSource(
1674 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261675 // Check if the URL to save matches the URL of the main frame. Since this
1676 // message originates from Pepper plugins, it may not be the case if the
1677 // plugin is an embedded element.
1678 GURL main_frame_url = GetURL();
1679 if (!main_frame_url.is_valid())
1680 return;
1681 bool is_main_frame = (url == main_frame_url);
1682 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271683}
1684
[email protected]3a29a6e2011-08-24 18:26:211685void TabContents::OnEnumerateDirectory(int request_id,
1686 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591687 ChildProcessSecurityPolicyImpl* policy =
1688 ChildProcessSecurityPolicyImpl::GetInstance();
1689 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1690 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211691}
1692
[email protected]7d189022011-08-25 22:54:201693void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511694 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201695}
1696
1697void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1698 const GURL& url,
1699 const string16& title) {
[email protected]b9535422012-02-09 01:47:591700 ChildProcessSecurityPolicyImpl* policy =
1701 ChildProcessSecurityPolicyImpl::GetInstance();
1702 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1703 return;
[email protected]6934a702011-12-20 00:04:511704 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201705}
1706
[email protected]b888919c2011-09-02 00:32:161707void TabContents::OnFindReply(int request_id,
1708 int number_of_matches,
1709 const gfx::Rect& selection_rect,
1710 int active_match_ordinal,
1711 bool final_update) {
[email protected]6934a702011-12-20 00:04:511712 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1713 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001714 // Send a notification to the renderer that we are ready to receive more
1715 // results from the scoping effort of the Find operation. The FindInPage
1716 // scoping is asynchronous and periodically sends results back up to the
1717 // browser using IPC. In an effort to not spam the browser we have the
1718 // browser send an ACK for each FindReply message and have the renderer
1719 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581720 GetRenderViewHostImpl()->Send(
1721 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161722}
1723
[email protected]d952a052011-09-06 18:42:451724void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511725 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451726}
1727
[email protected]7fc4bbb2011-09-08 21:23:101728void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1729 bool blocked_by_policy) {
1730 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251731 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101732 AppCacheAccessed(manifest_url, blocked_by_policy));
1733}
1734
[email protected]da8543762012-03-20 08:52:201735void TabContents::OnOpenColorChooser(int color_chooser_id,
1736 const SkColor& color) {
1737 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1738}
1739
1740void TabContents::OnEndColorChooser(int color_chooser_id) {
1741 if (color_chooser_ &&
1742 color_chooser_id == color_chooser_->identifier())
1743 color_chooser_->End();
1744}
1745
1746void TabContents::OnSetSelectedColorInColorChooser(int color_chooser_id,
1747 const SkColor& color) {
1748 if (color_chooser_ &&
1749 color_chooser_id == color_chooser_->identifier())
1750 color_chooser_->SetSelectedColor(color);
1751}
1752
[email protected]96d185d2009-04-24 03:28:541753// Notifies the RenderWidgetHost instance about the fact that the page is
1754// loading, or done loading and calls the base implementation.
1755void TabContents::SetIsLoading(bool is_loading,
1756 LoadNotificationDetails* details) {
1757 if (is_loading == is_loading_)
1758 return;
1759
1760 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211761 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541762 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561763 upload_size_ = 0;
1764 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541765 }
1766
1767 render_manager_.SetIsLoading(is_loading);
1768
1769 is_loading_ = is_loading;
1770 waiting_for_response_ = is_loading;
1771
[email protected]6ebdc9b2010-09-27 16:55:571772 if (delegate_)
1773 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461774 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541775
[email protected]432115822011-07-10 15:52:271776 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1777 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071778 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541779 if (details)
[email protected]6c2381d2011-10-19 02:52:531780 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071781 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501782 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541783 det);
1784}
1785
[email protected]420ae012009-04-24 05:16:321786void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131787 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321788 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561789 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381790 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441791 // that opened the window, as long as both renderers have the same
1792 // privileges.
[email protected]1fd1a502011-03-30 16:55:561793 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561794 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581795 // web_ui might be NULL if the URL refers to a non-existent extension.
1796 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401797 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521798 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441799 }
1800 }
[email protected]1fd1a502011-03-30 16:55:561801 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441802 }
1803
[email protected]4e697b042011-07-08 06:44:561804 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321805 // Clear the status bubble. This is a workaround for a bug where WebKit
1806 // doesn't let us know that the cursor left an element during a
1807 // transition (this is also why the mouse cursor remains as a hand after
1808 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1809 // clear the bubble when a user navigates to a named anchor in the same
1810 // page.
[email protected]36fc0392011-12-25 03:59:511811 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321812 }
1813
[email protected]a6e82fc2010-02-24 22:28:141814 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471815 // Once the main frame is navigated, we're no longer considered to have
1816 // displayed insecure content.
1817 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171818 }
[email protected]ce5c4502009-05-06 16:46:111819
[email protected]3c9e1872010-11-18 16:17:491820 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251821 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041822 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321823}
1824
1825void TabContents::DidNavigateAnyFramePostCommit(
1826 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131827 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321828 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061829 // If we navigate off the page, reset JavaScript state. This does nothing
1830 // to prevent a malicious script from spamming messages, since the script
1831 // could just reload the page to stop blocking.
1832 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551833 dialog_creator_->ResetJavaScriptState(this);
1834 dialog_creator_ = NULL;
1835 }
[email protected]420ae012009-04-24 05:16:321836
[email protected]3c9e1872010-11-18 16:17:491837 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251838 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041839 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321840}
1841
[email protected]74ce1ad2011-12-16 21:51:461842void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1843 // If we are creating a RVH for a restored controller, then we need to make
1844 // sure the RenderView starts with a next_page_id_ larger than the number
1845 // of restored entries. This must be called before the RenderView starts
1846 // navigating (to avoid a race between the browser updating max_page_id and
1847 // the renderer updating next_page_id_). Because of this, we only call this
1848 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561849 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581850 if (max_restored_page_id >
1851 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1852 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1853 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321854}
1855
[email protected]10f417c52011-12-28 21:04:231856bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571857 const string16& title) {
[email protected]420ae012009-04-24 05:16:321858 // For file URLs without a title, use the pathname instead. In the case of a
1859 // synthesized title, we don't want the update to count toward the "one set
1860 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511861 string16 final_title;
[email protected]420ae012009-04-24 05:16:321862 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511863 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1864 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321865 explicit_set = false; // Don't count synthetic titles toward the set limit.
1866 } else {
[email protected]acafd272011-07-26 17:35:571867 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321868 explicit_set = true;
1869 }
1870
[email protected]987fc3a2011-05-26 14:18:091871 // If a page is created via window.open and never navigated,
1872 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551873 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091874 if (entry) {
[email protected]36fc0392011-12-25 03:59:511875 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091876 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321877
[email protected]36fc0392011-12-25 03:59:511878 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091879 } else {
1880 if (page_title_when_no_navigation_entry_ == final_title)
1881 return false; // Nothing changed, don't bother.
1882
1883 page_title_when_no_navigation_entry_ = final_title;
1884 }
[email protected]420ae012009-04-24 05:16:321885
[email protected]420ae012009-04-24 05:16:321886 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231887 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321888
[email protected]2bb171882012-03-07 02:09:461889 std::pair<content::NavigationEntry*, bool> details =
1890 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141891
[email protected]ad50def52011-10-19 23:17:071892 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441893 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1894 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461895 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041896
[email protected]420ae012009-04-24 05:16:321897 return true;
1898}
1899
1900void TabContents::NotifySwapped() {
1901 // After sending out a swap notification, we need to send a disconnect
1902 // notification so that clients that pick up a pointer to |this| can NULL the
1903 // pointer. See Bug 1230284.
1904 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071905 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201906 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1907 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071908 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321909}
1910
1911void TabContents::NotifyConnected() {
1912 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071913 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121914 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1915 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071916 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321917}
1918
1919void TabContents::NotifyDisconnected() {
1920 if (!notify_disconnection_)
1921 return;
1922
1923 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071924 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321925 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
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
[email protected]8d3347f2009-07-09 22:00:211930RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321931 return view_.get();
1932}
1933
[email protected]8d3347f2009-07-09 22:00:211934RenderViewHostDelegate::RendererManagement*
1935TabContents::GetRendererManagementDelegate() {
1936 return &render_manager_;
1937}
1938
[email protected]daf82f82011-10-31 22:35:311939content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371940 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461941 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511942}
1943
[email protected]768c5472011-12-26 19:06:171944WebContents* TabContents::GetAsWebContents() {
1945 return this;
1946}
1947
[email protected]da4dfc42011-10-12 15:53:561948content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431949 return view_type_;
[email protected]7b291f92009-08-14 05:43:531950}
1951
[email protected]b7a756d42012-01-23 18:08:171952gfx::Rect TabContents::GetRootWindowResizerRect() const {
1953 if (delegate_)
1954 return delegate_->GetRootWindowResizerRect();
1955 return gfx::Rect();
1956}
1957
[email protected]420ae012009-04-24 05:16:321958void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071959 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271960 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321961 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531962 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231963 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321964 if (!entry)
1965 return;
1966
1967 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351968 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561969 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581970 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321971
1972 if (entry->IsViewSourceMode()) {
1973 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:581974 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
1975 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:321976 }
[email protected]0666aef2009-05-13 19:48:081977
[email protected]d487beefe2011-12-21 05:41:211978 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261979
1980 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251981 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321982}
1983
1984void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521985 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321986 // Don't notify the world, since this came from a renderer in the
1987 // background.
1988 return;
1989 }
1990
1991 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311992 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231993 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301994
1995 // Restore the focus to the tab (otherwise the focus will be on the top
1996 // window).
[email protected]484ae5912010-09-29 19:16:141997 if (was_crashed && !FocusLocationBarByDefault() &&
1998 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301999 Focus();
[email protected]484ae5912010-09-29 19:16:142000 }
[email protected]32ded2212011-11-10 18:51:432001
[email protected]d8c660432011-12-22 20:51:252002 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322003}
2004
[email protected]443b80e2010-12-14 00:42:232005void TabContents::RenderViewGone(RenderViewHost* rvh,
2006 base::TerminationStatus status,
2007 int error_code) {
[email protected]151a63d2011-12-20 22:32:522008 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322009 // The pending page's RenderViewHost is gone.
2010 return;
2011 }
2012
2013 SetIsLoading(false, NULL);
2014 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232015 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312016 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322017
[email protected]d8c660432011-12-22 20:51:252018 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272019 observers_,
[email protected]be1f56ab2011-12-22 06:55:312020 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322021}
2022
[email protected]2e4633c2009-07-09 16:58:062023void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482024 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252025 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062026}
2027
[email protected]420ae012009-04-24 05:16:322028void TabContents::DidNavigate(RenderViewHost* rvh,
2029 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582030 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322031 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372032
[email protected]434f69f2012-02-06 21:56:522033 // Update the site of the SiteInstance if it doesn't have one yet, unless
2034 // this is for about:blank. In that case, the SiteInstance can still be
2035 // considered unused until a navigation to a real page.
2036 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2037 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332038 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522039 }
[email protected]420ae012009-04-24 05:16:322040
2041 // Need to update MIME type here because it's referred to in
2042 // UpdateNavigationCommands() called by RendererDidNavigate() to
2043 // determine whether or not to enable the encoding menu.
2044 // It's updated only for the main frame. For a subframe,
2045 // RenderView::UpdateURL does not set params.contents_mime_type.
2046 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2047 // TODO(jungshik): Add a test for the encoding menu to avoid
2048 // regressing it again.
[email protected]2905f742011-10-13 03:51:582049 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322050 contents_mime_type_ = params.contents_mime_type;
2051
[email protected]8286f51a2011-05-31 17:39:132052 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002053 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392054
[email protected]a9c0bfe2010-09-17 08:35:222055 // Send notification about committed provisional loads. This notification is
2056 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2057 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082058 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072059 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2060 // that is not recorded in the navigation history. For the purpose of
2061 // tracking navigation events, we treat this event as a sub frame navigation
2062 // event.
2063 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582064 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222065 // Whether or not a page transition was triggered by going backward or
2066 // forward in the history is only stored in the navigation controller's
2067 // entry list.
2068 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512069 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582070 content::PAGE_TRANSITION_FORWARD_BACK)) {
2071 transition_type = content::PageTransitionFromInt(
2072 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222073 }
[email protected]0d60f0192011-04-14 12:40:102074 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252075 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102076 DidCommitProvisionalLoadForFrame(params.frame_id,
2077 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222078 }
2079
[email protected]76543b92009-08-31 17:27:452080 if (!did_navigate)
2081 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322082
2083 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2084 // for the appropriate notification (best) or you can add it to
2085 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2086 // necessary, please).
2087
2088 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002089 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322090 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512091 if (delegate_)
2092 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002093 }
[email protected]420ae012009-04-24 05:16:322094 DidNavigateAnyFramePostCommit(rvh, details, params);
2095}
2096
2097void TabContents::UpdateState(RenderViewHost* rvh,
2098 int32 page_id,
2099 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152100 // Ensure that this state update comes from either the active RVH or one of
2101 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522102 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322103
2104 // We must be prepared to handle state updates for any page, these occur
2105 // when the user is scrolling and entering form data, as well as when we're
2106 // leaving a page, in which case our state may have already been moved to
2107 // the next page. The navigation controller will look up the appropriate
2108 // NavigationEntry and update it when it is notified via the delegate.
2109
2110 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582111 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322112 if (entry_index < 0)
2113 return;
[email protected]10f417c52011-12-28 21:04:232114 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322115
[email protected]36fc0392011-12-25 03:59:512116 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322117 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512118 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322119 controller_.NotifyEntryChanged(entry, entry_index);
2120}
2121
2122void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572123 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462124 const string16& title,
2125 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322126 // If we have a title, that's a pretty good indication that we've started
2127 // getting useful data.
2128 SetNotWaitingForResponse();
2129
[email protected]73eb2602012-02-09 19:50:552130 // Try to find the navigation entry, which might not be the current one.
2131 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232132 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582133 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092134
[email protected]73eb2602012-02-09 19:50:552135 // We can handle title updates when we don't have an entry in
2136 // UpdateTitleForEntry, but only if the update is from the current RVH.
2137 if (!entry && rvh != GetRenderViewHost())
2138 return;
2139
[email protected]a49e10b2011-08-01 23:57:462140 // TODO(evan): make use of title_direction.
2141 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092142 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322143 return;
2144
2145 // Broadcast notifications when the UI should be updated.
2146 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462147 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322148}
2149
[email protected]420ae012009-04-24 05:16:322150void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402151 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312152 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322153}
2154
2155void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512156 if (delegate_)
2157 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322158}
2159
[email protected]420ae012009-04-24 05:16:322160void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292161 // The UI may be in an event-tracking loop, such as between the
2162 // mouse-down and mouse-up in text selection or a button click.
2163 // Defer the close until after tracking is complete, so that we
2164 // don't free objects out from under the UI.
2165 // TODO(shess): This could probably be integrated with the
2166 // IsDoingDrag() test below. Punting for now because I need more
2167 // research to understand how this impacts platforms other than Mac.
2168 // TODO(shess): This could get more fine-grained. For instance,
2169 // closing a tab in another window while selecting text in the
2170 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212171 if (GetView()->IsEventTracking()) {
2172 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292173 return;
2174 }
2175
[email protected]24a4d1062009-07-10 23:10:422176 // If we close the tab while we're in the middle of a drag, we'll crash.
2177 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212178 if (GetView()->IsDoingDrag()) {
2179 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422180 return;
2181 }
2182
[email protected]420ae012009-04-24 05:16:322183 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522184 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512185 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322186}
2187
[email protected]cd9ed79d2011-11-15 19:22:572188void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522189 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512190 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572191}
2192
[email protected]420ae012009-04-24 05:16:322193void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512194 if (delegate_ && delegate_->IsPopupOrPanel(this))
2195 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322196}
2197
[email protected]7ab1e7d62009-10-14 23:32:012198void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322199 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492200
[email protected]82114f52012-03-20 22:53:412201 if (delegate_ && content_restrictions_)
2202 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492203
2204 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252205 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322206}
2207
[email protected]7ab1e7d62009-10-14 23:32:012208void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322209 scoped_ptr<LoadNotificationDetails> details;
2210
[email protected]10f417c52011-12-28 21:04:232211 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322212 // An entry may not exist for a stop when loading an initial blank page or
2213 // if an iframe injected by script into a blank page finishes loading.
2214 if (entry) {
[email protected]420ae012009-04-24 05:16:322215 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2216
2217 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512218 entry->GetVirtualURL(),
2219 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322220 elapsed,
2221 &controller_,
2222 controller_.GetCurrentEntryIndex()));
2223 }
2224
[email protected]420ae012009-04-24 05:16:322225 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492226
2227 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252228 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322229}
2230
[email protected]c95fa8b2011-04-28 20:26:162231void TabContents::DidCancelLoading() {
2232 controller_.DiscardNonCommittedEntries();
2233
2234 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462235 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162236}
2237
[email protected]1a3c3cb2010-12-16 21:03:402238void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512239 if (delegate_)
2240 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402241}
2242
[email protected]952a68e2011-11-17 00:36:102243void TabContents::DocumentAvailableInMainFrame(
2244 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252245 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102246 DocumentAvailableInMainFrame());
2247}
2248
[email protected]25497492010-09-11 15:15:082249void TabContents::DocumentOnLoadCompletedInMainFrame(
2250 RenderViewHost* render_view_host,
2251 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072252 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272253 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322254 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532255 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082256}
2257
[email protected]ae5184d62011-10-06 19:25:582258void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152259 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582260 WindowOpenDisposition disposition,
2261 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482262 // Delegate to RequestTransferURL because this is just the generic
2263 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582264 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482265 GlobalRequestID());
2266}
2267
2268void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582269 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482270 WindowOpenDisposition disposition,
2271 int64 source_frame_id,
2272 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202273 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582274 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582275 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352276 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322277 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2278 // generated suggestions).
2279 //
[email protected]e0112912011-02-02 22:54:352280 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162281 // want web sites to see a referrer of "chrome://blah" (and some
2282 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322283 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432284 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222285 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482286 false /* is_renderer_initiated */);
2287 params.transferred_global_request_id = old_request_id;
2288 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222289 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322290 } else {
[email protected]6bf6a6b52012-02-03 15:41:432291 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482292 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2293 params.transferred_global_request_id = old_request_id;
2294 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582295 }
2296 if (new_contents) {
2297 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252298 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582299 DidOpenRequestedURL(new_contents,
2300 url,
2301 referrer,
2302 disposition,
2303 transition_type,
2304 source_frame_id));
[email protected]420ae012009-04-24 05:16:322305 }
2306}
2307
[email protected]420ae012009-04-24 05:16:322308void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342309 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412310 const string16& message,
2311 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322312 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472313 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322314 IPC::Message* reply_msg,
2315 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072316 // Suppress JavaScript dialogs when requested. Also suppress messages when
2317 // showing an interstitial as it's shown over the previous page and we don't
2318 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502319 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582320 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272321 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072322 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522323 delegate_->ShouldSuppressDialogs() ||
2324 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322325
2326 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432327 std::string accept_lang = content::GetContentClient()->browser()->
2328 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552329 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522330 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432331 this,
2332 frame_url.GetOrigin(),
2333 accept_lang,
2334 javascript_message_type,
2335 message,
[email protected]51da7e32012-01-30 19:24:522336 default_prompt,
2337 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432338 reply_msg),
[email protected]51da7e32012-01-30 19:24:522339 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322340 }
[email protected]3ab9cb82011-06-03 18:02:072341
2342 if (suppress_this_message) {
2343 // If we are suppressing messages, just reply as if the user immediately
2344 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342345 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072346 }
2347
2348 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322349}
2350
[email protected]fedec012012-01-28 03:09:342351void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412352 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322353 bool is_reload,
[email protected]420ae012009-04-24 05:16:322354 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582355 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512356 if (delegate_)
2357 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072358
2359 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582360 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072361 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522362 delegate_->ShouldSuppressDialogs() ||
2363 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152364 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342365 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582366 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502367 return;
2368 }
[email protected]3ab9cb82011-06-03 18:02:072369
[email protected]7ab1e7d62009-10-14 23:32:012370 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552371 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522372 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322373 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522374 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2375 reply_msg));
[email protected]420ae012009-04-24 05:16:322376}
2377
[email protected]420ae012009-04-24 05:16:322378WebPreferences TabContents::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332379 // We want to base the page config off of the real URL, rather than the
2380 // display URL.
2381 GURL url = controller_.GetActiveEntry()
2382 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2383 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322384}
2385
[email protected]7d472472011-01-22 01:30:252386void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272387 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252388 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222389
[email protected]ea114722012-03-12 01:11:252390 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172391 if (rdh) // NULL in unittests.
2392 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252393}
2394
[email protected]fa1cf0b82010-01-15 21:49:442395void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442396 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252397 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442398}
2399
[email protected]420ae012009-04-24 05:16:322400void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2401 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152402 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522403 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152404 return;
2405
[email protected]9f76c1e2012-03-05 15:15:582406 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2407
[email protected]e5fc1632011-08-08 07:51:532408 // Ignore renderer unresponsive event if debugger is attached to the tab
2409 // since the event may be a result of the renderer sitting on a breakpoint.
2410 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442411 DevToolsAgentHost* agent =
2412 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2413 if (agent &&
2414 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532415 return;
2416
[email protected]420ae012009-04-24 05:16:322417 if (is_during_unload) {
2418 // Hang occurred while firing the beforeunload/unload handler.
2419 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582420 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322421
2422 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2423 return;
2424
2425 // If the tab hangs in the beforeunload/unload handler there's really
2426 // nothing we can do to recover. Pretend the unload listeners have
2427 // all fired and close the tab. If the hang is in the beforeunload handler
2428 // then the user will not have the option of cancelling the close.
2429 Close(rvh);
2430 return;
2431 }
2432
[email protected]9f76c1e2012-03-05 15:15:582433 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472434 return;
2435
[email protected]6934a702011-12-20 00:04:512436 if (delegate_)
2437 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322438}
2439
2440void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512441 if (delegate_)
2442 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322443}
2444
2445void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212446 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562447 uint64 upload_position,
2448 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322449 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562450 upload_position_ = upload_position;
2451 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502452 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202453 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302454 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212455 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322456 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462457 if (IsLoading()) {
2458 NotifyNavigationStateChanged(
2459 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2460 }
[email protected]420ae012009-04-24 05:16:322461}
2462
[email protected]7d472472011-01-22 01:30:252463void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512464 if (delegate_)
2465 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252466}
2467
[email protected]420ae012009-04-24 05:16:322468void TabContents::BeforeUnloadFiredFromRenderManager(
2469 bool proceed,
2470 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512471 if (delegate_)
2472 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322473}
2474
[email protected]3a3d47472010-07-15 21:03:542475void TabContents::DidStartLoadingFromRenderManager(
2476 RenderViewHost* render_view_host) {
2477 DidStartLoading();
2478}
2479
2480void TabContents::RenderViewGoneFromRenderManager(
2481 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232482 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2483 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542484}
2485
[email protected]420ae012009-04-24 05:16:322486void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102487 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262488 gfx::Size size = view_->GetContainerSize();
2489 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2490 // here during container initialization and normal window size will be set
2491 // later. In case of tab duplication this resizing to 0x0 prevents setting
2492 // normal size later so just ignore it.
2493 if (!size.IsEmpty())
2494 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322495}
2496
[email protected]3a3d47472010-07-15 21:03:542497void TabContents::NotifySwappedFromRenderManager() {
2498 NotifySwapped();
2499}
2500
[email protected]d202a7c2012-01-04 07:53:472501NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202502 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542503}
2504
[email protected]d2353452012-01-19 19:53:562505WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2506 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322507}
2508
[email protected]10f417c52011-12-28 21:04:232509NavigationEntry*
2510 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322511 return controller_.GetLastCommittedEntry();
2512}
2513
2514bool TabContents::CreateRenderViewForRenderManager(
2515 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442516 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322517 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522518
[email protected]420ae012009-04-24 05:16:322519 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442520 if (rwh_view)
2521 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322522
[email protected]74ce1ad2011-12-16 21:51:462523 // Make sure we use the correct starting page_id in the new RenderView.
2524 UpdateMaxPageIDIfNecessary(render_view_host);
2525 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582526 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462527
[email protected]9f76c1e2012-03-05 15:15:582528 if (!static_cast<RenderViewHostImpl*>(
2529 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522530 return false;
2531
[email protected]e60c0232011-11-11 19:56:352532#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502533 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2534 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442535 if (rwh_view) {
2536 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2537 render_widget_host->WasResized();
2538 }
[email protected]f8233cc2011-05-31 20:24:502539#endif
2540
[email protected]420ae012009-04-24 05:16:322541 return true;
2542}
2543
[email protected]fedec012012-01-28 03:09:342544void TabContents::OnDialogClosed(RenderViewHost* rvh,
2545 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072546 bool success,
2547 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542548 if (is_showing_before_unload_dialog_ && !success) {
2549 // If a beforeunload dialog is canceled, we need to stop the throbber from
2550 // spinning, since we forced it to start spinning in Navigate.
2551 DidStopLoading();
2552
2553 tab_close_start_time_ = base::TimeTicks();
2554 }
2555 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582556 static_cast<RenderViewHostImpl*>(
2557 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542558}
2559
[email protected]be1f56ab2011-12-22 06:55:312560void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122561 encoding_ = content::GetContentClient()->browser()->
2562 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102563}
[email protected]f45d2a72010-03-08 23:28:352564
[email protected]e30d68d2012-02-09 00:06:262565void TabContents::SaveURL(const GURL& url,
2566 const GURL& referrer,
2567 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142568 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2569 if (!dlm)
2570 return;
2571 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262572 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142573 const NavigationEntry* entry = controller_.GetActiveEntry();
2574 if (entry)
2575 post_id = entry->GetPostID();
2576 }
[email protected]29a5ffc82012-03-13 19:35:582577 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142578 save_info.prompt_for_save_location = true;
2579 dlm->DownloadUrl(url,
2580 referrer,
2581 "",
2582 true, // prefer_cache
2583 post_id,
2584 save_info,
[email protected]89e6aa72012-03-12 22:51:332585 this,
2586 DownloadManager::OnStartedCallback());
[email protected]27678b2a2012-02-04 22:09:142587}
2588
[email protected]33f74972010-12-08 16:40:362589void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212590 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442591 // Can be NULL during tests.
2592 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212593 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362594}
[email protected]9f76c1e2012-03-05 15:15:582595
2596RenderViewHostImpl* TabContents::GetRenderViewHostImpl() {
2597 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2598}