blob: 930976c85012eb9eda9e444a101f2d51faaf464c [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);
[email protected]64d69de42012-02-06 00:19:54402 prefs.force_compositing_mode =
403 command_line.HasSwitch(switches::kForceCompositingMode);
404 prefs.fixed_position_compositing_enabled =
405 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
406 prefs.accelerated_2d_canvas_enabled =
407 GpuProcessHost::gpu_enabled() &&
408 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58409 prefs.deferred_2d_canvas_enabled =
410 command_line.HasSwitch(switches::kEnableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36411 prefs.threaded_animation_enabled =
[email protected]7d2e0532012-03-23 22:03:31412 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54413 prefs.accelerated_painting_enabled =
414 GpuProcessHost::gpu_enabled() &&
415 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
416 prefs.accelerated_filters_enabled =
417 GpuProcessHost::gpu_enabled() &&
418 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
419 prefs.accelerated_layers_enabled =
420 prefs.accelerated_animation_enabled =
421 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
422 prefs.composite_to_texture_enabled =
423 command_line.HasSwitch(switches::kEnableCompositeToTexture);
424 prefs.accelerated_plugins_enabled =
425 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
426 prefs.accelerated_video_enabled =
427 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
428 prefs.partial_swap_enabled =
429 command_line.HasSwitch(switches::kEnablePartialSwap);
430 prefs.interactive_form_validation_enabled =
431 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
432 prefs.fullscreen_enabled =
433 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16434 prefs.css_regions_enabled =
435 command_line.HasSwitch(switches::kEnableCssRegions);
436
[email protected]64d69de42012-02-06 00:19:54437
438#if defined(OS_MACOSX)
439 bool default_enable_scroll_animator = true;
440#else
441 // On CrOS, the launcher always passes in the --enable flag.
442 bool default_enable_scroll_animator = false;
443#endif
444 prefs.enable_scroll_animator = default_enable_scroll_animator;
445 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
446 prefs.enable_scroll_animator = true;
447 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
448 prefs.enable_scroll_animator = false;
449
450 prefs.visual_word_movement_enabled =
451 command_line.HasSwitch(switches::kEnableVisualWordMovement);
452 prefs.per_tile_painting_enabled =
453 command_line.HasSwitch(switches::kEnablePerTilePainting);
454
455 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32456 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54457 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11458 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
459 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54460 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11461 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54462 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11463 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54464 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11465 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54466 prefs.gl_multisampling_enabled = false;
467
468 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45469 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32470 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54471 prefs.accelerated_video_enabled = false;
472 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45473 prefs.accelerated_layers_enabled = false;
[email protected]64d69de42012-02-06 00:19:54474 }
475 }
476
[email protected]b9535422012-02-09 01:47:59477 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58478 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54479 prefs.loads_images_automatically = true;
480 prefs.javascript_enabled = true;
481 }
482
483 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
484
485 // Force accelerated compositing and 2d canvas off for chrome:, about: and
486 // chrome-devtools: pages (unless it's specifically allowed).
487 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54488 url.SchemeIs(chrome::kChromeUIScheme) ||
489 (url.SchemeIs(chrome::kAboutScheme) &&
490 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25491 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54492 prefs.accelerated_compositing_enabled = false;
493 prefs.accelerated_2d_canvas_enabled = false;
494 }
495
[email protected]43d9d782012-03-01 15:40:09496 int default_device_scale_factor;
497 base::StringToInt(command_line.GetSwitchValueASCII(
498 switches::kDefaultDeviceScaleFactor),
499 &default_device_scale_factor);
500
501 prefs.default_device_scale_factor = default_device_scale_factor;
502
[email protected]2e21fe292012-03-02 22:52:32503 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54504
505 return prefs;
506}
507
[email protected]d202a7c2012-01-04 07:53:47508NavigationControllerImpl& TabContents::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20509 return controller_;
510}
511
[email protected]765187182012-01-11 23:59:28512RenderViewHostManager* TabContents::GetRenderManagerForTesting() {
513 return &render_manager_;
514}
515
[email protected]724159a2010-12-30 01:11:18516bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56517 if (GetWebUI() &&
518 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17519 return true;
[email protected]d2353452012-01-19 19:53:56520 }
[email protected]f82d57b52011-04-27 19:13:17521
[email protected]d8c660432011-12-22 20:51:25522 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
523 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10524 while ((observer = it.GetNext()) != NULL)
525 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53526 return true;
[email protected]403415a2011-01-10 18:57:53527
[email protected]724159a2010-12-30 01:11:18528 bool handled = true;
529 bool message_is_ok = true;
530 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58531 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
532 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24533 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
534 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18535 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
536 OnDidStartProvisionalLoadForFrame)
537 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
538 OnDidRedirectProvisionalLoad)
539 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
540 OnDidFailProvisionalLoadWithError)
541 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
542 OnDidLoadResourceFromMemoryCache)
543 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
544 OnDidDisplayInsecureContent)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
546 OnDidRunInsecureContent)
547 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
548 OnDocumentLoadedInFrame)
549 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17550 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
551 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25552 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26553 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59554 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21555 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20556 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
557 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
558 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16559 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45560 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10561 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20562 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
563 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
564 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
565 OnSetSelectedColorInColorChooser)
[email protected]724159a2010-12-30 01:11:18566 IPC_MESSAGE_UNHANDLED(handled = false)
567 IPC_END_MESSAGE_MAP_EX()
568
569 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38570 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18571 GetRenderProcessHost()->ReceivedBadMessage();
572 }
573
574 return handled;
575}
576
[email protected]6c2e472f2011-08-24 23:26:18577void TabContents::RunFileChooser(
578 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23579 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51580 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18581}
582
[email protected]c5eed492012-01-04 17:07:50583NavigationController& TabContents::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56584 return controller_;
585}
586
[email protected]c5eed492012-01-04 17:07:50587const NavigationController& TabContents::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56588 return controller_;
589}
590
[email protected]627e0512011-12-21 22:55:30591content::BrowserContext* TabContents::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55592 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30593}
594
[email protected]f5fa20e2011-12-21 22:35:56595void TabContents::SetViewType(content::ViewType type) {
596 view_type_ = type;
597}
598
[email protected]ea049a02011-12-25 21:37:09599content::ViewType TabContents::GetViewType() const {
600 return view_type_;
601}
602
[email protected]be1f56ab2011-12-22 06:55:31603const GURL& TabContents::GetURL() const {
604 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23605 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51606 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31607}
608
609
610const base::PropertyBag* TabContents::GetPropertyBag() const {
611 return &property_bag_;
612}
613
614base::PropertyBag* TabContents::GetPropertyBag() {
615 return &property_bag_;
616}
617
618content::WebContentsDelegate* TabContents::GetDelegate() {
619 return delegate_;
620}
621
622void TabContents::SetDelegate(content::WebContentsDelegate* delegate) {
623 // TODO(cbentzel): remove this debugging code?
624 if (delegate == delegate_)
625 return;
626 if (delegate_)
627 delegate_->Detach(this);
628 delegate_ = delegate;
629 if (delegate_)
630 delegate_->Attach(this);
631}
632
[email protected]f3b1a082011-11-18 00:34:30633content::RenderProcessHost* TabContents::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41634 RenderViewHostImpl* host = render_manager_.current_host();
635 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16636}
637
[email protected]be1f56ab2011-12-22 06:55:31638RenderViewHost* TabContents::GetRenderViewHost() const {
639 return render_manager_.current_host();
640}
641
642RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const {
643 return render_manager_.GetRenderWidgetHostView();
644}
645
[email protected]8643e6d2012-01-18 20:26:10646content::WebContentsView* TabContents::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31647 return view_.get();
648}
649
[email protected]01ec4ec2012-01-18 04:13:47650content::WebUI* TabContents::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50651 WebUIControllerFactory* factory =
652 content::GetContentClient()->browser()->GetWebUIControllerFactory();
653 if (!factory)
654 return NULL;
[email protected]d2353452012-01-19 19:53:56655 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22656 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50657 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22658 if (controller) {
659 web_ui->SetController(controller);
660 return web_ui;
661 }
662
663 delete web_ui;
664 return NULL;
665}
666
[email protected]01ec4ec2012-01-18 04:13:47667content::WebUI* TabContents::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31668 return render_manager_.web_ui() ? render_manager_.web_ui()
669 : render_manager_.pending_web_ui();
670}
671
[email protected]01ec4ec2012-01-18 04:13:47672content::WebUI* TabContents::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31673 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34674}
675
[email protected]96d185d2009-04-24 03:28:54676const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55677 // Transient entries take precedence. They are used for interstitial pages
678 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23679 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08680 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20681 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30682 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23683 if (entry) {
[email protected]b5cca982011-05-26 04:42:08684 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23685 }
[email protected]7ade2732011-02-10 00:13:58686 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
687 render_manager_.pending_web_ui() : render_manager_.web_ui();
688 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54689 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55690 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54691 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35692 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22693 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54694 if (!title.empty())
695 return title;
696 }
697 }
698
699 // We use the title for the last committed entry rather than a pending
700 // navigation entry. For example, when the user types in a URL, we want to
701 // keep the old page's title until the new load has committed and we get a new
702 // title.
[email protected]96d185d2009-04-24 03:28:54703 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23704 if (entry) {
[email protected]b5cca982011-05-26 04:42:08705 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23706 }
[email protected]987fc3a2011-05-26 14:18:09707
708 // |page_title_when_no_navigation_entry_| is finally used
709 // if no title cannot be retrieved.
710 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54711}
712
[email protected]d5f942ba2008-09-26 19:30:34713int32 TabContents::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46714 return GetMaxPageIDForSiteInstance(GetSiteInstance());
715}
716
717int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33718 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
719 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46720
[email protected]b6583592012-01-25 19:52:33721 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34722}
723
724void TabContents::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46725 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
726}
727
[email protected]b6583592012-01-25 19:52:33728void TabContents::UpdateMaxPageIDForSiteInstance(
729 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46730 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33731 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34732}
733
[email protected]91854cd2012-01-10 19:43:57734void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) {
735 max_page_ids_ = tab_contents->max_page_ids_;
736}
737
[email protected]96d185d2009-04-24 03:28:54738SiteInstance* TabContents::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58739 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54740}
741
[email protected]77362eb2011-08-01 17:18:38742SiteInstance* TabContents::GetPendingSiteInstance() const {
743 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
744 render_manager_.pending_render_view_host() :
745 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58746 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38747}
748
[email protected]be1f56ab2011-12-22 06:55:31749bool TabContents::IsLoading() const {
750 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49751}
752
[email protected]be1f56ab2011-12-22 06:55:31753bool TabContents::IsWaitingForResponse() const {
754 return waiting_for_response_;
755}
756
757const net::LoadStateWithParam& TabContents::GetLoadState() const {
758 return load_state_;
759}
760
761const string16& TabContents::GetLoadStateHost() const {
762 return load_state_host_;
763}
764
765uint64 TabContents::GetUploadSize() const {
766 return upload_size_;
767}
768
769uint64 TabContents::GetUploadPosition() const {
770 return upload_position_;
771}
772
773const std::string& TabContents::GetEncoding() const {
774 return encoding_;
775}
776
777bool TabContents::DisplayedInsecureContent() const {
778 return displayed_insecure_content_;
779}
780
781void TabContents::SetCapturingContents(bool cap) {
782 capturing_contents_ = cap;
783}
784
785bool TabContents::IsCrashed() const {
786 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
787 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
788 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49789}
790
[email protected]443b80e2010-12-14 00:42:23791void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
792 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34793 return;
794
[email protected]443b80e2010-12-14 00:42:23795 crashed_status_ = status;
796 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46797 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34798}
799
[email protected]be1f56ab2011-12-22 06:55:31800base::TerminationStatus TabContents::GetCrashedStatus() const {
801 return crashed_status_;
802}
803
804bool TabContents::IsBeingDestroyed() const {
805 return is_being_destroyed_;
806}
807
[email protected]d5f942ba2008-09-26 19:30:34808void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
809 if (delegate_)
810 delegate_->NavigationStateChanged(this, changed_flags);
811}
812
[email protected]96d185d2009-04-24 03:28:54813void TabContents::DidBecomeSelected() {
814 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04815 RenderWidgetHostViewPort* rwhv =
816 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16817 if (rwhv) {
818 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43819#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16820 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43821#endif
822 }
[email protected]96d185d2009-04-24 03:28:54823
[email protected]5ac20162010-11-24 23:33:11824 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38825
[email protected]d8c660432011-12-22 20:51:25826 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59827
828 // The resize rect might have changed while this was inactive -- send the new
829 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58830 RenderViewHostImpl* rvh =
831 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59832 if (rvh) {
833 rvh->ResizeRectChanged(GetRootWindowResizerRect());
834 }
[email protected]96d185d2009-04-24 03:28:54835}
836
[email protected]be1f56ab2011-12-22 06:55:31837
838base::TimeTicks TabContents::GetLastSelectedTime() const {
839 return last_selected_time_;
840}
841
[email protected]96d185d2009-04-24 03:28:54842void TabContents::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31843 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52844 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
845 // open a tab in then background, then closes the tab before selecting it.
846 // This is because closing the tab calls TabContents::Destroy(), which
847 // removes the |GetRenderViewHost()|; then when we actually destroy the
848 // window, OnWindowPosChanged() notices and calls HideContents() (which
849 // calls us).
[email protected]c30585c2012-02-16 15:02:04850 RenderWidgetHostViewPort* rwhv =
851 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16852 if (rwhv)
853 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54854 }
855
[email protected]ad50def52011-10-19 23:17:07856 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09857 content::NOTIFICATION_WEB_CONTENTS_HIDDEN,
858 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07859 content::NotificationService::NoDetails());
[email protected]96d185d2009-04-24 03:28:54860}
861
[email protected]be1f56ab2011-12-22 06:55:31862void TabContents::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04863 RenderWidgetHostViewPort* rwhv =
864 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31865 if (rwhv)
866 rwhv->DidBecomeSelected();
867}
868
869void TabContents::HideContents() {
870 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
871 // our superclass HideContents(), because some callers want to be very picky
872 // about the order in which these get called. In addition to making the code
873 // here practically impossible to understand, this also means we end up
874 // calling TabContents::WasHidden() twice if callers call both versions of
875 // HideContents() on a TabContents.
876 WasHidden();
877}
878
879bool TabContents::NeedToFireBeforeUnload() {
880 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27881 return WillNotifyDisconnection() &&
882 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58883 !static_cast<RenderViewHostImpl*>(
884 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31885}
886
[email protected]0bfbf882011-12-22 18:19:27887void TabContents::Stop() {
888 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25889 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27890}
891
[email protected]d9083482012-01-06 00:38:46892WebContents* TabContents::Clone() {
[email protected]0bfbf882011-12-22 18:19:27893 // We create a new SiteInstance so that the new tab won't share processes
894 // with the old one. This can be changed in the future if we need it to share
895 // processes for some reason.
896 TabContents* tc = new TabContents(
897 GetBrowserContext(),
[email protected]b6583592012-01-25 19:52:33898 SiteInstance::Create(GetBrowserContext()),
[email protected]0bfbf882011-12-22 18:19:27899 MSG_ROUTING_NONE, this, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20900 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27901 return tc;
902}
903
[email protected]2a6bc3e2011-12-28 23:51:33904void TabContents::AddNewContents(WebContents* new_contents,
[email protected]0bfbf882011-12-22 18:19:27905 WindowOpenDisposition disposition,
906 const gfx::Rect& initial_pos,
907 bool user_gesture) {
908 if (!delegate_)
909 return;
910
911 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
912 user_gesture);
913}
914
915gfx::NativeView TabContents::GetContentNativeView() const {
916 return view_->GetContentNativeView();
917}
918
919gfx::NativeView TabContents::GetNativeView() const {
920 return view_->GetNativeView();
921}
922
923void TabContents::GetContainerBounds(gfx::Rect* out) const {
924 view_->GetContainerBounds(out);
925}
926
927void TabContents::Focus() {
928 view_->Focus();
929}
930
[email protected]d8c660432011-12-22 20:51:25931void TabContents::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31932 observers_.AddObserver(observer);
933}
934
[email protected]d8c660432011-12-22 20:51:25935void TabContents::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:31936 observers_.RemoveObserver(observer);
937}
938
[email protected]d5f942ba2008-09-26 19:30:34939void TabContents::Activate() {
940 if (delegate_)
941 delegate_->ActivateContents(this);
942}
943
[email protected]ea42e7782010-08-23 23:58:12944void TabContents::Deactivate() {
945 if (delegate_)
946 delegate_->DeactivateContents(this);
947}
948
[email protected]63954792011-07-11 04:17:48949void TabContents::LostCapture() {
950 if (delegate_)
951 delegate_->LostCapture();
952}
953
954bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
955 bool* is_keyboard_shortcut) {
956 return delegate_ &&
957 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
958}
959
960void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
961 if (delegate_)
962 delegate_->HandleKeyboardEvent(event);
963}
964
[email protected]32ded2212011-11-10 18:51:43965void TabContents::HandleMouseDown() {
966 if (delegate_)
967 delegate_->HandleMouseDown();
968}
969
[email protected]63954792011-07-11 04:17:48970void TabContents::HandleMouseUp() {
971 if (delegate_)
972 delegate_->HandleMouseUp();
973}
974
975void TabContents::HandleMouseActivate() {
976 if (delegate_)
977 delegate_->HandleMouseActivate();
978}
979
[email protected]8a5e0ca2011-08-25 06:30:47980void TabContents::ToggleFullscreenMode(bool enter_fullscreen) {
981 if (delegate_)
982 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
983}
984
[email protected]5d5f7af2011-10-01 01:38:12985bool TabContents::IsFullscreenForCurrentTab() const {
986 return delegate_ ? delegate_->IsFullscreenForTab(this) : false;
987}
988
[email protected]e9621112011-10-17 05:38:37989void TabContents::RequestToLockMouse() {
990 if (delegate_) {
991 delegate_->RequestToLockMouse(this);
992 } else {
993 GotResponseToLockMouseRequest(false);
994 }
995}
996
997void TabContents::LostMouseLock() {
998 if (delegate_)
999 delegate_->LostMouseLock();
1000}
1001
[email protected]0548c5352011-09-07 00:33:331002void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231003 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331004 if (delegate_)
1005 delegate_->UpdatePreferredSize(this, pref_size);
1006}
1007
[email protected]61e2b3cc2012-03-02 16:13:341008void TabContents::ResizeDueToAutoResize(const gfx::Size& new_size) {
1009 if (delegate_)
1010 delegate_->ResizeDueToAutoResize(this, new_size);
1011}
1012
[email protected]32ded2212011-11-10 18:51:431013void TabContents::WebUISend(RenderViewHost* render_view_host,
1014 const GURL& source_url,
1015 const std::string& name,
1016 const base::ListValue& args) {
1017 if (delegate_)
1018 delegate_->WebUISend(this, source_url, name, args);
1019}
1020
[email protected]e5d549d2011-12-28 01:29:201021WebContents* TabContents::OpenURL(const OpenURLParams& params) {
1022 if (!delegate_)
1023 return NULL;
[email protected]00c37fc2011-08-02 00:22:501024
[email protected]e5d549d2011-12-28 01:29:201025 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1026 // Notify observers.
1027 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1028 DidOpenURL(params.url, params.referrer,
1029 params.disposition, params.transition));
1030 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341031}
1032
[email protected]1ccb3568d2010-02-19 10:51:161033bool TabContents::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501034 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251035 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231036 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251037 reload_type);
[email protected]876bc832010-09-07 16:29:541038}
[email protected]96d185d2009-04-24 03:28:541039
[email protected]876bc832010-09-07 16:29:541040bool TabContents::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231041 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501042 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401043 // The renderer will reject IPC messages with URLs longer than
1044 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511045 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401046 return false;
1047
[email protected]9f76c1e2012-03-05 15:15:581048 RenderViewHostImpl* dest_render_view_host =
1049 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401050 if (!dest_render_view_host)
1051 return false; // Unable to create the desired render view host.
1052
[email protected]80a8fad2011-01-29 04:02:381053 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071054 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581055 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501056 WebUIControllerFactory* factory =
1057 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1058 bool is_allowed_in_web_ui_renderer =
1059 factory &&
1060 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL());
[email protected]32ded2212011-11-10 18:51:431061#if defined(OS_CHROMEOS)
[email protected]36fc0392011-12-25 03:59:511062 is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme);
[email protected]32ded2212011-11-10 18:51:431063#endif
[email protected]e091df82011-10-11 18:13:211064 CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) ||
[email protected]c09163a2011-02-15 00:05:551065 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581066
[email protected]96d185d2009-04-24 03:28:541067 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441068 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521069 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441070 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511071 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541072
1073 // Used for page load time metrics.
1074 current_load_start_ = base::TimeTicks::Now();
1075
1076 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341077 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271078 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]6c6b02d2011-09-02 03:36:471079 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341080 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541081
[email protected]36fc0392011-12-25 03:59:511082 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541083 // HACK!! This code suppresses javascript: URLs from being added to
1084 // session history, which is what we want to do for javascript: URLs that
1085 // do not generate content. What we really need is a message from the
1086 // renderer telling us that a new page was not created. The same message
1087 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511088 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541089 return false;
1090 }
1091
[email protected]3c9e1872010-11-18 16:17:491092 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251093 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041094 observers_,
[email protected]36fc0392011-12-25 03:59:511095 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541096
[email protected]09b29342011-06-24 19:18:481097 if (delegate_)
1098 delegate_->DidNavigateToPendingEntry(this);
1099
[email protected]d5f942ba2008-09-26 19:30:341100 return true;
1101}
1102
[email protected]b6583592012-01-25 19:52:331103void TabContents::SetHistoryLengthAndPrune(
1104 const SiteInstance* site_instance,
1105 int history_length,
1106 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411107 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1108 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191109 if (render_manager_.pending_render_view_host()) {
1110 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141111 return;
[email protected]9e1ad4b2011-08-14 16:49:191112 }
[email protected]9f76c1e2012-03-05 15:15:581113 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191114 if (!rvh) {
1115 NOTREACHED();
1116 return;
1117 }
[email protected]9f76c1e2012-03-05 15:15:581118 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191119 NOTREACHED();
1120 return;
1121 }
[email protected]9f76c1e2012-03-05 15:15:581122 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191123 history_length,
1124 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141125}
1126
[email protected]90daadb42009-06-08 21:27:281127void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271128 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541129 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1130 return;
1131 }
[email protected]9f76c1e2012-03-05 15:15:581132 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541133}
1134
[email protected]0bfbf882011-12-22 18:19:271135bool TabContents::ShowingInterstitialPage() const {
1136 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541137}
1138
[email protected]0bfbf882011-12-22 18:19:271139InterstitialPage* TabContents::GetInterstitialPage() const {
1140 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221141}
1142
[email protected]a53209b2012-01-20 16:48:161143bool TabContents::IsSavable() {
1144 // WebKit creates Document object when MIME type is application/xhtml+xml,
1145 // so we also support this MIME type.
1146 return contents_mime_type_ == "text/html" ||
1147 contents_mime_type_ == "text/xml" ||
1148 contents_mime_type_ == "application/xhtml+xml" ||
1149 contents_mime_type_ == "text/plain" ||
1150 contents_mime_type_ == "text/css" ||
1151 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1152}
1153
[email protected]c7dd2f62011-07-18 15:57:591154void TabContents::OnSavePage() {
1155 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161156 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481157 download_stats::RecordDownloadSource(
1158 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]e30d68d2012-02-09 00:06:261159 SaveURL(GetURL(), GURL(), true);
[email protected]27678b2a2012-02-04 22:09:141160 return;
[email protected]c7dd2f62011-07-18 15:57:591161 }
1162
1163 Stop();
1164
1165 // Create the save package and possibly prompt the user for the name to save
1166 // the page as. The user prompt is an asynchronous operation that runs on
1167 // another thread.
1168 save_package_ = new SavePackage(this);
1169 save_package_->GetSaveInfo();
1170}
1171
1172// Used in automated testing to bypass prompting the user for file names.
1173// Instead, the names and paths are hard coded rather than running them through
1174// file name sanitation and extension / mime checking.
1175bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]a53209b2012-01-20 16:48:161176 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591177 // Stop the page from navigating.
1178 Stop();
1179
1180 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
1181 return save_package_->Init();
1182}
1183
[email protected]aa4f3972012-03-01 18:12:121184void TabContents::GenerateMHTML(
1185 const FilePath& file,
1186 const base::Callback<void(const FilePath&, int64)>& callback) {
1187 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1188}
1189
[email protected]420ae012009-04-24 05:16:321190bool TabContents::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231191 NavigationEntryImpl* active_entry =
1192 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321193 return (active_entry != NULL &&
1194 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511195 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321196}
1197
[email protected]0bfbf882011-12-22 18:19:271198const std::string& TabContents::GetContentsMimeType() const {
1199 return contents_mime_type_;
1200}
1201
1202bool TabContents::WillNotifyDisconnection() const {
1203 return notify_disconnection_;
1204}
1205
[email protected]b2fe07d12010-02-09 14:38:081206void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311207 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581208 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1209 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161210}
1211
[email protected]b2fe07d12010-02-09 14:38:081212void TabContents::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311213 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581214 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1215 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161216}
1217
[email protected]0bfbf882011-12-22 18:19:271218content::RendererPreferences* TabContents::GetMutableRendererPrefs() {
1219 return &renderer_preferences_;
1220}
1221
1222void TabContents::SetNewTabStartTime(const base::TimeTicks& time) {
1223 new_tab_start_time_ = time;
1224}
1225
1226base::TimeTicks TabContents::GetNewTabStartTime() const {
1227 return new_tab_start_time_;
1228}
1229
[email protected]7ab1e7d62009-10-14 23:32:011230void TabContents::OnCloseStarted() {
1231 if (tab_close_start_time_.is_null())
1232 tab_close_start_time_ = base::TimeTicks::Now();
1233}
1234
[email protected]46624bf2010-06-09 16:04:191235bool TabContents::ShouldAcceptDragAndDrop() const {
1236#if defined(OS_CHROMEOS)
1237 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1238 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511239 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201240 return false;
1241 return true;
[email protected]46624bf2010-06-09 16:04:191242#else
1243 return true;
1244#endif
1245}
1246
[email protected]7813bd72011-02-05 02:19:341247void TabContents::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521248 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581249 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511250 if (delegate_)
1251 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341252}
1253
[email protected]0bfbf882011-12-22 18:19:271254void TabContents::SetClosedByUserGesture(bool value) {
1255 closed_by_user_gesture_ = value;
1256}
1257
1258bool TabContents::GetClosedByUserGesture() const {
1259 return closed_by_user_gesture_;
1260}
1261
[email protected]d0b8d092010-10-25 04:05:171262double TabContents::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051263 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561264 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251265 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171266 return 0;
[email protected]b75b8292010-10-01 07:28:251267
1268 double zoom_level;
1269 if (temporary_zoom_settings_) {
1270 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581271 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251272 } else {
[email protected]2ae88d12011-10-14 09:11:191273 GURL url;
[email protected]10f417c52011-12-28 21:04:231274 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191275 // Since zoom map is updated using rewritten URL, use rewritten URL
1276 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511277 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191278 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251279 }
[email protected]d0b8d092010-10-25 04:05:171280 return zoom_level;
1281}
[email protected]b75b8292010-10-01 07:28:251282
[email protected]d0b8d092010-10-25 04:05:171283int TabContents::GetZoomPercent(bool* enable_increment,
1284 bool* enable_decrement) {
1285 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011286 // Calculate the zoom percent from the factor. Round up to the nearest whole
1287 // number.
[email protected]b75b8292010-10-01 07:28:251288 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011289 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251290 *enable_decrement = percent > minimum_zoom_percent_;
1291 *enable_increment = percent < maximum_zoom_percent_;
1292 return percent;
1293}
1294
[email protected]3c733bde2010-12-21 19:56:311295void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501296 if (!delegate_)
1297 return;
1298
[email protected]10f417c52011-12-28 21:04:231299 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501300 if (!active_entry)
1301 return;
1302
[email protected]36fc0392011-12-25 03:59:511303 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121304}
1305
[email protected]932b7a12011-03-09 12:50:271306void TabContents::ViewFrameSource(const GURL& url,
1307 const std::string& content_state) {
1308 if (!delegate_)
1309 return;
1310
1311 delegate_->ViewSourceForFrame(this, url, content_state);
1312}
1313
[email protected]0bfbf882011-12-22 18:19:271314int TabContents::GetMinimumZoomPercent() const {
1315 return minimum_zoom_percent_;
1316}
1317
1318int TabContents::GetMaximumZoomPercent() const {
1319 return maximum_zoom_percent_;
1320}
1321
[email protected]bcd2815602012-01-14 18:17:231322gfx::Size TabContents::GetPreferredSize() const {
1323 return preferred_size_;
1324}
1325
[email protected]0bfbf882011-12-22 18:19:271326int TabContents::GetContentRestrictions() const {
1327 return content_restrictions_;
1328}
1329
1330WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501331 WebUIControllerFactory* factory =
1332 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1333 if (!factory)
1334 return WebUI::kNoWebUI;
1335 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271336}
1337
[email protected]01ec4ec2012-01-18 04:13:471338content::WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271339 // When there is a pending navigation entry, we want to use the pending WebUI
1340 // that goes along with it to control the basic flags. For example, we want to
1341 // show the pending URL in the URL bar, so we want the display_url flag to
1342 // be from the pending entry.
1343 //
1344 // The confusion comes because there are multiple possibilities for the
1345 // initial load in a tab as a side effect of the way the RenderViewHostManager
1346 // works.
1347 //
1348 // - For the very first tab the load looks "normal". The new tab Web UI is
1349 // the pending one, and we want it to apply here.
1350 //
1351 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1352 // get switched to the one previously associated with the new tab pages.
1353 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1354 // have a committed Web UI in this case.
1355 //
1356 // This condition handles all of these cases:
1357 //
1358 // - First load in first tab: no committed nav entry + pending nav entry +
1359 // pending dom ui:
1360 // -> Use pending Web UI if any.
1361 //
1362 // - First load in second tab: no committed nav entry + pending nav entry +
1363 // no pending Web UI:
1364 // -> Use the committed Web UI if any.
1365 //
1366 // - Second navigation in any tab: committed nav entry + pending nav entry:
1367 // -> Use pending Web UI if any.
1368 //
1369 // - Normal state with no load: committed nav entry + no pending nav entry:
1370 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251371 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271372 (controller_.GetLastCommittedEntry() ||
1373 render_manager_.pending_web_ui()))
1374 return render_manager_.pending_web_ui();
1375 return render_manager_.web_ui();
1376}
1377
1378bool TabContents::GotResponseToLockMouseRequest(bool allowed) {
1379 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581380 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271381}
1382
[email protected]a0358d72012-03-09 14:06:501383bool TabContents::HasOpener() const {
1384 return has_opener_;
1385}
1386
[email protected]da8543762012-03-20 08:52:201387void TabContents::DidChooseColorInColorChooser(int color_chooser_id,
1388 const SkColor& color) {
1389 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1390 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1391}
1392
1393void TabContents::DidEndColorChooser(int color_chooser_id) {
1394 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1395 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1396 if (delegate_)
1397 delegate_->DidEndColorChooser();
1398 color_chooser_ = NULL;
1399}
1400
[email protected]0bfbf882011-12-22 18:19:271401bool TabContents::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471402 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271403 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221404 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231405 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411406 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271407}
1408
1409void TabContents::SetFocusToLocationBar(bool select_all) {
1410 if (delegate_)
1411 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211412}
1413
[email protected]8b5af492011-11-28 21:50:581414void TabContents::OnRegisterIntentService(const string16& action,
[email protected]63c239322011-10-31 23:56:301415 const string16& type,
1416 const string16& href,
1417 const string16& title,
1418 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511419 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301420 this, action, type, href, title, disposition);
1421}
1422
[email protected]678105012011-12-09 04:01:211423void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent,
[email protected]63c239322011-10-31 23:56:301424 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001425 WebIntentsDispatcherImpl* intents_dispatcher =
1426 new WebIntentsDispatcherImpl(this, intent, intent_id);
1427 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301428}
1429
[email protected]724159a2010-12-30 01:11:181430void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1431 bool is_main_frame,
[email protected]57b9396c2011-10-07 19:11:591432 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181433 const GURL& url) {
1434 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1435 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451436 GURL validated_opener_url(opener_url);
[email protected]9f76c1e2012-03-05 15:15:581437 GetRenderViewHostImpl()->FilterURL(
1438 ChildProcessSecurityPolicyImpl::GetInstance(),
1439 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451440 false,
[email protected]9f76c1e2012-03-05 15:15:581441 &validated_url);
[email protected]6b7cd8f2012-03-21 21:02:451442 GetRenderViewHostImpl()->FilterURL(
1443 ChildProcessSecurityPolicyImpl::GetInstance(),
1444 GetRenderProcessHost()->GetID(),
1445 true,
1446 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181447
[email protected]8093a542011-05-13 07:29:321448 RenderViewHost* rvh =
1449 render_manager_.pending_render_view_host() ?
[email protected]151a63d2011-12-20 22:32:521450 render_manager_.pending_render_view_host() : GetRenderViewHost();
[email protected]0d60f0192011-04-14 12:40:101451 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251452 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101453 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]8093a542011-05-13 07:29:321454 validated_url, is_error_page, rvh));
[email protected]0d60f0192011-04-14 12:40:101455
[email protected]724159a2010-12-30 01:11:181456 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591457 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251458 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451459 ProvisionalChangeToMainFrameUrl(validated_url,
1460 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181461 }
1462}
1463
1464void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
[email protected]57b9396c2011-10-07 19:11:591465 const GURL& opener_url,
[email protected]724159a2010-12-30 01:11:181466 const GURL& source_url,
1467 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491468 // TODO(creis): Remove this method and have the pre-rendering code listen to
1469 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1470 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451471 GURL validated_source_url(source_url);
1472 GURL validated_target_url(target_url);
1473 GURL validated_opener_url(opener_url);
1474 GetRenderViewHostImpl()->FilterURL(
1475 ChildProcessSecurityPolicyImpl::GetInstance(),
1476 GetRenderProcessHost()->GetID(),
1477 false,
1478 &validated_source_url);
1479 GetRenderViewHostImpl()->FilterURL(
1480 ChildProcessSecurityPolicyImpl::GetInstance(),
1481 GetRenderProcessHost()->GetID(),
1482 false,
1483 &validated_target_url);
1484 GetRenderViewHostImpl()->FilterURL(
1485 ChildProcessSecurityPolicyImpl::GetInstance(),
1486 GetRenderProcessHost()->GetID(),
1487 true,
1488 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231489 NavigationEntry* entry;
[email protected]724159a2010-12-30 01:11:181490 if (page_id == -1)
[email protected]022af742011-12-28 18:37:251491 entry = controller_.GetPendingEntry();
[email protected]724159a2010-12-30 01:11:181492 else
1493 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
[email protected]6b7cd8f2012-03-21 21:02:451494 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181495 return;
[email protected]e7d50892011-01-19 21:47:381496
[email protected]4850a7f2011-03-08 23:36:591497 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251498 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451499 ProvisionalChangeToMainFrameUrl(validated_target_url,
1500 validated_opener_url));
[email protected]724159a2010-12-30 01:11:181501}
1502
1503void TabContents::OnDidFailProvisionalLoadWithError(
[email protected]d7b175e2011-10-11 15:31:581504 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1505 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1506 << ", error_code: " << params.error_code
1507 << ", error_description: " << params.error_description
1508 << ", is_main_frame: " << params.is_main_frame
1509 << ", showing_repost_interstitial: " <<
1510 params.showing_repost_interstitial
1511 << ", frame_id: " << params.frame_id;
1512 GURL validated_url(params.url);
[email protected]9f76c1e2012-03-05 15:15:581513 GetRenderViewHostImpl()->FilterURL(
1514 ChildProcessSecurityPolicyImpl::GetInstance(),
1515 GetRenderProcessHost()->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451516 false,
[email protected]9f76c1e2012-03-05 15:15:581517 &validated_url);
[email protected]724159a2010-12-30 01:11:181518
[email protected]d7b175e2011-10-11 15:31:581519 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181520 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1521 // This means that the interstitial won't be torn down properly, which is
1522 // bad. But if we have an interstitial, go back to another tab type, and
1523 // then load the same interstitial again, we could end up getting the first
1524 // interstitial's "failed" message (as a result of the cancel) when we're on
1525 // the second one.
1526 //
1527 // We can't tell this apart, so we think we're tearing down the current page
1528 // which will cause a crash later one. There is also some code in
1529 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1530 // out because of this problem.
1531 //
1532 // http://code.google.com/p/chromium/issues/detail?id=2855
1533 // Because this will not tear down the interstitial properly, if "back" is
1534 // back to another tab type, the interstitial will still be somewhat alive
1535 // in the previous tab type. If you navigate somewhere that activates the
1536 // tab with the interstitial again, you'll see a flash before the new load
1537 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271538 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181539 LOG(WARNING) << "Discarding message during interstitial.";
1540 return;
1541 }
1542
[email protected]02102f82011-06-13 20:37:021543 // Discard our pending entry if the load canceled (e.g. if we decided to
1544 // download the file instead of load it). We do not verify that the URL
1545 // being canceled matches the pending entry's URL because they will not
1546 // match if a redirect occurred (in which case we do not want to leave a
1547 // stale redirect URL showing). This means that we also cancel the pending
1548 // entry if the user started a new navigation. As a result, the navigation
1549 // controller may not remember that a load is in progress, but the
1550 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251551 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161552 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181553
[email protected]151a63d2011-12-20 22:32:521554 render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost());
[email protected]724159a2010-12-30 01:11:181555 }
1556
[email protected]d8c660432011-12-22 20:51:251557 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581558 observers_,
1559 DidFailProvisionalLoad(params.frame_id,
1560 params.is_main_frame,
1561 validated_url,
1562 params.error_code,
1563 params.error_description));
[email protected]724159a2010-12-30 01:11:181564}
1565
1566void TabContents::OnDidLoadResourceFromMemoryCache(
1567 const GURL& url,
[email protected]70435962011-08-02 20:13:281568 const std::string& security_info,
1569 const std::string& http_method,
1570 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191571 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181572 cache.Increment();
1573
1574 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081575 int cert_id = 0;
1576 net::CertStatus cert_status = 0;
1577 int security_bits = -1;
1578 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511579 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1580 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301581 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]7a8c55e2011-02-15 08:21:161582 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181583
[email protected]ad50def52011-10-19 23:17:071584 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271585 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501586 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531587 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181588}
1589
1590void TabContents::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381591 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181592 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201593 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181594}
1595
1596void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021597 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231598 LOG(INFO) << security_origin << " ran insecure content from "
1599 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381600 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411601 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1602 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181603 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411604 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201605 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181606}
1607
1608void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1609 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251610 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101611 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181612}
1613
[email protected]1a55c5be2011-11-29 11:36:311614void TabContents::OnDidFinishLoad(
1615 int64 frame_id,
1616 const GURL& validated_url,
1617 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251618 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311619 DidFinishLoad(frame_id, validated_url, is_main_frame));
1620}
1621
1622void TabContents::OnDidFailLoadWithError(int64 frame_id,
1623 const GURL& validated_url,
1624 bool is_main_frame,
1625 int error_code,
1626 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251627 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311628 DidFailLoad(frame_id, validated_url, is_main_frame,
1629 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181630}
1631
[email protected]c8f73ab2011-01-22 00:05:171632void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271633 content_restrictions_ = restrictions;
1634 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171635}
1636
[email protected]216813952011-05-19 22:21:261637void TabContents::OnGoToEntryAtOffset(int offset) {
1638 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231639 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251640 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261641 if (!entry)
1642 return;
1643 // Note that we don't call NavigationController::GotToOffset() as we don't
1644 // want to create a pending navigation entry (it might end up lingering
1645 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251646 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581647 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511648 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581649 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471650 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571651
1652 // If the entry is being restored and doesn't have a SiteInstance yet, fill
1653 // it in now that we know. This allows us to find the entry when it commits.
1654 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:231655 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:331656 entry->set_site_instance(
1657 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:571658 }
[email protected]216813952011-05-19 22:21:261659 }
1660}
1661
1662void TabContents::OnUpdateZoomLimits(int minimum_percent,
1663 int maximum_percent,
1664 bool remember) {
1665 minimum_zoom_percent_ = minimum_percent;
1666 maximum_zoom_percent_ = maximum_percent;
1667 temporary_zoom_settings_ = !remember;
1668}
1669
[email protected]0bfbf882011-12-22 18:19:271670void TabContents::OnSaveURL(const GURL& url) {
[email protected]731809e2012-02-15 21:56:481671 download_stats::RecordDownloadSource(
1672 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:261673 // Check if the URL to save matches the URL of the main frame. Since this
1674 // message originates from Pepper plugins, it may not be the case if the
1675 // plugin is an embedded element.
1676 GURL main_frame_url = GetURL();
1677 if (!main_frame_url.is_valid())
1678 return;
1679 bool is_main_frame = (url == main_frame_url);
1680 SaveURL(url, main_frame_url, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:271681}
1682
[email protected]3a29a6e2011-08-24 18:26:211683void TabContents::OnEnumerateDirectory(int request_id,
1684 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:591685 ChildProcessSecurityPolicyImpl* policy =
1686 ChildProcessSecurityPolicyImpl::GetInstance();
1687 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
1688 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:211689}
1690
[email protected]7d189022011-08-25 22:54:201691void TabContents::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:511692 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:201693}
1694
1695void TabContents::OnRegisterProtocolHandler(const std::string& protocol,
1696 const GURL& url,
1697 const string16& title) {
[email protected]b9535422012-02-09 01:47:591698 ChildProcessSecurityPolicyImpl* policy =
1699 ChildProcessSecurityPolicyImpl::GetInstance();
1700 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
1701 return;
[email protected]6934a702011-12-20 00:04:511702 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:201703}
1704
[email protected]b888919c2011-09-02 00:32:161705void TabContents::OnFindReply(int request_id,
1706 int number_of_matches,
1707 const gfx::Rect& selection_rect,
1708 int active_match_ordinal,
1709 bool final_update) {
[email protected]6934a702011-12-20 00:04:511710 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
1711 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:001712 // Send a notification to the renderer that we are ready to receive more
1713 // results from the scoping effort of the Find operation. The FindInPage
1714 // scoping is asynchronous and periodically sends results back up to the
1715 // browser using IPC. In an effort to not spam the browser we have the
1716 // browser send an ACK for each FindReply message and have the renderer
1717 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:581718 GetRenderViewHostImpl()->Send(
1719 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:161720}
1721
[email protected]d952a052011-09-06 18:42:451722void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]6934a702011-12-20 00:04:511723 delegate_->CrashedPlugin(this, plugin_path);
[email protected]d952a052011-09-06 18:42:451724}
1725
[email protected]7fc4bbb2011-09-08 21:23:101726void TabContents::OnAppCacheAccessed(const GURL& manifest_url,
1727 bool blocked_by_policy) {
1728 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251729 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:101730 AppCacheAccessed(manifest_url, blocked_by_policy));
1731}
1732
[email protected]da8543762012-03-20 08:52:201733void TabContents::OnOpenColorChooser(int color_chooser_id,
1734 const SkColor& color) {
1735 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
1736}
1737
1738void TabContents::OnEndColorChooser(int color_chooser_id) {
1739 if (color_chooser_ &&
1740 color_chooser_id == color_chooser_->identifier())
1741 color_chooser_->End();
1742}
1743
1744void TabContents::OnSetSelectedColorInColorChooser(int color_chooser_id,
1745 const SkColor& color) {
1746 if (color_chooser_ &&
1747 color_chooser_id == color_chooser_->identifier())
1748 color_chooser_->SetSelectedColor(color);
1749}
1750
[email protected]96d185d2009-04-24 03:28:541751// Notifies the RenderWidgetHost instance about the fact that the page is
1752// loading, or done loading and calls the base implementation.
1753void TabContents::SetIsLoading(bool is_loading,
1754 LoadNotificationDetails* details) {
1755 if (is_loading == is_loading_)
1756 return;
1757
1758 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:211759 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:541760 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561761 upload_size_ = 0;
1762 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541763 }
1764
1765 render_manager_.SetIsLoading(is_loading);
1766
1767 is_loading_ = is_loading;
1768 waiting_for_response_ = is_loading;
1769
[email protected]6ebdc9b2010-09-27 16:55:571770 if (delegate_)
1771 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:461772 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:541773
[email protected]432115822011-07-10 15:52:271774 int type = is_loading ? content::NOTIFICATION_LOAD_START :
1775 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:071776 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541777 if (details)
[email protected]6c2381d2011-10-19 02:52:531778 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:071779 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:501780 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:541781 det);
1782}
1783
[email protected]420ae012009-04-24 05:16:321784void TabContents::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:131785 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321786 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561787 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381788 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441789 // that opened the window, as long as both renderers have the same
1790 // privileges.
[email protected]1fd1a502011-03-30 16:55:561791 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:561792 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:581793 // web_ui might be NULL if the URL refers to a non-existent extension.
1794 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401795 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:521796 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:441797 }
1798 }
[email protected]1fd1a502011-03-30 16:55:561799 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441800 }
1801
[email protected]4e697b042011-07-08 06:44:561802 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:321803 // Clear the status bubble. This is a workaround for a bug where WebKit
1804 // doesn't let us know that the cursor left an element during a
1805 // transition (this is also why the mouse cursor remains as a hand after
1806 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1807 // clear the bubble when a user navigates to a named anchor in the same
1808 // page.
[email protected]36fc0392011-12-25 03:59:511809 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:321810 }
1811
[email protected]a6e82fc2010-02-24 22:28:141812 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:471813 // Once the main frame is navigated, we're no longer considered to have
1814 // displayed insecure content.
1815 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171816 }
[email protected]ce5c4502009-05-06 16:46:111817
[email protected]3c9e1872010-11-18 16:17:491818 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251819 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041820 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:321821}
1822
1823void TabContents::DidNavigateAnyFramePostCommit(
1824 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:131825 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321826 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:061827 // If we navigate off the page, reset JavaScript state. This does nothing
1828 // to prevent a malicious script from spamming messages, since the script
1829 // could just reload the page to stop blocking.
1830 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:551831 dialog_creator_->ResetJavaScriptState(this);
1832 dialog_creator_ = NULL;
1833 }
[email protected]420ae012009-04-24 05:16:321834
[email protected]3c9e1872010-11-18 16:17:491835 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251836 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:041837 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:321838}
1839
[email protected]74ce1ad2011-12-16 21:51:461840void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
1841 // If we are creating a RVH for a restored controller, then we need to make
1842 // sure the RenderView starts with a next_page_id_ larger than the number
1843 // of restored entries. This must be called before the RenderView starts
1844 // navigating (to avoid a race between the browser updating max_page_id and
1845 // the renderer updating next_page_id_). Because of this, we only call this
1846 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:561847 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:581848 if (max_restored_page_id >
1849 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
1850 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
1851 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:321852}
1853
[email protected]10f417c52011-12-28 21:04:231854bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]acafd272011-07-26 17:35:571855 const string16& title) {
[email protected]420ae012009-04-24 05:16:321856 // For file URLs without a title, use the pathname instead. In the case of a
1857 // synthesized title, we don't want the update to count toward the "one set
1858 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:511859 string16 final_title;
[email protected]420ae012009-04-24 05:16:321860 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:511861 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
1862 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321863 explicit_set = false; // Don't count synthetic titles toward the set limit.
1864 } else {
[email protected]acafd272011-07-26 17:35:571865 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321866 explicit_set = true;
1867 }
1868
[email protected]987fc3a2011-05-26 14:18:091869 // If a page is created via window.open and never navigated,
1870 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:551871 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:091872 if (entry) {
[email protected]36fc0392011-12-25 03:59:511873 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:091874 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:321875
[email protected]36fc0392011-12-25 03:59:511876 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:091877 } else {
1878 if (page_title_when_no_navigation_entry_ == final_title)
1879 return false; // Nothing changed, don't bother.
1880
1881 page_title_when_no_navigation_entry_ = final_title;
1882 }
[email protected]420ae012009-04-24 05:16:321883
[email protected]420ae012009-04-24 05:16:321884 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:231885 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:321886
[email protected]2bb171882012-03-07 02:09:461887 std::pair<content::NavigationEntry*, bool> details =
1888 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:141889
[email protected]ad50def52011-10-19 23:17:071890 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:441891 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
1892 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:461893 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:041894
[email protected]420ae012009-04-24 05:16:321895 return true;
1896}
1897
1898void TabContents::NotifySwapped() {
1899 // After sending out a swap notification, we need to send a disconnect
1900 // notification so that clients that pick up a pointer to |this| can NULL the
1901 // pointer. See Bug 1230284.
1902 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071903 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:201904 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
1905 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071906 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321907}
1908
1909void TabContents::NotifyConnected() {
1910 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:071911 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:121912 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
1913 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071914 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321915}
1916
1917void TabContents::NotifyDisconnected() {
1918 if (!notify_disconnection_)
1919 return;
1920
1921 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:071922 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:321923 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
1924 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:071925 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:321926}
1927
[email protected]8d3347f2009-07-09 22:00:211928RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321929 return view_.get();
1930}
1931
[email protected]8d3347f2009-07-09 22:00:211932RenderViewHostDelegate::RendererManagement*
1933TabContents::GetRendererManagementDelegate() {
1934 return &render_manager_;
1935}
1936
[email protected]daf82f82011-10-31 22:35:311937content::RendererPreferences TabContents::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:371938 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:461939 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511940}
1941
[email protected]768c5472011-12-26 19:06:171942WebContents* TabContents::GetAsWebContents() {
1943 return this;
1944}
1945
[email protected]da4dfc42011-10-12 15:53:561946content::ViewType TabContents::GetRenderViewType() const {
[email protected]32ded2212011-11-10 18:51:431947 return view_type_;
[email protected]7b291f92009-08-14 05:43:531948}
1949
[email protected]b7a756d42012-01-23 18:08:171950gfx::Rect TabContents::GetRootWindowResizerRect() const {
1951 if (delegate_)
1952 return delegate_->GetRootWindowResizerRect();
1953 return gfx::Rect();
1954}
1955
[email protected]420ae012009-04-24 05:16:321956void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]ad50def52011-10-19 23:17:071957 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271958 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:321959 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:531960 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:231961 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:321962 if (!entry)
1963 return;
1964
1965 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351966 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561967 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581968 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321969
1970 if (entry->IsViewSourceMode()) {
1971 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:581972 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
1973 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:321974 }
[email protected]0666aef2009-05-13 19:48:081975
[email protected]d487beefe2011-12-21 05:41:211976 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:261977
1978 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:251979 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:321980}
1981
1982void TabContents::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:521983 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:321984 // Don't notify the world, since this came from a renderer in the
1985 // background.
1986 return;
1987 }
1988
1989 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:311990 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:231991 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301992
1993 // Restore the focus to the tab (otherwise the focus will be on the top
1994 // window).
[email protected]484ae5912010-09-29 19:16:141995 if (was_crashed && !FocusLocationBarByDefault() &&
1996 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301997 Focus();
[email protected]484ae5912010-09-29 19:16:141998 }
[email protected]32ded2212011-11-10 18:51:431999
[email protected]d8c660432011-12-22 20:51:252000 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322001}
2002
[email protected]443b80e2010-12-14 00:42:232003void TabContents::RenderViewGone(RenderViewHost* rvh,
2004 base::TerminationStatus status,
2005 int error_code) {
[email protected]151a63d2011-12-20 22:32:522006 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322007 // The pending page's RenderViewHost is gone.
2008 return;
2009 }
2010
2011 SetIsLoading(false, NULL);
2012 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232013 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312014 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322015
[email protected]d8c660432011-12-22 20:51:252016 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272017 observers_,
[email protected]be1f56ab2011-12-22 06:55:312018 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322019}
2020
[email protected]2e4633c2009-07-09 16:58:062021void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482022 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252023 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062024}
2025
[email protected]420ae012009-04-24 05:16:322026void TabContents::DidNavigate(RenderViewHost* rvh,
2027 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582028 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322029 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372030
[email protected]434f69f2012-02-06 21:56:522031 // Update the site of the SiteInstance if it doesn't have one yet, unless
2032 // this is for about:blank. In that case, the SiteInstance can still be
2033 // considered unused until a navigation to a real page.
2034 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2035 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332036 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522037 }
[email protected]420ae012009-04-24 05:16:322038
2039 // Need to update MIME type here because it's referred to in
2040 // UpdateNavigationCommands() called by RendererDidNavigate() to
2041 // determine whether or not to enable the encoding menu.
2042 // It's updated only for the main frame. For a subframe,
2043 // RenderView::UpdateURL does not set params.contents_mime_type.
2044 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2045 // TODO(jungshik): Add a test for the encoding menu to avoid
2046 // regressing it again.
[email protected]2905f742011-10-13 03:51:582047 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322048 contents_mime_type_ = params.contents_mime_type;
2049
[email protected]8286f51a2011-05-31 17:39:132050 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002051 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392052
[email protected]a9c0bfe2010-09-17 08:35:222053 // Send notification about committed provisional loads. This notification is
2054 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2055 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082056 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072057 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2058 // that is not recorded in the navigation history. For the purpose of
2059 // tracking navigation events, we treat this event as a sub frame navigation
2060 // event.
2061 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582062 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222063 // Whether or not a page transition was triggered by going backward or
2064 // forward in the history is only stored in the navigation controller's
2065 // entry list.
2066 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512067 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582068 content::PAGE_TRANSITION_FORWARD_BACK)) {
2069 transition_type = content::PageTransitionFromInt(
2070 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222071 }
[email protected]0d60f0192011-04-14 12:40:102072 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252073 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102074 DidCommitProvisionalLoadForFrame(params.frame_id,
2075 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:222076 }
2077
[email protected]76543b92009-08-31 17:27:452078 if (!did_navigate)
2079 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322080
2081 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2082 // for the appropriate notification (best) or you can add it to
2083 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2084 // necessary, please).
2085
2086 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002087 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322088 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512089 if (delegate_)
2090 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002091 }
[email protected]420ae012009-04-24 05:16:322092 DidNavigateAnyFramePostCommit(rvh, details, params);
2093}
2094
2095void TabContents::UpdateState(RenderViewHost* rvh,
2096 int32 page_id,
2097 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152098 // Ensure that this state update comes from either the active RVH or one of
2099 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522100 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322101
2102 // We must be prepared to handle state updates for any page, these occur
2103 // when the user is scrolling and entering form data, as well as when we're
2104 // leaving a page, in which case our state may have already been moved to
2105 // the next page. The navigation controller will look up the appropriate
2106 // NavigationEntry and update it when it is notified via the delegate.
2107
2108 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582109 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322110 if (entry_index < 0)
2111 return;
[email protected]10f417c52011-12-28 21:04:232112 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322113
[email protected]36fc0392011-12-25 03:59:512114 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322115 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512116 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322117 controller_.NotifyEntryChanged(entry, entry_index);
2118}
2119
2120void TabContents::UpdateTitle(RenderViewHost* rvh,
[email protected]acafd272011-07-26 17:35:572121 int32 page_id,
[email protected]a49e10b2011-08-01 23:57:462122 const string16& title,
2123 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322124 // If we have a title, that's a pretty good indication that we've started
2125 // getting useful data.
2126 SetNotWaitingForResponse();
2127
[email protected]73eb2602012-02-09 19:50:552128 // Try to find the navigation entry, which might not be the current one.
2129 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232130 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582131 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092132
[email protected]73eb2602012-02-09 19:50:552133 // We can handle title updates when we don't have an entry in
2134 // UpdateTitleForEntry, but only if the update is from the current RVH.
2135 if (!entry && rvh != GetRenderViewHost())
2136 return;
2137
[email protected]a49e10b2011-08-01 23:57:462138 // TODO(evan): make use of title_direction.
2139 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092140 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322141 return;
2142
2143 // Broadcast notifications when the UI should be updated.
2144 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462145 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322146}
2147
[email protected]420ae012009-04-24 05:16:322148void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402149 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312150 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322151}
2152
2153void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512154 if (delegate_)
2155 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322156}
2157
[email protected]420ae012009-04-24 05:16:322158void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292159 // The UI may be in an event-tracking loop, such as between the
2160 // mouse-down and mouse-up in text selection or a button click.
2161 // Defer the close until after tracking is complete, so that we
2162 // don't free objects out from under the UI.
2163 // TODO(shess): This could probably be integrated with the
2164 // IsDoingDrag() test below. Punting for now because I need more
2165 // research to understand how this impacts platforms other than Mac.
2166 // TODO(shess): This could get more fine-grained. For instance,
2167 // closing a tab in another window while selecting text in the
2168 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212169 if (GetView()->IsEventTracking()) {
2170 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292171 return;
2172 }
2173
[email protected]24a4d1062009-07-10 23:10:422174 // If we close the tab while we're in the middle of a drag, we'll crash.
2175 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212176 if (GetView()->IsDoingDrag()) {
2177 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422178 return;
2179 }
2180
[email protected]420ae012009-04-24 05:16:322181 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522182 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512183 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322184}
2185
[email protected]cd9ed79d2011-11-15 19:22:572186void TabContents::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522187 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512188 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572189}
2190
[email protected]420ae012009-04-24 05:16:322191void TabContents::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512192 if (delegate_ && delegate_->IsPopupOrPanel(this))
2193 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322194}
2195
[email protected]7ab1e7d62009-10-14 23:32:012196void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322197 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492198
[email protected]82114f52012-03-20 22:53:412199 if (delegate_ && content_restrictions_)
2200 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492201
2202 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252203 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322204}
2205
[email protected]7ab1e7d62009-10-14 23:32:012206void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322207 scoped_ptr<LoadNotificationDetails> details;
2208
[email protected]10f417c52011-12-28 21:04:232209 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322210 // An entry may not exist for a stop when loading an initial blank page or
2211 // if an iframe injected by script into a blank page finishes loading.
2212 if (entry) {
[email protected]420ae012009-04-24 05:16:322213 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2214
2215 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512216 entry->GetVirtualURL(),
2217 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322218 elapsed,
2219 &controller_,
2220 controller_.GetCurrentEntryIndex()));
2221 }
2222
[email protected]420ae012009-04-24 05:16:322223 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492224
2225 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252226 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322227}
2228
[email protected]c95fa8b2011-04-28 20:26:162229void TabContents::DidCancelLoading() {
2230 controller_.DiscardNonCommittedEntries();
2231
2232 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462233 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162234}
2235
[email protected]1a3c3cb2010-12-16 21:03:402236void TabContents::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512237 if (delegate_)
2238 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402239}
2240
[email protected]952a68e2011-11-17 00:36:102241void TabContents::DocumentAvailableInMainFrame(
2242 RenderViewHost* render_view_host) {
[email protected]d8c660432011-12-22 20:51:252243 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]952a68e2011-11-17 00:36:102244 DocumentAvailableInMainFrame());
2245}
2246
[email protected]25497492010-09-11 15:15:082247void TabContents::DocumentOnLoadCompletedInMainFrame(
2248 RenderViewHost* render_view_host,
2249 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072250 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272251 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322252 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532253 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082254}
2255
[email protected]ae5184d62011-10-06 19:25:582256void TabContents::RequestOpenURL(const GURL& url,
[email protected]445e1042011-12-03 21:03:152257 const content::Referrer& referrer,
[email protected]ae5184d62011-10-06 19:25:582258 WindowOpenDisposition disposition,
2259 int64 source_frame_id) {
[email protected]4ad5d77d2011-12-03 02:00:482260 // Delegate to RequestTransferURL because this is just the generic
2261 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582262 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482263 GlobalRequestID());
2264}
2265
2266void TabContents::RequestTransferURL(const GURL& url,
[email protected]bce1f1c2011-12-05 15:11:582267 const content::Referrer& referrer,
[email protected]4ad5d77d2011-12-03 02:00:482268 WindowOpenDisposition disposition,
2269 int64 source_frame_id,
2270 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202271 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582272 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582273 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352274 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322275 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2276 // generated suggestions).
2277 //
[email protected]e0112912011-02-02 22:54:352278 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162279 // want web sites to see a referrer of "chrome://blah" (and some
2280 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322281 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432282 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222283 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482284 false /* is_renderer_initiated */);
2285 params.transferred_global_request_id = old_request_id;
2286 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222287 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322288 } else {
[email protected]6bf6a6b52012-02-03 15:41:432289 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482290 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2291 params.transferred_global_request_id = old_request_id;
2292 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582293 }
2294 if (new_contents) {
2295 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252296 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582297 DidOpenRequestedURL(new_contents,
2298 url,
2299 referrer,
2300 disposition,
2301 transition_type,
2302 source_frame_id));
[email protected]420ae012009-04-24 05:16:322303 }
2304}
2305
[email protected]420ae012009-04-24 05:16:322306void TabContents::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342307 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412308 const string16& message,
2309 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322310 const GURL& frame_url,
[email protected]269f86d2011-12-07 02:43:472311 ui::JavascriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322312 IPC::Message* reply_msg,
2313 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072314 // Suppress JavaScript dialogs when requested. Also suppress messages when
2315 // showing an interstitial as it's shown over the previous page and we don't
2316 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502317 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582318 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272319 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072320 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522321 delegate_->ShouldSuppressDialogs() ||
2322 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322323
2324 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432325 std::string accept_lang = content::GetContentClient()->browser()->
2326 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552327 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522328 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432329 this,
2330 frame_url.GetOrigin(),
2331 accept_lang,
2332 javascript_message_type,
2333 message,
[email protected]51da7e32012-01-30 19:24:522334 default_prompt,
2335 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
[email protected]55df9092012-02-29 22:56:432336 reply_msg),
[email protected]51da7e32012-01-30 19:24:522337 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322338 }
[email protected]3ab9cb82011-06-03 18:02:072339
2340 if (suppress_this_message) {
2341 // If we are suppressing messages, just reply as if the user immediately
2342 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342343 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072344 }
2345
2346 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322347}
2348
[email protected]fedec012012-01-28 03:09:342349void TabContents::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412350 const string16& message,
[email protected]3b3301f62012-02-29 04:32:322351 bool is_reload,
[email protected]420ae012009-04-24 05:16:322352 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582353 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512354 if (delegate_)
2355 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072356
2357 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582358 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072359 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522360 delegate_->ShouldSuppressDialogs() ||
2361 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152362 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342363 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582364 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502365 return;
2366 }
[email protected]3ab9cb82011-06-03 18:02:072367
[email protected]7ab1e7d62009-10-14 23:32:012368 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552369 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522370 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322371 this, message, is_reload,
[email protected]51da7e32012-01-30 19:24:522372 base::Bind(&TabContents::OnDialogClosed, base::Unretained(this), rvh,
2373 reply_msg));
[email protected]420ae012009-04-24 05:16:322374}
2375
[email protected]420ae012009-04-24 05:16:322376WebPreferences TabContents::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332377 // We want to base the page config off of the real URL, rather than the
2378 // display URL.
2379 GURL url = controller_.GetActiveEntry()
2380 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2381 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322382}
2383
[email protected]7d472472011-01-22 01:30:252384void TabContents::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272385 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252386 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222387
[email protected]ea114722012-03-12 01:11:252388 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172389 if (rdh) // NULL in unittests.
2390 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252391}
2392
[email protected]fa1cf0b82010-01-15 21:49:442393void TabContents::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442394 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252395 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442396}
2397
[email protected]420ae012009-04-24 05:16:322398void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2399 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152400 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522401 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152402 return;
2403
[email protected]9f76c1e2012-03-05 15:15:582404 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2405
[email protected]e5fc1632011-08-08 07:51:532406 // Ignore renderer unresponsive event if debugger is attached to the tab
2407 // since the event may be a result of the renderer sitting on a breakpoint.
2408 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442409 DevToolsAgentHost* agent =
2410 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2411 if (agent &&
2412 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532413 return;
2414
[email protected]420ae012009-04-24 05:16:322415 if (is_during_unload) {
2416 // Hang occurred while firing the beforeunload/unload handler.
2417 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582418 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322419
2420 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2421 return;
2422
2423 // If the tab hangs in the beforeunload/unload handler there's really
2424 // nothing we can do to recover. Pretend the unload listeners have
2425 // all fired and close the tab. If the hang is in the beforeunload handler
2426 // then the user will not have the option of cancelling the close.
2427 Close(rvh);
2428 return;
2429 }
2430
[email protected]9f76c1e2012-03-05 15:15:582431 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472432 return;
2433
[email protected]6934a702011-12-20 00:04:512434 if (delegate_)
2435 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322436}
2437
2438void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512439 if (delegate_)
2440 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322441}
2442
2443void TabContents::LoadStateChanged(const GURL& url,
[email protected]9c235f042011-08-10 22:28:212444 const net::LoadStateWithParam& load_state,
[email protected]094e5b22009-09-25 04:23:562445 uint64 upload_position,
2446 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322447 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562448 upload_position_ = upload_position;
2449 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502450 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202451 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302452 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212453 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322454 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462455 if (IsLoading()) {
2456 NotifyNavigationStateChanged(
2457 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2458 }
[email protected]420ae012009-04-24 05:16:322459}
2460
[email protected]7d472472011-01-22 01:30:252461void TabContents::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512462 if (delegate_)
2463 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252464}
2465
[email protected]420ae012009-04-24 05:16:322466void TabContents::BeforeUnloadFiredFromRenderManager(
2467 bool proceed,
2468 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512469 if (delegate_)
2470 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322471}
2472
[email protected]3a3d47472010-07-15 21:03:542473void TabContents::DidStartLoadingFromRenderManager(
2474 RenderViewHost* render_view_host) {
2475 DidStartLoading();
2476}
2477
2478void TabContents::RenderViewGoneFromRenderManager(
2479 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232480 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2481 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542482}
2483
[email protected]420ae012009-04-24 05:16:322484void TabContents::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102485 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262486 gfx::Size size = view_->GetContainerSize();
2487 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2488 // here during container initialization and normal window size will be set
2489 // later. In case of tab duplication this resizing to 0x0 prevents setting
2490 // normal size later so just ignore it.
2491 if (!size.IsEmpty())
2492 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322493}
2494
[email protected]3a3d47472010-07-15 21:03:542495void TabContents::NotifySwappedFromRenderManager() {
2496 NotifySwapped();
2497}
2498
[email protected]d202a7c2012-01-04 07:53:472499NavigationControllerImpl& TabContents::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202500 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542501}
2502
[email protected]d2353452012-01-19 19:53:562503WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) {
2504 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322505}
2506
[email protected]10f417c52011-12-28 21:04:232507NavigationEntry*
2508 TabContents::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322509 return controller_.GetLastCommittedEntry();
2510}
2511
2512bool TabContents::CreateRenderViewForRenderManager(
2513 RenderViewHost* render_view_host) {
[email protected]245f7d52011-11-28 15:36:442514 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322515 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522516
[email protected]420ae012009-04-24 05:16:322517 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442518 if (rwh_view)
2519 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322520
[email protected]74ce1ad2011-12-16 21:51:462521 // Make sure we use the correct starting page_id in the new RenderView.
2522 UpdateMaxPageIDIfNecessary(render_view_host);
2523 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582524 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462525
[email protected]9f76c1e2012-03-05 15:15:582526 if (!static_cast<RenderViewHostImpl*>(
2527 render_view_host)->CreateRenderView(string16(), max_page_id))
[email protected]a4127722011-04-27 23:13:522528 return false;
2529
[email protected]e60c0232011-11-11 19:56:352530#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:502531 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
2532 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:442533 if (rwh_view) {
2534 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
2535 render_widget_host->WasResized();
2536 }
[email protected]f8233cc2011-05-31 20:24:502537#endif
2538
[email protected]420ae012009-04-24 05:16:322539 return true;
2540}
2541
[email protected]fedec012012-01-28 03:09:342542void TabContents::OnDialogClosed(RenderViewHost* rvh,
2543 IPC::Message* reply_msg,
[email protected]3ab9cb82011-06-03 18:02:072544 bool success,
2545 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:542546 if (is_showing_before_unload_dialog_ && !success) {
2547 // If a beforeunload dialog is canceled, we need to stop the throbber from
2548 // spinning, since we forced it to start spinning in Navigate.
2549 DidStopLoading();
2550
2551 tab_close_start_time_ = base::TimeTicks();
2552 }
2553 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:582554 static_cast<RenderViewHostImpl*>(
2555 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:542556}
2557
[email protected]be1f56ab2011-12-22 06:55:312558void TabContents::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:122559 encoding_ = content::GetContentClient()->browser()->
2560 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:102561}
[email protected]f45d2a72010-03-08 23:28:352562
[email protected]e30d68d2012-02-09 00:06:262563void TabContents::SaveURL(const GURL& url,
2564 const GURL& referrer,
2565 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142566 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
2567 if (!dlm)
2568 return;
2569 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:262570 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:142571 const NavigationEntry* entry = controller_.GetActiveEntry();
2572 if (entry)
2573 post_id = entry->GetPostID();
2574 }
[email protected]29a5ffc82012-03-13 19:35:582575 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:142576 save_info.prompt_for_save_location = true;
2577 dlm->DownloadUrl(url,
2578 referrer,
2579 "",
2580 true, // prefer_cache
2581 post_id,
2582 save_info,
[email protected]89e6aa72012-03-12 22:51:332583 this,
2584 DownloadManager::OnStartedCallback());
[email protected]27678b2a2012-02-04 22:09:142585}
2586
[email protected]33f74972010-12-08 16:40:362587void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:212588 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:442589 // Can be NULL during tests.
2590 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:212591 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:362592}
[email protected]9f76c1e2012-03-05 15:15:582593
2594RenderViewHostImpl* TabContents::GetRenderViewHostImpl() {
2595 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
2596}