blob: 0872c9ed25a37c01ebd1ed063682e7edd53ef5b9 [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]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.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]172cf712012-05-23 15:07:3917#include "content/browser/browser_plugin/browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5918#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4419#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0420#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4621#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1222#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1623#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3224#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5425#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0526#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0027#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0128#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5031#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2532#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3333#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3734#include "content/browser/web_contents/interstitial_page_impl.h"
35#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5636#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2437#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5138#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5740#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5841#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1142#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2043#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4444#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4445#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1746#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1447#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4648#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1549#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2750#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0051#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3752#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1453#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3254#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3855#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4256#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2557#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1058#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5059#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2160#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4861#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1862#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5463#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0364#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1665#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2966#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5467#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3468#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3769#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5670#include "ui/base/layout.h"
[email protected]d353541f2012-05-03 22:45:4171#include "ui/base/ui_base_switches.h"
72#include "ui/gfx/monitor.h"
73#include "ui/gfx/screen.h"
[email protected]ce9751942011-09-21 01:57:2474#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3675#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3176#include "webkit/glue/webpreferences.h"
77
[email protected]f66df822012-05-18 16:52:1778#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5079#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4180#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5781#endif
[email protected]3e45ba92009-02-20 21:09:0082
[email protected]420ae012009-04-24 05:16:3283// Cross-Site Navigations
84//
[email protected]b172aee2012-04-10 17:05:2685// If a WebContentsImpl is told to navigate to a different web site (as
86// determined by SiteInstance), it will replace its current RenderViewHost with
87// a new RenderViewHost dedicated to the new SiteInstance. This works as
88// follows:
[email protected]420ae012009-04-24 05:16:3289//
90// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4691// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3292// - The pending RVH is "suspended," so that no navigation messages are sent to
93// its renderer until the onbeforeunload JavaScript handler has a chance to
94// run in the current RVH.
95// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
96// that it has a pending cross-site request. ResourceDispatcherHost will
97// check for this when the response arrives.
98// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4699// cancel all the pending logic. Otherwise we allow the pending RVH to send
100// the navigation request to its renderer.
101// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
102// main resource load on the pending RVH. It checks CrossSiteRequestManager
103// to see that it is a cross-site request, and installs a
104// CrossSiteResourceHandler.
105// - When RDH receives a response, the BufferedResourceHandler determines
106// whether it is a download. If so, it sends a message to the new renderer
107// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26108// pending RVH remains until the next DidNavigate event for this
109// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32110// - After RDH receives a response and determines that it is safe and not a
111// download, it pauses the response to first run the old page's onunload
112// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26113// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32114// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15115// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32116// the ResourceDispatcherHost, who unpauses the response. Data is then sent
117// to the pending RVH.
118// - The pending renderer sends a FrameNavigate message that invokes the
119// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46120// pending RVH.
[email protected]992db4c2011-05-12 15:37:15121// - The previous renderer is kept swapped out in RenderViewHostManager in case
122// the user goes back. The process only stays live if another tab is using
123// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32124
[email protected]0e12d7d2011-12-01 16:21:44125using content::DevToolsAgentHost;
126using content::DevToolsAgentHostRegistry;
127using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17128using content::DownloadItem;
129using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14130using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20131using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56132using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13133using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27134using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54135using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50136using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23137using content::NavigationEntry;
138using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20139using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11140using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57141using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57142using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27143using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11144using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50145using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58146using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04147using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25148using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14149using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43150using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33151using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38152using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09153using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25154using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56155using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22156using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50157using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25158using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44159
[email protected]420ae012009-04-24 05:16:32160namespace {
161
162// Amount of time we wait between when a key event is received and the renderer
163// is queried for its state and pushed to the NavigationEntry.
164const int kQueryStateDelay = 5000;
165
[email protected]6ebdc9b2010-09-27 16:55:57166const int kSyncWaitDelay = 40;
167
[email protected]82114f52012-03-20 22:53:41168const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05169
[email protected]420ae012009-04-24 05:16:32170#if defined(OS_WIN)
171
172BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
173 // Note: erase is required to properly paint some widgets borders. This can
174 // be seen with textfields.
175 InvalidateRect(hwnd, NULL, TRUE);
176 return TRUE;
177}
178#endif
179
[email protected]2c5569662011-03-22 20:45:02180ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23181 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50182 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16183 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47184 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02185 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47186 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02187 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47188 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16189 break; // Fall through to rest of function.
190 }
[email protected]5e369672009-11-03 23:48:30191
[email protected]59246c572012-02-10 13:32:13192 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
193 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23194 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13195 browser_context->DidLastSessionExitCleanly()) {
196 if (entry.GetHasPostData())
197 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02198 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13199 }
[email protected]5e369672009-11-03 23:48:30200
[email protected]2c5569662011-03-22 20:45:02201 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30202}
203
[email protected]10f417c52011-12-28 21:04:23204void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47205 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42206 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50207 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24208 const std::string& embedder_channel_name,
209 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16210 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51211 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54212 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55213 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
214 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51215 params->url = entry.GetURL();
216 params->referrer = entry.GetReferrer();
217 params->transition = entry.GetTransitionType();
218 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00219 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55220 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34221 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47222 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48223 params->transferred_request_child_id =
224 entry.transferred_global_request_id().child_id;
225 params->transferred_request_request_id =
226 entry.transferred_global_request_id().request_id;
[email protected]80744782012-05-04 01:47:00227 // Avoid downloading when in view-source mode.
228 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24229 params->embedder_channel_name = embedder_channel_name;
230 params->embedder_container_id = embedder_container_id;
[email protected]6c6b02d2011-09-02 03:36:47231
232 if (delegate)
233 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34234}
235
[email protected]f98f5092012-05-19 00:08:14236int GetSwitchValueAsInt(
237 const CommandLine& command_line,
238 const std::string& switch_string,
239 int min_value) {
240 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
241 int int_value;
242 if (base::StringToInt(string_value, &int_value))
243 return std::max(min_value, int_value);
244 else
245 return min_value;
246}
247
[email protected]420ae012009-04-24 05:16:32248} // namespace
249
[email protected]a81343d232011-12-27 07:39:20250namespace content {
251
252WebContents* WebContents::Create(
253 BrowserContext* browser_context,
254 SiteInstance* site_instance,
255 int routing_id,
[email protected]b172aee2012-04-10 17:05:26256 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20257 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26258 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43259 browser_context,
260 site_instance,
261 routing_id,
[email protected]b172aee2012-04-10 17:05:26262 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44263 NULL,
[email protected]adbfb8df2012-02-24 01:19:43264 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20265}
[email protected]746d3052012-05-22 15:15:47266
[email protected]299d7f12012-05-23 05:31:15267WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47268 return rvh->GetDelegate()->GetAsWebContents();
269}
270
[email protected]a81343d232011-12-27 07:39:20271}
[email protected]f4f50ef2011-01-21 19:01:19272
[email protected]b172aee2012-04-10 17:05:26273// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32274
[email protected]b172aee2012-04-10 17:05:26275WebContentsImpl::WebContentsImpl(
276 content::BrowserContext* browser_context,
277 SiteInstance* site_instance,
278 int routing_id,
279 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44280 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26281 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42282 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07283 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37284 this, browser_context, session_storage_namespace)),
[email protected]5a3bdf52012-05-24 15:12:57285 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44286 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05287 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34288 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23289 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
290 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34291 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21292 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56293 upload_size_(0),
294 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47295 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57296 capturing_contents_(false),
297 is_being_destroyed_(false),
298 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55299 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57300#if defined(OS_WIN)
301 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
302#endif
[email protected]7ab1e7d62009-10-14 23:32:01303 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56304 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38305 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25306 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01307 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25308 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01309 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00310 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43311 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20312 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37313 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32314
[email protected]38b098f2012-03-14 21:11:57315 view_.reset(content::GetContentClient()->browser()->
[email protected]5a3bdf52012-05-24 15:12:57316 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
317 if (view_.get()) {
318 CHECK(render_view_host_delegate_view_);
319 } else {
[email protected]38b098f2012-03-14 21:11:57320 content::WebContentsViewDelegate* delegate =
321 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
322 this);
[email protected]5a3bdf52012-05-24 15:12:57323 view_.reset(CreateWebContentsView(
324 this, delegate, &render_view_host_delegate_view_));
325 CHECK(render_view_host_delegate_view_);
[email protected]38b098f2012-03-14 21:11:57326 }
327 CHECK(view_.get());
328
[email protected]ca13a442012-04-17 14:00:12329 // We have the initial size of the view be based on the size of the view of
330 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26331 view_->CreateView(base_web_contents ?
332 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00333
[email protected]14392a52012-05-02 20:28:44334 // Listen for whether our opener gets destroyed.
335 if (opener_) {
336 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
337 content::Source<WebContents>(opener_));
338 }
339
[email protected]bafe6cd2012-05-23 23:09:50340 registrar_.Add(this,
341 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
342 content::NotificationService::AllBrowserContextsAndSources());
343
[email protected]483623eb2011-10-25 09:30:00344#if defined(ENABLE_JAVA_BRIDGE)
345 java_bridge_dispatcher_host_manager_.reset(
346 new JavaBridgeDispatcherHostManager(this));
347#endif
[email protected]172cf712012-05-23 15:07:39348
349 browser_plugin_host_.reset(new content::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35350}
initial.commit09911bf2008-07-26 23:55:29351
[email protected]b172aee2012-04-10 17:05:26352WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32353 is_being_destroyed_ = true;
354
[email protected]3ab9cb82011-06-03 18:02:07355 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55356 if (dialog_creator_)
357 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07358
[email protected]da8543762012-03-20 08:52:20359 if (color_chooser_)
360 color_chooser_->End();
361
[email protected]420ae012009-04-24 05:16:32362 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32363
[email protected]ca13a442012-04-17 14:00:12364 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07365 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09366 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
367 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07368 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32369
370 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07371#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32372 // If we still have a window handle, destroy it. GetNativeView can return
373 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42374 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52375 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58376 if (host && host->GetView())
377 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42378 }
[email protected]420ae012009-04-24 05:16:32379#endif
[email protected]7ab1e7d62009-10-14 23:32:01380
381 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15382 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01383 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15384 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01385 }
[email protected]b5a1d11c2011-02-17 03:09:42386
[email protected]2db9bd72012-04-13 20:20:56387 FOR_EACH_OBSERVER(WebContentsObserver,
388 observers_,
389 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08390
[email protected]6934a702011-12-20 00:04:51391 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42392}
393
[email protected]b172aee2012-04-10 17:05:26394WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
395 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54396 WebPreferences prefs;
397
398 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
399
400 prefs.developer_extras_enabled = true;
401 prefs.javascript_enabled =
402 !command_line.HasSwitch(switches::kDisableJavaScript);
403 prefs.web_security_enabled =
404 !command_line.HasSwitch(switches::kDisableWebSecurity);
405 prefs.plugins_enabled =
406 !command_line.HasSwitch(switches::kDisablePlugins);
407 prefs.java_enabled =
408 !command_line.HasSwitch(switches::kDisableJava);
409
410 prefs.uses_page_cache =
411 command_line.HasSwitch(switches::kEnableFastback);
412 prefs.remote_fonts_enabled =
413 !command_line.HasSwitch(switches::kDisableRemoteFonts);
414 prefs.xss_auditor_enabled =
415 !command_line.HasSwitch(switches::kDisableXSSAuditor);
416 prefs.application_cache_enabled =
417 !command_line.HasSwitch(switches::kDisableApplicationCache);
418
419 prefs.local_storage_enabled =
420 !command_line.HasSwitch(switches::kDisableLocalStorage);
421 prefs.databases_enabled =
422 !command_line.HasSwitch(switches::kDisableDatabases);
423 prefs.webaudio_enabled =
424 !command_line.HasSwitch(switches::kDisableWebAudio);
425
426 prefs.experimental_webgl_enabled =
427 GpuProcessHost::gpu_enabled() &&
428 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
429 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
430
[email protected]e0d8c422012-06-04 22:57:19431 prefs.flash_3d_enabled = prefs.flash_stage3d_enabled =
432 GpuProcessHost::gpu_enabled();
433
[email protected]64d69de42012-02-06 00:19:54434 prefs.gl_multisampling_enabled =
435 !command_line.HasSwitch(switches::kDisableGLMultisampling);
436 prefs.privileged_webgl_extensions_enabled =
437 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
438 prefs.site_specific_quirks_enabled =
439 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
440 prefs.allow_file_access_from_file_urls =
441 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
442 prefs.show_composited_layer_borders =
443 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
444 prefs.show_composited_layer_tree =
445 command_line.HasSwitch(switches::kShowCompositedLayerTree);
446 prefs.show_fps_counter =
447 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19448 prefs.show_paint_rects =
449 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]64d69de42012-02-06 00:19:54450 prefs.accelerated_compositing_enabled =
451 GpuProcessHost::gpu_enabled() &&
452 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54453 prefs.force_compositing_mode =
454 command_line.HasSwitch(switches::kForceCompositingMode);
455 prefs.fixed_position_compositing_enabled =
456 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
457 prefs.accelerated_2d_canvas_enabled =
458 GpuProcessHost::gpu_enabled() &&
459 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58460 prefs.deferred_2d_canvas_enabled =
[email protected]00bbad22012-05-25 13:24:17461 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36462 prefs.threaded_animation_enabled =
[email protected]efcde132012-05-30 01:05:18463 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54464 prefs.accelerated_painting_enabled =
465 GpuProcessHost::gpu_enabled() &&
466 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
467 prefs.accelerated_filters_enabled =
468 GpuProcessHost::gpu_enabled() &&
469 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
470 prefs.accelerated_layers_enabled =
471 prefs.accelerated_animation_enabled =
472 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54473 prefs.accelerated_plugins_enabled =
474 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
475 prefs.accelerated_video_enabled =
476 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
477 prefs.partial_swap_enabled =
478 command_line.HasSwitch(switches::kEnablePartialSwap);
479 prefs.interactive_form_validation_enabled =
480 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
481 prefs.fullscreen_enabled =
482 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16483 prefs.css_regions_enabled =
484 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29485 prefs.css_shaders_enabled =
486 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]a08412b62012-05-29 21:28:56487 prefs.device_supports_touch =
488 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]64d69de42012-02-06 00:19:54489
490#if defined(OS_MACOSX)
491 bool default_enable_scroll_animator = true;
492#else
493 // On CrOS, the launcher always passes in the --enable flag.
494 bool default_enable_scroll_animator = false;
495#endif
496 prefs.enable_scroll_animator = default_enable_scroll_animator;
497 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
498 prefs.enable_scroll_animator = true;
499 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
500 prefs.enable_scroll_animator = false;
501
502 prefs.visual_word_movement_enabled =
503 command_line.HasSwitch(switches::kEnableVisualWordMovement);
504 prefs.per_tile_painting_enabled =
505 command_line.HasSwitch(switches::kEnablePerTilePainting);
506
507 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32508 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54509 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11510 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
511 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54512 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11513 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54514 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19515 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
516 prefs.flash_3d_enabled = false;
517 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
518 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11519 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54520 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11521 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54522 prefs.gl_multisampling_enabled = false;
523
524 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45525 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32526 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54527 prefs.accelerated_video_enabled = false;
528 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45529 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09530 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54531 }
532 }
533
[email protected]b9535422012-02-09 01:47:59534 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58535 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54536 prefs.loads_images_automatically = true;
537 prefs.javascript_enabled = true;
538 }
539
540 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
541
542 // Force accelerated compositing and 2d canvas off for chrome:, about: and
543 // chrome-devtools: pages (unless it's specifically allowed).
544 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54545 url.SchemeIs(chrome::kChromeUIScheme) ||
546 (url.SchemeIs(chrome::kAboutScheme) &&
547 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25548 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54549 prefs.accelerated_compositing_enabled = false;
550 prefs.accelerated_2d_canvas_enabled = false;
551 }
[email protected]8b3b36152012-05-01 04:55:07552#if defined(OS_MACOSX)
553 // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
554 // crbug.com/125690.
[email protected]82c9a8e2012-05-02 01:07:23555 prefs.default_device_scale_factor =
556 gfx::Monitor::GetDefaultDeviceScaleFactor();
[email protected]8b3b36152012-05-01 04:55:07557#else
558 if (rvh->GetView()) {
559 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
560 rvh->GetView()->GetNativeView());
561 prefs.default_device_scale_factor =
562 static_cast<int>(monitor.device_scale_factor());
563 } else {
[email protected]82c9a8e2012-05-02 01:07:23564 prefs.default_device_scale_factor =
565 gfx::Monitor::GetDefaultDeviceScaleFactor();;
[email protected]8b3b36152012-05-01 04:55:07566 }
567#endif
[email protected]43d9d782012-03-01 15:40:09568
[email protected]f98f5092012-05-19 00:08:14569 if (command_line.HasSwitch(switches::kDefaultTileWidth))
570 prefs.default_tile_width =
571 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
572 if (command_line.HasSwitch(switches::kDefaultTileHeight))
573 prefs.default_tile_height =
574 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
575 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
576 prefs.max_untiled_layer_width =
577 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
578 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
579 prefs.max_untiled_layer_height =
580 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
581
[email protected]2486dce2012-05-23 17:18:19582 if (gfx::Screen::IsDIPEnabled()) {
583 // Only apply when using DIP coordinate system as this setting interferes
584 // with fixed layout mode.
585 prefs.apply_default_device_scale_factor_in_compositor = true;
586 }
587
[email protected]96bcdc102012-05-24 23:42:10588 prefs.fixed_position_creates_stacking_context =
589 command_line.HasSwitch(switches::kFixedPositionCreatesStackingContext);
590
[email protected]2e21fe292012-03-02 22:52:32591 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54592
593 return prefs;
594}
595
[email protected]b172aee2012-04-10 17:05:26596NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20597 return controller_;
598}
599
[email protected]b172aee2012-04-10 17:05:26600RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28601 return &render_manager_;
602}
603
[email protected]b172aee2012-04-10 17:05:26604bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56605 if (GetWebUI() &&
606 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17607 return true;
[email protected]d2353452012-01-19 19:53:56608 }
[email protected]f82d57b52011-04-27 19:13:17609
[email protected]d8c660432011-12-22 20:51:25610 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
611 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10612 while ((observer = it.GetNext()) != NULL)
613 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53614 return true;
[email protected]403415a2011-01-10 18:57:53615
[email protected]724159a2010-12-30 01:11:18616 bool handled = true;
617 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26618 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58619 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
620 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24621 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
622 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18623 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
624 OnDidLoadResourceFromMemoryCache)
625 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
626 OnDidDisplayInsecureContent)
627 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
628 OnDidRunInsecureContent)
629 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
630 OnDocumentLoadedInFrame)
631 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26632 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
633 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17634 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
635 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25636 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26637 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59638 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21639 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20640 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
641 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
642 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16643 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45644 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10645 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20646 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
647 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
648 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
649 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29650 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50651 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18652 IPC_MESSAGE_UNHANDLED(handled = false)
653 IPC_END_MESSAGE_MAP_EX()
654
655 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38656 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18657 GetRenderProcessHost()->ReceivedBadMessage();
658 }
659
660 return handled;
661}
662
[email protected]b172aee2012-04-10 17:05:26663void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18664 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23665 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51666 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18667}
668
[email protected]b172aee2012-04-10 17:05:26669NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56670 return controller_;
671}
672
[email protected]b172aee2012-04-10 17:05:26673const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56674 return controller_;
675}
676
[email protected]b172aee2012-04-10 17:05:26677content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55678 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30679}
680
[email protected]b172aee2012-04-10 17:05:26681const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31682 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23683 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51684 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31685}
686
687
[email protected]b172aee2012-04-10 17:05:26688const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31689 return &property_bag_;
690}
691
[email protected]b172aee2012-04-10 17:05:26692base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31693 return &property_bag_;
694}
695
[email protected]b172aee2012-04-10 17:05:26696content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31697 return delegate_;
698}
699
[email protected]b172aee2012-04-10 17:05:26700void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31701 // TODO(cbentzel): remove this debugging code?
702 if (delegate == delegate_)
703 return;
704 if (delegate_)
705 delegate_->Detach(this);
706 delegate_ = delegate;
707 if (delegate_)
708 delegate_->Attach(this);
709}
710
[email protected]b172aee2012-04-10 17:05:26711content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41712 RenderViewHostImpl* host = render_manager_.current_host();
713 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16714}
715
[email protected]b172aee2012-04-10 17:05:26716RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31717 return render_manager_.current_host();
718}
719
[email protected]b172aee2012-04-10 17:05:26720RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31721 return render_manager_.GetRenderWidgetHostView();
722}
723
[email protected]b172aee2012-04-10 17:05:26724content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31725 return view_.get();
726}
727
[email protected]b172aee2012-04-10 17:05:26728content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50729 WebUIControllerFactory* factory =
730 content::GetContentClient()->browser()->GetWebUIControllerFactory();
731 if (!factory)
732 return NULL;
[email protected]d2353452012-01-19 19:53:56733 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22734 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50735 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22736 if (controller) {
737 web_ui->SetController(controller);
738 return web_ui;
739 }
740
741 delete web_ui;
742 return NULL;
743}
744
[email protected]b172aee2012-04-10 17:05:26745content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31746 return render_manager_.web_ui() ? render_manager_.web_ui()
747 : render_manager_.pending_web_ui();
748}
749
[email protected]b172aee2012-04-10 17:05:26750content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31751 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34752}
753
[email protected]86ef6a392012-05-11 22:03:11754void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
755 user_agent_override_ = override;
756}
757
758const std::string& WebContentsImpl::GetUserAgentOverride() const {
759 return user_agent_override_;
760}
761
[email protected]b172aee2012-04-10 17:05:26762const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55763 // Transient entries take precedence. They are used for interstitial pages
764 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23765 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08766 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20767 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30768 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23769 if (entry) {
[email protected]b5cca982011-05-26 04:42:08770 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23771 }
[email protected]7ade2732011-02-10 00:13:58772 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
773 render_manager_.pending_web_ui() : render_manager_.web_ui();
774 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54775 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55776 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54777 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35778 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22779 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54780 if (!title.empty())
781 return title;
782 }
783 }
784
785 // We use the title for the last committed entry rather than a pending
786 // navigation entry. For example, when the user types in a URL, we want to
787 // keep the old page's title until the new load has committed and we get a new
788 // title.
[email protected]96d185d2009-04-24 03:28:54789 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23790 if (entry) {
[email protected]b5cca982011-05-26 04:42:08791 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23792 }
[email protected]987fc3a2011-05-26 14:18:09793
794 // |page_title_when_no_navigation_entry_| is finally used
795 // if no title cannot be retrieved.
796 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54797}
798
[email protected]b172aee2012-04-10 17:05:26799int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46800 return GetMaxPageIDForSiteInstance(GetSiteInstance());
801}
802
[email protected]b172aee2012-04-10 17:05:26803int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
804 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33805 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
806 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46807
[email protected]b6583592012-01-25 19:52:33808 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34809}
810
[email protected]b172aee2012-04-10 17:05:26811void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46812 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
813}
814
[email protected]b172aee2012-04-10 17:05:26815void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33816 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46817 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33818 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34819}
820
[email protected]b172aee2012-04-10 17:05:26821void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
822 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57823}
824
[email protected]b172aee2012-04-10 17:05:26825SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58826 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54827}
828
[email protected]b172aee2012-04-10 17:05:26829SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38830 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
831 render_manager_.pending_render_view_host() :
832 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58833 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38834}
835
[email protected]b172aee2012-04-10 17:05:26836bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31837 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49838}
839
[email protected]b172aee2012-04-10 17:05:26840bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31841 return waiting_for_response_;
842}
843
[email protected]b172aee2012-04-10 17:05:26844const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31845 return load_state_;
846}
847
[email protected]b172aee2012-04-10 17:05:26848const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31849 return load_state_host_;
850}
851
[email protected]b172aee2012-04-10 17:05:26852uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31853 return upload_size_;
854}
855
[email protected]b172aee2012-04-10 17:05:26856uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31857 return upload_position_;
858}
859
[email protected]b172aee2012-04-10 17:05:26860const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31861 return encoding_;
862}
863
[email protected]b172aee2012-04-10 17:05:26864bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31865 return displayed_insecure_content_;
866}
867
[email protected]b172aee2012-04-10 17:05:26868void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31869 capturing_contents_ = cap;
870}
871
[email protected]b172aee2012-04-10 17:05:26872bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31873 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
874 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
875 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49876}
877
[email protected]b172aee2012-04-10 17:05:26878void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
879 int error_code) {
[email protected]443b80e2010-12-14 00:42:23880 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34881 return;
882
[email protected]443b80e2010-12-14 00:42:23883 crashed_status_ = status;
884 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46885 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34886}
887
[email protected]b172aee2012-04-10 17:05:26888base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31889 return crashed_status_;
890}
891
[email protected]b172aee2012-04-10 17:05:26892bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31893 return is_being_destroyed_;
894}
895
[email protected]b172aee2012-04-10 17:05:26896void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34897 if (delegate_)
898 delegate_->NavigationStateChanged(this, changed_flags);
899}
900
[email protected]b172aee2012-04-10 17:05:26901void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54902 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04903 RenderWidgetHostViewPort* rwhv =
904 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16905 if (rwhv) {
906 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43907#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16908 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43909#endif
910 }
[email protected]96d185d2009-04-24 03:28:54911
[email protected]5ac20162010-11-24 23:33:11912 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38913
[email protected]d8c660432011-12-22 20:51:25914 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59915
916 // The resize rect might have changed while this was inactive -- send the new
917 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58918 RenderViewHostImpl* rvh =
919 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59920 if (rvh) {
921 rvh->ResizeRectChanged(GetRootWindowResizerRect());
922 }
[email protected]96d185d2009-04-24 03:28:54923}
924
[email protected]be1f56ab2011-12-22 06:55:31925
[email protected]b172aee2012-04-10 17:05:26926base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31927 return last_selected_time_;
928}
929
[email protected]b172aee2012-04-10 17:05:26930void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31931 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52932 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
933 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26934 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52935 // removes the |GetRenderViewHost()|; then when we actually destroy the
936 // window, OnWindowPosChanged() notices and calls HideContents() (which
937 // calls us).
[email protected]c30585c2012-02-16 15:02:04938 RenderWidgetHostViewPort* rwhv =
939 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16940 if (rwhv)
941 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54942 }
943
[email protected]375fa1b2012-05-22 22:05:37944 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07945 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37946 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09947 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37948 content::Details<bool>(&is_visible));
949}
950
951void WebContentsImpl::WasRestored() {
952 bool is_visible = true;
953 content::NotificationService::current()->Notify(
954 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
955 content::Source<WebContents>(this),
956 content::Details<bool>(&is_visible));
[email protected]96d185d2009-04-24 03:28:54957}
958
[email protected]b172aee2012-04-10 17:05:26959void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04960 RenderWidgetHostViewPort* rwhv =
961 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31962 if (rwhv)
963 rwhv->DidBecomeSelected();
[email protected]375fa1b2012-05-22 22:05:37964 WasRestored();
[email protected]be1f56ab2011-12-22 06:55:31965}
966
[email protected]b172aee2012-04-10 17:05:26967void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31968 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
969 // our superclass HideContents(), because some callers want to be very picky
970 // about the order in which these get called. In addition to making the code
971 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26972 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
973 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31974 WasHidden();
975}
976
[email protected]b172aee2012-04-10 17:05:26977bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31978 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27979 return WillNotifyDisconnection() &&
980 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58981 !static_cast<RenderViewHostImpl*>(
982 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31983}
984
[email protected]b172aee2012-04-10 17:05:26985void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27986 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25987 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27988}
989
[email protected]b172aee2012-04-10 17:05:26990WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44991 // We use our current SiteInstance since the cloned entry will use it anyway.
992 // We pass |this| for the |base_web_contents| to size the view correctly, and
993 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26994 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44995 GetBrowserContext(), GetSiteInstance(),
996 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20997 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27998 return tc;
999}
1000
[email protected]b172aee2012-04-10 17:05:261001void WebContentsImpl::AddNewContents(WebContents* new_contents,
1002 WindowOpenDisposition disposition,
1003 const gfx::Rect& initial_pos,
1004 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271005 if (!delegate_)
1006 return;
1007
1008 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1009 user_gesture);
1010}
1011
[email protected]b172aee2012-04-10 17:05:261012gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271013 return view_->GetContentNativeView();
1014}
1015
[email protected]b172aee2012-04-10 17:05:261016gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271017 return view_->GetNativeView();
1018}
1019
[email protected]b172aee2012-04-10 17:05:261020void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271021 view_->GetContainerBounds(out);
1022}
1023
[email protected]b172aee2012-04-10 17:05:261024void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271025 view_->Focus();
1026}
1027
[email protected]14392a52012-05-02 20:28:441028void WebContentsImpl::Observe(int type,
1029 const content::NotificationSource& source,
1030 const content::NotificationDetails& details) {
1031 switch (type) {
1032 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1033 OnWebContentsDestroyed(
1034 content::Source<content::WebContents>(source).ptr());
1035 break;
[email protected]bafe6cd2012-05-23 23:09:501036 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1037 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1038 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1039 i != pending_widget_views_.end(); ++i) {
1040 if (host->GetView() == i->second) {
1041 pending_widget_views_.erase(i);
1042 break;
1043 }
1044 }
1045 break;
1046 }
[email protected]14392a52012-05-02 20:28:441047 default:
1048 NOTREACHED();
1049 }
1050}
1051
1052void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1053 // Clear the opener if it has been closed.
1054 if (web_contents == opener_) {
1055 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1056 content::Source<WebContents>(opener_));
1057 opener_ = NULL;
1058 }
1059}
1060
[email protected]b172aee2012-04-10 17:05:261061void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311062 observers_.AddObserver(observer);
1063}
1064
[email protected]b172aee2012-04-10 17:05:261065void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311066 observers_.RemoveObserver(observer);
1067}
1068
[email protected]b172aee2012-04-10 17:05:261069void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341070 if (delegate_)
1071 delegate_->ActivateContents(this);
1072}
1073
[email protected]b172aee2012-04-10 17:05:261074void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121075 if (delegate_)
1076 delegate_->DeactivateContents(this);
1077}
1078
[email protected]b172aee2012-04-10 17:05:261079void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481080 if (delegate_)
1081 delegate_->LostCapture();
1082}
1083
[email protected]b172aee2012-04-10 17:05:261084bool WebContentsImpl::PreHandleKeyboardEvent(
1085 const NativeWebKeyboardEvent& event,
1086 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481087 return delegate_ &&
1088 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1089}
1090
[email protected]b172aee2012-04-10 17:05:261091void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481092 if (delegate_)
1093 delegate_->HandleKeyboardEvent(event);
1094}
1095
[email protected]b172aee2012-04-10 17:05:261096void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431097 if (delegate_)
1098 delegate_->HandleMouseDown();
1099}
1100
[email protected]b172aee2012-04-10 17:05:261101void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481102 if (delegate_)
1103 delegate_->HandleMouseUp();
1104}
1105
[email protected]b172aee2012-04-10 17:05:261106void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481107 if (delegate_)
1108 delegate_->HandleMouseActivate();
1109}
1110
[email protected]b172aee2012-04-10 17:05:261111void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471112 if (delegate_)
1113 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1114}
1115
[email protected]b172aee2012-04-10 17:05:261116bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381117 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121118}
1119
[email protected]a9c81f02012-06-01 00:15:441120void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1121 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371122 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441123 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371124 } else {
1125 GotResponseToLockMouseRequest(false);
1126 }
1127}
1128
[email protected]b172aee2012-04-10 17:05:261129void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371130 if (delegate_)
1131 delegate_->LostMouseLock();
1132}
1133
[email protected]bafe6cd2012-05-23 23:09:501134void WebContentsImpl::CreateNewWindow(
1135 int route_id,
[email protected]97714c82012-06-06 10:15:131136 const ViewHostMsg_CreateWindow_Params& params,
1137 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501138 if (delegate_ && !delegate_->ShouldCreateWebContents(
1139 this, route_id, params.window_container_type, params.frame_name,
1140 params.target_url)) {
1141 return;
1142 }
1143
1144 // We usually create the new window in the same BrowsingInstance (group of
1145 // script-related windows), by passing in the current SiteInstance. However,
1146 // if the opener is being suppressed, we create a new SiteInstance in its own
1147 // BrowsingInstance.
1148 scoped_refptr<SiteInstance> site_instance =
1149 params.opener_suppressed ?
1150 SiteInstance::Create(GetBrowserContext()) :
1151 GetSiteInstance();
1152
1153 // Create the new web contents. This will automatically create the new
1154 // WebContentsView. In the future, we may want to create the view separately.
[email protected]97714c82012-06-06 10:15:131155 WebContentsImpl* new_contents = new WebContentsImpl(
1156 GetBrowserContext(),
1157 site_instance,
1158 route_id,
1159 this,
1160 params.opener_suppressed ? NULL : this,
1161 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]bafe6cd2012-05-23 23:09:501162 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1163
1164 if (!params.opener_suppressed) {
1165 content::WebContentsView* new_view = new_contents->GetView();
1166
1167 // TODO(brettw): It seems bogus that we have to call this function on the
1168 // newly created object and give it one of its own member variables.
1169 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1170
1171 // Save the created window associated with the route so we can show it
1172 // later.
1173 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1174 pending_contents_[route_id] = new_contents;
1175 }
1176
1177 if (delegate_) {
1178 delegate_->WebContentsCreated(
1179 this, params.opener_frame_id, params.target_url, new_contents);
1180 }
1181
1182 if (params.opener_suppressed) {
1183 // When the opener is suppressed, the original renderer cannot access the
1184 // new window. As a result, we need to show and navigate the window here.
1185 gfx::Rect initial_pos;
1186 AddNewContents(
1187 new_contents, params.disposition, initial_pos, params.user_gesture);
1188
1189 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1190 CURRENT_TAB,
1191 content::PAGE_TRANSITION_LINK,
1192 true /* is_renderer_initiated */);
1193 new_contents->OpenURL(open_params);
1194 }
1195}
1196
1197void WebContentsImpl::CreateNewWidget(int route_id,
1198 WebKit::WebPopupType popup_type) {
1199 CreateNewWidget(route_id, false, popup_type);
1200}
1201
1202void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1203 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1204}
1205
1206void WebContentsImpl::CreateNewWidget(int route_id,
1207 bool is_fullscreen,
1208 WebKit::WebPopupType popup_type) {
1209 content::RenderProcessHost* process = GetRenderProcessHost();
1210 RenderWidgetHostImpl* widget_host =
1211 new RenderWidgetHostImpl(this, process, route_id);
1212 RenderWidgetHostViewPort* widget_view =
1213 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1214 if (!is_fullscreen) {
1215 // Popups should not get activated.
1216 widget_view->SetPopupType(popup_type);
1217 }
1218 // Save the created widget associated with the route so we can show it later.
1219 pending_widget_views_[route_id] = widget_view;
1220
1221#if defined(OS_MACOSX)
1222 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1223 // to allow it to survive the trip without being hosted.
1224 base::mac::NSObjectRetain(widget_view->GetNativeView());
1225#endif
1226}
1227
1228void WebContentsImpl::ShowCreatedWindow(int route_id,
1229 WindowOpenDisposition disposition,
1230 const gfx::Rect& initial_pos,
1231 bool user_gesture) {
1232 WebContentsImpl* contents = GetCreatedWindow(route_id);
1233 if (contents)
1234 AddNewContents(contents, disposition, initial_pos, user_gesture);
1235}
1236
1237void WebContentsImpl::ShowCreatedWidget(int route_id,
1238 const gfx::Rect& initial_pos) {
1239 ShowCreatedWidget(route_id, false, initial_pos);
1240}
1241
1242void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1243 ShowCreatedWidget(route_id, true, gfx::Rect());
1244}
1245
1246void WebContentsImpl::ShowCreatedWidget(int route_id,
1247 bool is_fullscreen,
1248 const gfx::Rect& initial_pos) {
1249 if (delegate_)
1250 delegate_->RenderWidgetShowing();
1251
1252 RenderWidgetHostViewPort* widget_host_view =
1253 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1254 if (!widget_host_view)
1255 return;
1256 if (is_fullscreen) {
1257 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1258 } else {
1259 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1260 }
[email protected]89054502012-06-03 10:29:241261
1262 RenderWidgetHostImpl* render_widget_host_impl =
1263 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1264 render_widget_host_impl->Init();
1265 // Only allow privileged mouse lock for fullscreen render widget, which is
1266 // used to implement Pepper Flash fullscreen.
1267 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501268
1269#if defined(OS_MACOSX)
1270 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1271 // properly embedded (or purposefully ignored) we can release the retain we
1272 // took in CreateNewWidget().
1273 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1274#endif
1275}
1276
1277WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1278 PendingContents::iterator iter = pending_contents_.find(route_id);
1279
1280 // Certain systems can block the creation of new windows. If we didn't succeed
1281 // in creating one, just return NULL.
1282 if (iter == pending_contents_.end()) {
1283 return NULL;
1284 }
1285
1286 WebContentsImpl* new_contents = iter->second;
1287 pending_contents_.erase(route_id);
1288
1289 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1290 !new_contents->GetRenderViewHost()->GetView())
1291 return NULL;
1292
1293 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1294 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1295 return new_contents;
1296}
1297
1298RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1299 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1300 if (iter == pending_widget_views_.end()) {
1301 DCHECK(false);
1302 return NULL;
1303 }
1304
1305 RenderWidgetHostView* widget_host_view = iter->second;
1306 pending_widget_views_.erase(route_id);
1307
1308 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1309 if (!widget_host->GetProcess()->HasConnection()) {
1310 // The view has gone away or the renderer crashed. Nothing to do.
1311 return NULL;
1312 }
1313
1314 return widget_host_view;
1315}
1316
1317void WebContentsImpl::ShowContextMenu(
1318 const content::ContextMenuParams& params) {
1319 // Allow WebContentsDelegates to handle the context menu operation first.
1320 if (delegate_ && delegate_->HandleContextMenu(params))
1321 return;
1322
[email protected]5a3bdf52012-05-24 15:12:571323 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501324}
1325
[email protected]b172aee2012-04-10 17:05:261326void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231327 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331328 if (delegate_)
1329 delegate_->UpdatePreferredSize(this, pref_size);
1330}
1331
[email protected]b172aee2012-04-10 17:05:261332void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341333 if (delegate_)
1334 delegate_->ResizeDueToAutoResize(this, new_size);
1335}
1336
[email protected]b172aee2012-04-10 17:05:261337WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201338 if (!delegate_)
1339 return NULL;
[email protected]00c37fc2011-08-02 00:22:501340
[email protected]e5d549d2011-12-28 01:29:201341 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1342 // Notify observers.
1343 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1344 DidOpenURL(params.url, params.referrer,
1345 params.disposition, params.transition));
1346 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341347}
1348
[email protected]b172aee2012-04-10 17:05:261349bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501350 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251351 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231352 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251353 reload_type);
[email protected]876bc832010-09-07 16:29:541354}
[email protected]96d185d2009-04-24 03:28:541355
[email protected]ba45bfd2012-05-22 21:51:441356void WebContentsImpl::RenderViewForInterstitialPageCreated(
1357 content::RenderViewHost* render_view_host) {
1358 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1359 RenderViewForInterstitialPageCreated(render_view_host));
1360}
1361
[email protected]b172aee2012-04-10 17:05:261362bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231363 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501364 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401365 // The renderer will reject IPC messages with URLs longer than
1366 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511367 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401368 return false;
1369
[email protected]9f76c1e2012-03-05 15:15:581370 RenderViewHostImpl* dest_render_view_host =
1371 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401372 if (!dest_render_view_host)
1373 return false; // Unable to create the desired render view host.
1374
[email protected]80a8fad2011-01-29 04:02:381375 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071376 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581377 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501378 WebUIControllerFactory* factory =
1379 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271380 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501381 bool is_allowed_in_web_ui_renderer =
1382 factory &&
[email protected]24e18252012-04-16 21:26:271383 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1384 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231385 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1386 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271387 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231388 content::GetContentClient()->SetActiveURL(entry.GetURL());
1389 CHECK(0);
1390 }
[email protected]54ec6472010-04-09 19:39:581391
[email protected]96d185d2009-04-24 03:28:541392 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441393 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521394 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441395 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511396 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541397
1398 // Used for page load time metrics.
1399 current_load_start_ = base::TimeTicks::Now();
1400
1401 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241402 std::string embedder_channel_name;
1403 int embedder_container_id;
1404 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1405 &embedder_channel_name,
1406 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341407 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271408 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241409 embedder_channel_name,
1410 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471411 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341412 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541413
[email protected]36fc0392011-12-25 03:59:511414 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541415 // HACK!! This code suppresses javascript: URLs from being added to
1416 // session history, which is what we want to do for javascript: URLs that
1417 // do not generate content. What we really need is a message from the
1418 // renderer telling us that a new page was not created. The same message
1419 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511420 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541421 return false;
1422 }
1423
[email protected]3c9e1872010-11-18 16:17:491424 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251425 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041426 observers_,
[email protected]36fc0392011-12-25 03:59:511427 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541428
[email protected]09b29342011-06-24 19:18:481429 if (delegate_)
1430 delegate_->DidNavigateToPendingEntry(this);
1431
[email protected]d5f942ba2008-09-26 19:30:341432 return true;
1433}
1434
[email protected]b172aee2012-04-10 17:05:261435void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331436 const SiteInstance* site_instance,
1437 int history_length,
1438 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411439 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1440 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191441 if (render_manager_.pending_render_view_host()) {
1442 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141443 return;
[email protected]9e1ad4b2011-08-14 16:49:191444 }
[email protected]9f76c1e2012-03-05 15:15:581445 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191446 if (!rvh) {
1447 NOTREACHED();
1448 return;
1449 }
[email protected]9f76c1e2012-03-05 15:15:581450 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191451 NOTREACHED();
1452 return;
1453 }
[email protected]9f76c1e2012-03-05 15:15:581454 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191455 history_length,
1456 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141457}
1458
[email protected]b172aee2012-04-10 17:05:261459void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271460 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541461 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1462 return;
1463 }
[email protected]9f76c1e2012-03-05 15:15:581464 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541465}
1466
[email protected]b172aee2012-04-10 17:05:261467bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271468 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541469}
1470
[email protected]b172aee2012-04-10 17:05:261471InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271472 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221473}
1474
[email protected]b172aee2012-04-10 17:05:261475bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161476 // WebKit creates Document object when MIME type is application/xhtml+xml,
1477 // so we also support this MIME type.
1478 return contents_mime_type_ == "text/html" ||
1479 contents_mime_type_ == "text/xml" ||
1480 contents_mime_type_ == "application/xhtml+xml" ||
1481 contents_mime_type_ == "text/plain" ||
1482 contents_mime_type_ == "text/css" ||
1483 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1484}
1485
[email protected]b172aee2012-04-10 17:05:261486void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591487 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161488 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481489 download_stats::RecordDownloadSource(
1490 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461491 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141492 return;
[email protected]c7dd2f62011-07-18 15:57:591493 }
1494
1495 Stop();
1496
1497 // Create the save package and possibly prompt the user for the name to save
1498 // the page as. The user prompt is an asynchronous operation that runs on
1499 // another thread.
1500 save_package_ = new SavePackage(this);
1501 save_package_->GetSaveInfo();
1502}
1503
1504// Used in automated testing to bypass prompting the user for file names.
1505// Instead, the names and paths are hard coded rather than running them through
1506// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261507bool WebContentsImpl::SavePage(const FilePath& main_file,
1508 const FilePath& dir_path,
1509 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591510 // Stop the page from navigating.
1511 Stop();
1512
1513 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271514 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591515}
1516
[email protected]b172aee2012-04-10 17:05:261517void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121518 const FilePath& file,
1519 const base::Callback<void(const FilePath&, int64)>& callback) {
1520 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1521}
1522
[email protected]b172aee2012-04-10 17:05:261523bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231524 NavigationEntryImpl* active_entry =
1525 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321526 return (active_entry != NULL &&
1527 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511528 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321529}
1530
[email protected]b172aee2012-04-10 17:05:261531const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271532 return contents_mime_type_;
1533}
1534
[email protected]b172aee2012-04-10 17:05:261535bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271536 return notify_disconnection_;
1537}
1538
[email protected]b172aee2012-04-10 17:05:261539void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311540 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581541 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1542 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161543}
1544
[email protected]b172aee2012-04-10 17:05:261545void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311546 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581547 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1548 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161549}
1550
[email protected]b172aee2012-04-10 17:05:261551content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271552 return &renderer_preferences_;
1553}
1554
[email protected]b172aee2012-04-10 17:05:261555void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271556 new_tab_start_time_ = time;
1557}
1558
[email protected]b172aee2012-04-10 17:05:261559base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271560 return new_tab_start_time_;
1561}
1562
[email protected]e35ccd52012-05-23 16:22:471563void WebContentsImpl::Close() {
1564 Close(GetRenderViewHost());
1565}
1566
[email protected]b172aee2012-04-10 17:05:261567void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151568 if (close_start_time_.is_null())
1569 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011570}
1571
[email protected]b172aee2012-04-10 17:05:261572bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191573#if defined(OS_CHROMEOS)
1574 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1575 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511576 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201577 return false;
1578 return true;
[email protected]46624bf2010-06-09 16:04:191579#else
1580 return true;
1581#endif
1582}
1583
[email protected]b172aee2012-04-10 17:05:261584void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521585 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581586 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511587 if (delegate_)
1588 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341589}
1590
[email protected]e35ccd52012-05-23 16:22:471591void WebContentsImpl::UserGestureDone() {
1592 OnUserGesture();
1593}
1594
[email protected]b172aee2012-04-10 17:05:261595void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271596 closed_by_user_gesture_ = value;
1597}
1598
[email protected]b172aee2012-04-10 17:05:261599bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271600 return closed_by_user_gesture_;
1601}
1602
[email protected]b172aee2012-04-10 17:05:261603double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051604 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561605 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251606 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171607 return 0;
[email protected]b75b8292010-10-01 07:28:251608
1609 double zoom_level;
1610 if (temporary_zoom_settings_) {
1611 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581612 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251613 } else {
[email protected]2ae88d12011-10-14 09:11:191614 GURL url;
[email protected]10f417c52011-12-28 21:04:231615 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191616 // Since zoom map is updated using rewritten URL, use rewritten URL
1617 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511618 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191619 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251620 }
[email protected]d0b8d092010-10-25 04:05:171621 return zoom_level;
1622}
[email protected]b75b8292010-10-01 07:28:251623
[email protected]b172aee2012-04-10 17:05:261624int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1625 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171626 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011627 // Calculate the zoom percent from the factor. Round up to the nearest whole
1628 // number.
[email protected]b75b8292010-10-01 07:28:251629 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011630 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251631 *enable_decrement = percent > minimum_zoom_percent_;
1632 *enable_increment = percent < maximum_zoom_percent_;
1633 return percent;
1634}
1635
[email protected]b172aee2012-04-10 17:05:261636void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501637 if (!delegate_)
1638 return;
1639
[email protected]10f417c52011-12-28 21:04:231640 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501641 if (!active_entry)
1642 return;
1643
[email protected]36fc0392011-12-25 03:59:511644 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121645}
1646
[email protected]b172aee2012-04-10 17:05:261647void WebContentsImpl::ViewFrameSource(const GURL& url,
1648 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271649 if (!delegate_)
1650 return;
1651
1652 delegate_->ViewSourceForFrame(this, url, content_state);
1653}
1654
[email protected]b172aee2012-04-10 17:05:261655int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271656 return minimum_zoom_percent_;
1657}
1658
[email protected]b172aee2012-04-10 17:05:261659int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271660 return maximum_zoom_percent_;
1661}
1662
[email protected]b172aee2012-04-10 17:05:261663gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231664 return preferred_size_;
1665}
1666
[email protected]b172aee2012-04-10 17:05:261667int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271668 return content_restrictions_;
1669}
1670
[email protected]b172aee2012-04-10 17:05:261671WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501672 WebUIControllerFactory* factory =
1673 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1674 if (!factory)
1675 return WebUI::kNoWebUI;
1676 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271677}
1678
[email protected]b172aee2012-04-10 17:05:261679content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271680 // When there is a pending navigation entry, we want to use the pending WebUI
1681 // that goes along with it to control the basic flags. For example, we want to
1682 // show the pending URL in the URL bar, so we want the display_url flag to
1683 // be from the pending entry.
1684 //
1685 // The confusion comes because there are multiple possibilities for the
1686 // initial load in a tab as a side effect of the way the RenderViewHostManager
1687 // works.
1688 //
1689 // - For the very first tab the load looks "normal". The new tab Web UI is
1690 // the pending one, and we want it to apply here.
1691 //
1692 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1693 // get switched to the one previously associated with the new tab pages.
1694 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1695 // have a committed Web UI in this case.
1696 //
1697 // This condition handles all of these cases:
1698 //
1699 // - First load in first tab: no committed nav entry + pending nav entry +
1700 // pending dom ui:
1701 // -> Use pending Web UI if any.
1702 //
1703 // - First load in second tab: no committed nav entry + pending nav entry +
1704 // no pending Web UI:
1705 // -> Use the committed Web UI if any.
1706 //
1707 // - Second navigation in any tab: committed nav entry + pending nav entry:
1708 // -> Use pending Web UI if any.
1709 //
1710 // - Normal state with no load: committed nav entry + no pending nav entry:
1711 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251712 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271713 (controller_.GetLastCommittedEntry() ||
1714 render_manager_.pending_web_ui()))
1715 return render_manager_.pending_web_ui();
1716 return render_manager_.web_ui();
1717}
1718
[email protected]b172aee2012-04-10 17:05:261719bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271720 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581721 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271722}
1723
[email protected]b172aee2012-04-10 17:05:261724bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441725 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501726}
1727
[email protected]b172aee2012-04-10 17:05:261728void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321729 SkColor color) {
[email protected]da8543762012-03-20 08:52:201730 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1731 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1732}
1733
[email protected]b172aee2012-04-10 17:05:261734void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201735 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1736 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1737 if (delegate_)
1738 delegate_->DidEndColorChooser();
1739 color_chooser_ = NULL;
1740}
1741
[email protected]b172aee2012-04-10 17:05:261742bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471743 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271744 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221745 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231746 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411747 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271748}
1749
[email protected]b172aee2012-04-10 17:05:261750void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271751 if (delegate_)
1752 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211753}
1754
[email protected]3a3b75a2012-06-01 08:38:361755void WebContentsImpl::OnRegisterIntentService(
1756 const webkit_glue::WebIntentServiceData& data,
1757 bool user_gesture) {
1758 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301759}
1760
[email protected]b172aee2012-04-10 17:05:261761void WebContentsImpl::OnWebIntentDispatch(
1762 const webkit_glue::WebIntentData& intent,
1763 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001764 WebIntentsDispatcherImpl* intents_dispatcher =
1765 new WebIntentsDispatcherImpl(this, intent, intent_id);
1766 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301767}
1768
[email protected]54047eb52012-05-08 21:45:571769void WebContentsImpl::DidStartProvisionalLoadForFrame(
1770 content::RenderViewHost* render_view_host,
1771 int64 frame_id,
1772 bool is_main_frame,
1773 const GURL& opener_url,
1774 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281775 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181776 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451777 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571778 content::RenderProcessHost* render_process_host =
1779 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161780 RenderViewHostImpl::FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581781 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571782 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451783 false,
[email protected]9f76c1e2012-03-05 15:15:581784 &validated_url);
[email protected]97d402f32012-06-01 02:55:161785 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451786 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571787 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451788 true,
1789 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181790
[email protected]0d60f0192011-04-14 12:40:101791 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251792 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101793 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571794 validated_url, is_error_page, render_view_host));
[email protected]0d60f0192011-04-14 12:40:101795
[email protected]724159a2010-12-30 01:11:181796 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591797 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251798 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451799 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]ef16c3e2012-05-16 22:13:461800 validated_opener_url,
1801 render_view_host));
[email protected]724159a2010-12-30 01:11:181802 }
1803}
1804
[email protected]54047eb52012-05-08 21:45:571805void WebContentsImpl::DidRedirectProvisionalLoad(
1806 content::RenderViewHost* render_view_host,
1807 int32 page_id,
1808 const GURL& opener_url,
1809 const GURL& source_url,
1810 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491811 // TODO(creis): Remove this method and have the pre-rendering code listen to
1812 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1813 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451814 GURL validated_source_url(source_url);
1815 GURL validated_target_url(target_url);
1816 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571817 content::RenderProcessHost* render_process_host =
1818 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161819 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451820 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571821 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451822 false,
1823 &validated_source_url);
[email protected]97d402f32012-06-01 02:55:161824 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451825 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571826 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451827 false,
1828 &validated_target_url);
[email protected]97d402f32012-06-01 02:55:161829 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451830 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571831 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451832 true,
1833 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231834 NavigationEntry* entry;
[email protected]54047eb52012-05-08 21:45:571835 if (page_id == -1) {
[email protected]022af742011-12-28 18:37:251836 entry = controller_.GetPendingEntry();
[email protected]54047eb52012-05-08 21:45:571837 } else {
1838 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1839 page_id);
1840 }
[email protected]6b7cd8f2012-03-21 21:02:451841 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181842 return;
[email protected]e7d50892011-01-19 21:47:381843
[email protected]4850a7f2011-03-08 23:36:591844 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251845 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451846 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]ef16c3e2012-05-16 22:13:461847 validated_opener_url,
1848 render_view_host));
[email protected]724159a2010-12-30 01:11:181849}
1850
[email protected]54047eb52012-05-08 21:45:571851void WebContentsImpl::DidFailProvisionalLoadWithError(
1852 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581853 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1854 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1855 << ", error_code: " << params.error_code
1856 << ", error_description: " << params.error_description
1857 << ", is_main_frame: " << params.is_main_frame
1858 << ", showing_repost_interstitial: " <<
1859 params.showing_repost_interstitial
1860 << ", frame_id: " << params.frame_id;
1861 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571862 content::RenderProcessHost* render_process_host =
1863 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161864 RenderViewHostImpl::FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581865 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571866 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451867 false,
[email protected]9f76c1e2012-03-05 15:15:581868 &validated_url);
[email protected]724159a2010-12-30 01:11:181869
[email protected]d7b175e2011-10-11 15:31:581870 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181871 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1872 // This means that the interstitial won't be torn down properly, which is
1873 // bad. But if we have an interstitial, go back to another tab type, and
1874 // then load the same interstitial again, we could end up getting the first
1875 // interstitial's "failed" message (as a result of the cancel) when we're on
1876 // the second one.
1877 //
1878 // We can't tell this apart, so we think we're tearing down the current page
1879 // which will cause a crash later one. There is also some code in
1880 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1881 // out because of this problem.
1882 //
1883 // http://code.google.com/p/chromium/issues/detail?id=2855
1884 // Because this will not tear down the interstitial properly, if "back" is
1885 // back to another tab type, the interstitial will still be somewhat alive
1886 // in the previous tab type. If you navigate somewhere that activates the
1887 // tab with the interstitial again, you'll see a flash before the new load
1888 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271889 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181890 LOG(WARNING) << "Discarding message during interstitial.";
1891 return;
1892 }
1893
[email protected]02102f82011-06-13 20:37:021894 // Discard our pending entry if the load canceled (e.g. if we decided to
1895 // download the file instead of load it). We do not verify that the URL
1896 // being canceled matches the pending entry's URL because they will not
1897 // match if a redirect occurred (in which case we do not want to leave a
1898 // stale redirect URL showing). This means that we also cancel the pending
1899 // entry if the user started a new navigation. As a result, the navigation
1900 // controller may not remember that a load is in progress, but the
1901 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251902 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161903 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181904
[email protected]54047eb52012-05-08 21:45:571905 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181906 }
1907
[email protected]d8c660432011-12-22 20:51:251908 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581909 observers_,
1910 DidFailProvisionalLoad(params.frame_id,
1911 params.is_main_frame,
1912 validated_url,
1913 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461914 params.error_description,
1915 render_view_host));
[email protected]724159a2010-12-30 01:11:181916}
1917
[email protected]b172aee2012-04-10 17:05:261918void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181919 const GURL& url,
[email protected]70435962011-08-02 20:13:281920 const std::string& security_info,
1921 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181922 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281923 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191924 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181925 cache.Increment();
1926
1927 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081928 int cert_id = 0;
1929 net::CertStatus cert_status = 0;
1930 int security_bits = -1;
1931 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511932 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1933 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301934 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]6d6cfb3a2012-05-23 22:53:181935 cert_id, cert_status, http_method,
1936 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181937
[email protected]ad50def52011-10-19 23:17:071938 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271939 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501940 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531941 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181942}
1943
[email protected]b172aee2012-04-10 17:05:261944void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381945 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181946 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201947 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181948}
1949
[email protected]b172aee2012-04-10 17:05:261950void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021951 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231952 LOG(INFO) << security_origin << " ran insecure content from "
1953 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381954 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411955 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1956 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181957 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411958 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201959 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181960}
1961
[email protected]b172aee2012-04-10 17:05:261962void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181963 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251964 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101965 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181966}
1967
[email protected]b172aee2012-04-10 17:05:261968void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311969 int64 frame_id,
1970 const GURL& validated_url,
1971 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251972 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311973 DidFinishLoad(frame_id, validated_url, is_main_frame));
1974}
1975
[email protected]b172aee2012-04-10 17:05:261976void WebContentsImpl::OnDidFailLoadWithError(
1977 int64 frame_id,
1978 const GURL& validated_url,
1979 bool is_main_frame,
1980 int error_code,
1981 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251982 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311983 DidFailLoad(frame_id, validated_url, is_main_frame,
1984 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181985}
1986
[email protected]b172aee2012-04-10 17:05:261987void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271988 content_restrictions_ = restrictions;
1989 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171990}
1991
[email protected]b172aee2012-04-10 17:05:261992void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261993 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231994 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251995 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261996 if (!entry)
1997 return;
1998 // Note that we don't call NavigationController::GotToOffset() as we don't
1999 // want to create a pending navigation entry (it might end up lingering
2000 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252001 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582002 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512003 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582004 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472005 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572006
2007 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2008 // it in now that we know. This allows us to find the entry when it commits.
2009 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232010 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332011 entry->set_site_instance(
2012 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572013 }
[email protected]216813952011-05-19 22:21:262014 }
2015}
2016
[email protected]b172aee2012-04-10 17:05:262017void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2018 int maximum_percent,
2019 bool remember) {
[email protected]216813952011-05-19 22:21:262020 minimum_zoom_percent_ = minimum_percent;
2021 maximum_zoom_percent_ = maximum_percent;
2022 temporary_zoom_settings_ = !remember;
2023}
2024
[email protected]20b433a2012-05-15 21:23:462025void WebContentsImpl::OnSaveURL(const GURL& url,
2026 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482027 download_stats::RecordDownloadSource(
2028 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262029 // Check if the URL to save matches the URL of the main frame. Since this
2030 // message originates from Pepper plugins, it may not be the case if the
2031 // plugin is an embedded element.
2032 GURL main_frame_url = GetURL();
2033 if (!main_frame_url.is_valid())
2034 return;
2035 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462036 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272037}
2038
[email protected]b172aee2012-04-10 17:05:262039void WebContentsImpl::OnEnumerateDirectory(int request_id,
2040 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:592041 ChildProcessSecurityPolicyImpl* policy =
2042 ChildProcessSecurityPolicyImpl::GetInstance();
2043 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2044 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212045}
2046
[email protected]b172aee2012-04-10 17:05:262047void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:512048 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202049}
2050
[email protected]b172aee2012-04-10 17:05:262051void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2052 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362053 const string16& title,
2054 bool user_gesture) {
[email protected]b9535422012-02-09 01:47:592055 ChildProcessSecurityPolicyImpl* policy =
2056 ChildProcessSecurityPolicyImpl::GetInstance();
2057 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2058 return;
[email protected]3a3b75a2012-06-01 08:38:362059 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202060}
2061
[email protected]b172aee2012-04-10 17:05:262062void WebContentsImpl::OnFindReply(int request_id,
2063 int number_of_matches,
2064 const gfx::Rect& selection_rect,
2065 int active_match_ordinal,
2066 bool final_update) {
[email protected]6934a702011-12-20 00:04:512067 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2068 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:002069 // Send a notification to the renderer that we are ready to receive more
2070 // results from the scoping effort of the Find operation. The FindInPage
2071 // scoping is asynchronous and periodically sends results back up to the
2072 // browser using IPC. In an effort to not spam the browser we have the
2073 // browser send an ACK for each FindReply message and have the renderer
2074 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582075 GetRenderViewHostImpl()->Send(
2076 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162077}
2078
[email protected]b172aee2012-04-10 17:05:262079void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442080 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2081 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452082}
2083
[email protected]b172aee2012-04-10 17:05:262084void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2085 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102086 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252087 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102088 AppCacheAccessed(manifest_url, blocked_by_policy));
2089}
2090
[email protected]b172aee2012-04-10 17:05:262091void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322092 SkColor color) {
[email protected]da8543762012-03-20 08:52:202093 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
2094}
2095
[email protected]b172aee2012-04-10 17:05:262096void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202097 if (color_chooser_ &&
2098 color_chooser_id == color_chooser_->identifier())
2099 color_chooser_->End();
2100}
2101
[email protected]b172aee2012-04-10 17:05:262102void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322103 SkColor color) {
[email protected]da8543762012-03-20 08:52:202104 if (color_chooser_ &&
2105 color_chooser_id == color_chooser_->identifier())
2106 color_chooser_->SetSelectedColor(color);
2107}
2108
[email protected]9f2a9d72012-04-16 16:02:222109void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2110 const FilePath& path,
2111 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442112 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2113 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292114}
2115
[email protected]d0759f492012-04-19 22:50:502116// This exists for render views that don't have a WebUI, but do have WebUI
2117// bindings enabled.
2118void WebContentsImpl::OnWebUISend(const GURL& source_url,
2119 const std::string& name,
2120 const base::ListValue& args) {
2121 if (delegate_)
2122 delegate_->WebUISend(this, source_url, name, args);
2123}
2124
[email protected]96d185d2009-04-24 03:28:542125// Notifies the RenderWidgetHost instance about the fact that the page is
2126// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262127void WebContentsImpl::SetIsLoading(bool is_loading,
2128 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542129 if (is_loading == is_loading_)
2130 return;
2131
2132 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212133 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542134 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562135 upload_size_ = 0;
2136 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542137 }
2138
2139 render_manager_.SetIsLoading(is_loading);
2140
2141 is_loading_ = is_loading;
2142 waiting_for_response_ = is_loading;
2143
[email protected]6ebdc9b2010-09-27 16:55:572144 if (delegate_)
2145 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462146 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542147
[email protected]432115822011-07-10 15:52:272148 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2149 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072150 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542151 if (details)
[email protected]6c2381d2011-10-19 02:52:532152 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072153 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502154 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542155 det);
2156}
2157
[email protected]b172aee2012-04-10 17:05:262158void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132159 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322160 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562161 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382162 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442163 // that opened the window, as long as both renderers have the same
2164 // privileges.
[email protected]1fd1a502011-03-30 16:55:562165 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562166 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582167 // web_ui might be NULL if the URL refers to a non-existent extension.
2168 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402169 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522170 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442171 }
2172 }
[email protected]1fd1a502011-03-30 16:55:562173 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442174 }
2175
[email protected]4e697b042011-07-08 06:44:562176 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322177 // Clear the status bubble. This is a workaround for a bug where WebKit
2178 // doesn't let us know that the cursor left an element during a
2179 // transition (this is also why the mouse cursor remains as a hand after
2180 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2181 // clear the bubble when a user navigates to a named anchor in the same
2182 // page.
[email protected]36fc0392011-12-25 03:59:512183 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322184 }
2185
[email protected]a6e82fc2010-02-24 22:28:142186 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472187 // Once the main frame is navigated, we're no longer considered to have
2188 // displayed insecure content.
2189 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172190 }
[email protected]ce5c4502009-05-06 16:46:112191
[email protected]3c9e1872010-11-18 16:17:492192 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252193 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042194 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322195}
2196
[email protected]b172aee2012-04-10 17:05:262197void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322198 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132199 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322200 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062201 // If we navigate off the page, reset JavaScript state. This does nothing
2202 // to prevent a malicious script from spamming messages, since the script
2203 // could just reload the page to stop blocking.
2204 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552205 dialog_creator_->ResetJavaScriptState(this);
2206 dialog_creator_ = NULL;
2207 }
[email protected]420ae012009-04-24 05:16:322208
[email protected]3c9e1872010-11-18 16:17:492209 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252210 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042211 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322212}
2213
[email protected]b172aee2012-04-10 17:05:262214void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462215 // If we are creating a RVH for a restored controller, then we need to make
2216 // sure the RenderView starts with a next_page_id_ larger than the number
2217 // of restored entries. This must be called before the RenderView starts
2218 // navigating (to avoid a race between the browser updating max_page_id and
2219 // the renderer updating next_page_id_). Because of this, we only call this
2220 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562221 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582222 if (max_restored_page_id >
2223 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2224 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2225 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322226}
2227
[email protected]b172aee2012-04-10 17:05:262228bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2229 const string16& title) {
[email protected]420ae012009-04-24 05:16:322230 // For file URLs without a title, use the pathname instead. In the case of a
2231 // synthesized title, we don't want the update to count toward the "one set
2232 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512233 string16 final_title;
[email protected]420ae012009-04-24 05:16:322234 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512235 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2236 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322237 explicit_set = false; // Don't count synthetic titles toward the set limit.
2238 } else {
[email protected]acafd272011-07-26 17:35:572239 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322240 explicit_set = true;
2241 }
2242
[email protected]987fc3a2011-05-26 14:18:092243 // If a page is created via window.open and never navigated,
2244 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552245 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092246 if (entry) {
[email protected]36fc0392011-12-25 03:59:512247 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092248 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322249
[email protected]36fc0392011-12-25 03:59:512250 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092251 } else {
2252 if (page_title_when_no_navigation_entry_ == final_title)
2253 return false; // Nothing changed, don't bother.
2254
2255 page_title_when_no_navigation_entry_ = final_title;
2256 }
[email protected]420ae012009-04-24 05:16:322257
[email protected]420ae012009-04-24 05:16:322258 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232259 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322260
[email protected]2bb171882012-03-07 02:09:462261 std::pair<content::NavigationEntry*, bool> details =
2262 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142263
[email protected]ad50def52011-10-19 23:17:072264 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442265 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2266 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462267 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042268
[email protected]420ae012009-04-24 05:16:322269 return true;
2270}
2271
[email protected]b172aee2012-04-10 17:05:262272void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322273 // After sending out a swap notification, we need to send a disconnect
2274 // notification so that clients that pick up a pointer to |this| can NULL the
2275 // pointer. See Bug 1230284.
2276 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072277 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202278 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2279 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072280 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322281}
2282
[email protected]b172aee2012-04-10 17:05:262283void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322284 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072285 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122286 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2287 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072288 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322289}
2290
[email protected]b172aee2012-04-10 17:05:262291void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322292 if (!notify_disconnection_)
2293 return;
2294
2295 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072296 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322297 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2298 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072299 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322300}
2301
[email protected]5a3bdf52012-05-24 15:12:572302RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2303 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322304}
2305
[email protected]8d3347f2009-07-09 22:00:212306RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262307WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212308 return &render_manager_;
2309}
2310
[email protected]b172aee2012-04-10 17:05:262311content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372312 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462313 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512314}
2315
[email protected]b172aee2012-04-10 17:05:262316WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172317 return this;
2318}
2319
[email protected]b172aee2012-04-10 17:05:262320gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172321 if (delegate_)
2322 return delegate_->GetRootWindowResizerRect();
2323 return gfx::Rect();
2324}
2325
[email protected]b172aee2012-04-10 17:05:262326void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442327 // Don't send notifications if we are just creating a swapped-out RVH for
2328 // the opener chain. These won't be used for view-source or WebUI, so it's
2329 // ok to return early.
2330 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2331 return;
2332
[email protected]ad50def52011-10-19 23:17:072333 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272334 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322335 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532336 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232337 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322338 if (!entry)
2339 return;
2340
2341 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352342 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562343 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582344 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322345
2346 if (entry->IsViewSourceMode()) {
2347 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582348 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2349 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322350 }
[email protected]0666aef2009-05-13 19:48:082351
[email protected]d487beefe2011-12-21 05:41:212352 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262353
2354 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252355 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322356}
2357
[email protected]b172aee2012-04-10 17:05:262358void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522359 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322360 // Don't notify the world, since this came from a renderer in the
2361 // background.
2362 return;
2363 }
2364
2365 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312366 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232367 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302368
2369 // Restore the focus to the tab (otherwise the focus will be on the top
2370 // window).
[email protected]484ae5912010-09-29 19:16:142371 if (was_crashed && !FocusLocationBarByDefault() &&
2372 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302373 Focus();
[email protected]484ae5912010-09-29 19:16:142374 }
[email protected]32ded2212011-11-10 18:51:432375
[email protected]d8c660432011-12-22 20:51:252376 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322377}
2378
[email protected]b172aee2012-04-10 17:05:262379void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2380 base::TerminationStatus status,
2381 int error_code) {
[email protected]151a63d2011-12-20 22:32:522382 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322383 // The pending page's RenderViewHost is gone.
2384 return;
2385 }
2386
2387 SetIsLoading(false, NULL);
2388 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232389 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312390 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322391
[email protected]d8c660432011-12-22 20:51:252392 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272393 observers_,
[email protected]be1f56ab2011-12-22 06:55:312394 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322395}
2396
[email protected]b172aee2012-04-10 17:05:262397void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482398 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252399 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062400}
2401
[email protected]b172aee2012-04-10 17:05:262402void WebContentsImpl::DidNavigate(
2403 RenderViewHost* rvh,
2404 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582405 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322406 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372407
[email protected]434f69f2012-02-06 21:56:522408 // Update the site of the SiteInstance if it doesn't have one yet, unless
2409 // this is for about:blank. In that case, the SiteInstance can still be
2410 // considered unused until a navigation to a real page.
2411 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2412 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332413 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522414 }
[email protected]420ae012009-04-24 05:16:322415
2416 // Need to update MIME type here because it's referred to in
2417 // UpdateNavigationCommands() called by RendererDidNavigate() to
2418 // determine whether or not to enable the encoding menu.
2419 // It's updated only for the main frame. For a subframe,
2420 // RenderView::UpdateURL does not set params.contents_mime_type.
2421 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2422 // TODO(jungshik): Add a test for the encoding menu to avoid
2423 // regressing it again.
[email protected]2905f742011-10-13 03:51:582424 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322425 contents_mime_type_ = params.contents_mime_type;
2426
[email protected]8286f51a2011-05-31 17:39:132427 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002428 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392429
[email protected]a9c0bfe2010-09-17 08:35:222430 // Send notification about committed provisional loads. This notification is
2431 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2432 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082433 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072434 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2435 // that is not recorded in the navigation history. For the purpose of
2436 // tracking navigation events, we treat this event as a sub frame navigation
2437 // event.
2438 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582439 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222440 // Whether or not a page transition was triggered by going backward or
2441 // forward in the history is only stored in the navigation controller's
2442 // entry list.
2443 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512444 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582445 content::PAGE_TRANSITION_FORWARD_BACK)) {
2446 transition_type = content::PageTransitionFromInt(
2447 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222448 }
[email protected]0d60f0192011-04-14 12:40:102449 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252450 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102451 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462452 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222453 }
2454
[email protected]76543b92009-08-31 17:27:452455 if (!did_navigate)
2456 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322457
2458 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2459 // for the appropriate notification (best) or you can add it to
2460 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2461 // necessary, please).
2462
2463 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002464 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322465 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512466 if (delegate_)
2467 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002468 }
[email protected]420ae012009-04-24 05:16:322469 DidNavigateAnyFramePostCommit(rvh, details, params);
2470}
2471
[email protected]b172aee2012-04-10 17:05:262472void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2473 int32 page_id,
2474 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152475 // Ensure that this state update comes from either the active RVH or one of
2476 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522477 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322478
2479 // We must be prepared to handle state updates for any page, these occur
2480 // when the user is scrolling and entering form data, as well as when we're
2481 // leaving a page, in which case our state may have already been moved to
2482 // the next page. The navigation controller will look up the appropriate
2483 // NavigationEntry and update it when it is notified via the delegate.
2484
2485 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582486 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322487 if (entry_index < 0)
2488 return;
[email protected]10f417c52011-12-28 21:04:232489 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322490
[email protected]36fc0392011-12-25 03:59:512491 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322492 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512493 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322494 controller_.NotifyEntryChanged(entry, entry_index);
2495}
2496
[email protected]b172aee2012-04-10 17:05:262497void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2498 int32 page_id,
2499 const string16& title,
2500 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322501 // If we have a title, that's a pretty good indication that we've started
2502 // getting useful data.
2503 SetNotWaitingForResponse();
2504
[email protected]73eb2602012-02-09 19:50:552505 // Try to find the navigation entry, which might not be the current one.
2506 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232507 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582508 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092509
[email protected]73eb2602012-02-09 19:50:552510 // We can handle title updates when we don't have an entry in
2511 // UpdateTitleForEntry, but only if the update is from the current RVH.
2512 if (!entry && rvh != GetRenderViewHost())
2513 return;
2514
[email protected]a49e10b2011-08-01 23:57:462515 // TODO(evan): make use of title_direction.
2516 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092517 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322518 return;
2519
2520 // Broadcast notifications when the UI should be updated.
2521 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462522 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322523}
2524
[email protected]b172aee2012-04-10 17:05:262525void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2526 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312527 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322528}
2529
[email protected]b172aee2012-04-10 17:05:262530void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512531 if (delegate_)
2532 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322533}
2534
[email protected]b172aee2012-04-10 17:05:262535void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292536 // The UI may be in an event-tracking loop, such as between the
2537 // mouse-down and mouse-up in text selection or a button click.
2538 // Defer the close until after tracking is complete, so that we
2539 // don't free objects out from under the UI.
2540 // TODO(shess): This could probably be integrated with the
2541 // IsDoingDrag() test below. Punting for now because I need more
2542 // research to understand how this impacts platforms other than Mac.
2543 // TODO(shess): This could get more fine-grained. For instance,
2544 // closing a tab in another window while selecting text in the
2545 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212546 if (GetView()->IsEventTracking()) {
2547 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292548 return;
2549 }
2550
[email protected]24a4d1062009-07-10 23:10:422551 // If we close the tab while we're in the middle of a drag, we'll crash.
2552 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212553 if (GetView()->IsDoingDrag()) {
2554 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422555 return;
2556 }
2557
[email protected]420ae012009-04-24 05:16:322558 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522559 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512560 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322561}
2562
[email protected]b172aee2012-04-10 17:05:262563void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522564 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512565 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572566}
2567
[email protected]b172aee2012-04-10 17:05:262568void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512569 if (delegate_ && delegate_->IsPopupOrPanel(this))
2570 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322571}
2572
[email protected]b172aee2012-04-10 17:05:262573void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322574 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492575
[email protected]82114f52012-03-20 22:53:412576 if (delegate_ && content_restrictions_)
2577 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492578
2579 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252580 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322581}
2582
[email protected]b172aee2012-04-10 17:05:262583void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322584 scoped_ptr<LoadNotificationDetails> details;
2585
[email protected]10f417c52011-12-28 21:04:232586 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322587 // An entry may not exist for a stop when loading an initial blank page or
2588 // if an iframe injected by script into a blank page finishes loading.
2589 if (entry) {
[email protected]420ae012009-04-24 05:16:322590 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2591
2592 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512593 entry->GetVirtualURL(),
2594 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322595 elapsed,
2596 &controller_,
2597 controller_.GetCurrentEntryIndex()));
2598 }
2599
[email protected]420ae012009-04-24 05:16:322600 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492601
2602 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252603 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322604}
2605
[email protected]b172aee2012-04-10 17:05:262606void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162607 controller_.DiscardNonCommittedEntries();
2608
2609 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462610 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162611}
2612
[email protected]b172aee2012-04-10 17:05:262613void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512614 if (delegate_)
2615 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402616}
2617
[email protected]87717d0e2012-04-26 02:58:432618void WebContentsImpl::DocumentAvailableInMainFrame(
2619 RenderViewHost* render_view_host) {
2620 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2621 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102622}
2623
[email protected]b172aee2012-04-10 17:05:262624void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082625 RenderViewHost* render_view_host,
2626 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072627 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272628 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322629 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532630 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082631}
2632
[email protected]196159d2012-05-04 17:26:542633void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2634 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262635 const content::Referrer& referrer,
2636 WindowOpenDisposition disposition,
2637 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542638 // If this came from a swapped out RenderViewHost, we only allow the request
2639 // if we are still in the same BrowsingInstance.
2640 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2641 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2642 return;
2643 }
2644
[email protected]4ad5d77d2011-12-03 02:00:482645 // Delegate to RequestTransferURL because this is just the generic
2646 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582647 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482648 GlobalRequestID());
2649}
2650
[email protected]b172aee2012-04-10 17:05:262651void WebContentsImpl::RequestTransferURL(
2652 const GURL& url,
2653 const content::Referrer& referrer,
2654 WindowOpenDisposition disposition,
2655 int64 source_frame_id,
2656 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202657 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582658 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582659 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352660 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322661 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2662 // generated suggestions).
2663 //
[email protected]e0112912011-02-02 22:54:352664 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162665 // want web sites to see a referrer of "chrome://blah" (and some
2666 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322667 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432668 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222669 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482670 false /* is_renderer_initiated */);
2671 params.transferred_global_request_id = old_request_id;
2672 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222673 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322674 } else {
[email protected]6bf6a6b52012-02-03 15:41:432675 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482676 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2677 params.transferred_global_request_id = old_request_id;
2678 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582679 }
2680 if (new_contents) {
2681 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252682 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582683 DidOpenRequestedURL(new_contents,
2684 url,
2685 referrer,
2686 disposition,
2687 transition_type,
2688 source_frame_id));
[email protected]420ae012009-04-24 05:16:322689 }
2690}
2691
[email protected]e1c3a552012-05-04 20:51:322692void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2693 // Tell the active RenderViewHost to run unload handlers and close, as long
2694 // as the request came from a RenderViewHost in the same BrowsingInstance.
2695 // In most cases, we receive this from a swapped out RenderViewHost.
2696 // It is possible to receive it from one that has just been swapped in,
2697 // in which case we might as well deliver the message anyway.
2698 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2699 GetRenderViewHost()->ClosePage();
2700}
2701
[email protected]f546640b2012-05-15 00:03:492702void WebContentsImpl::RouteMessageEvent(
2703 RenderViewHost* rvh,
2704 const ViewMsg_PostMessage_Params& params) {
2705 // Only deliver the message to the active RenderViewHost if the request
2706 // came from a RenderViewHost in the same BrowsingInstance.
2707 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2708 return;
2709
2710 ViewMsg_PostMessage_Params new_params(params);
2711
2712 // If there is a source_routing_id, translate it to the routing ID for
2713 // the equivalent swapped out RVH in the target process. If we need
2714 // to create a swapped out RVH for the source tab, we create its opener
2715 // chain as well, since those will also be accessible to the target page.
2716 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2717 // Try to look up the WebContents for the source page.
2718 WebContentsImpl* source_contents = NULL;
2719 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2720 rvh->GetProcess()->GetID(), params.source_routing_id);
2721 if (source_rvh) {
2722 source_contents = static_cast<WebContentsImpl*>(
2723 source_rvh->GetDelegate()->GetAsWebContents());
2724 }
2725
2726 if (source_contents) {
2727 new_params.source_routing_id =
2728 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2729 } else {
2730 // We couldn't find it, so don't pass a source frame.
2731 new_params.source_routing_id = MSG_ROUTING_NONE;
2732 }
2733 }
2734
2735 // In most cases, we receive this from a swapped out RenderViewHost.
2736 // It is possible to receive it from one that has just been swapped in,
2737 // in which case we might as well deliver the message anyway.
2738 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2739 GetRenderViewHost()->GetRoutingID(), new_params));
2740}
2741
[email protected]b172aee2012-04-10 17:05:262742void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342743 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412744 const string16& message,
2745 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322746 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142747 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322748 IPC::Message* reply_msg,
2749 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072750 // Suppress JavaScript dialogs when requested. Also suppress messages when
2751 // showing an interstitial as it's shown over the previous page and we don't
2752 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502753 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582754 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272755 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072756 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522757 delegate_->ShouldSuppressDialogs() ||
2758 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322759
2760 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432761 std::string accept_lang = content::GetContentClient()->browser()->
2762 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552763 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522764 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432765 this,
2766 frame_url.GetOrigin(),
2767 accept_lang,
2768 javascript_message_type,
2769 message,
[email protected]51da7e32012-01-30 19:24:522770 default_prompt,
[email protected]b172aee2012-04-10 17:05:262771 base::Bind(&WebContentsImpl::OnDialogClosed,
2772 base::Unretained(this),
2773 rvh,
2774 reply_msg),
[email protected]51da7e32012-01-30 19:24:522775 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322776 }
[email protected]3ab9cb82011-06-03 18:02:072777
2778 if (suppress_this_message) {
2779 // If we are suppressing messages, just reply as if the user immediately
2780 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342781 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072782 }
2783
2784 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322785}
2786
[email protected]b172aee2012-04-10 17:05:262787void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2788 const string16& message,
2789 bool is_reload,
2790 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582791 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512792 if (delegate_)
2793 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072794
2795 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582796 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072797 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522798 delegate_->ShouldSuppressDialogs() ||
2799 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152800 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342801 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582802 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502803 return;
2804 }
[email protected]3ab9cb82011-06-03 18:02:072805
[email protected]7ab1e7d62009-10-14 23:32:012806 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552807 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522808 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322809 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262810 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522811 reply_msg));
[email protected]420ae012009-04-24 05:16:322812}
2813
[email protected]a796f202012-05-30 14:14:252814bool WebContentsImpl::AddMessageToConsole(int32 level,
2815 const string16& message,
2816 int32 line_no,
2817 const string16& source_id) {
2818 if (!delegate_)
2819 return false;
2820 return delegate_->AddMessageToConsole(this, level, message, line_no,
2821 source_id);
2822}
2823
[email protected]b172aee2012-04-10 17:05:262824WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332825 // We want to base the page config off of the real URL, rather than the
2826 // display URL.
2827 GURL url = controller_.GetActiveEntry()
2828 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2829 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322830}
2831
[email protected]b172aee2012-04-10 17:05:262832void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272833 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252834 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222835
[email protected]ea114722012-03-12 01:11:252836 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172837 if (rdh) // NULL in unittests.
2838 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252839}
2840
[email protected]b172aee2012-04-10 17:05:262841void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442842 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252843 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442844}
2845
[email protected]b172aee2012-04-10 17:05:262846void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2847 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152848 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522849 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152850 return;
2851
[email protected]9f76c1e2012-03-05 15:15:582852 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2853
[email protected]e5fc1632011-08-08 07:51:532854 // Ignore renderer unresponsive event if debugger is attached to the tab
2855 // since the event may be a result of the renderer sitting on a breakpoint.
2856 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442857 DevToolsAgentHost* agent =
2858 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2859 if (agent &&
2860 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532861 return;
2862
[email protected]420ae012009-04-24 05:16:322863 if (is_during_unload) {
2864 // Hang occurred while firing the beforeunload/unload handler.
2865 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582866 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322867
2868 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2869 return;
2870
2871 // If the tab hangs in the beforeunload/unload handler there's really
2872 // nothing we can do to recover. Pretend the unload listeners have
2873 // all fired and close the tab. If the hang is in the beforeunload handler
2874 // then the user will not have the option of cancelling the close.
2875 Close(rvh);
2876 return;
2877 }
2878
[email protected]9f76c1e2012-03-05 15:15:582879 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472880 return;
2881
[email protected]6934a702011-12-20 00:04:512882 if (delegate_)
2883 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322884}
2885
[email protected]b172aee2012-04-10 17:05:262886void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512887 if (delegate_)
2888 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322889}
2890
[email protected]b172aee2012-04-10 17:05:262891void WebContentsImpl::LoadStateChanged(
2892 const GURL& url,
2893 const net::LoadStateWithParam& load_state,
2894 uint64 upload_position,
2895 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322896 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562897 upload_position_ = upload_position;
2898 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502899 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202900 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302901 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212902 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322903 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462904 if (IsLoading()) {
2905 NotifyNavigationStateChanged(
2906 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2907 }
[email protected]420ae012009-04-24 05:16:322908}
2909
[email protected]b172aee2012-04-10 17:05:262910void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512911 if (delegate_)
2912 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252913}
2914
[email protected]b172aee2012-04-10 17:05:262915void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322916 bool proceed,
2917 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512918 if (delegate_)
2919 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322920}
2921
[email protected]b172aee2012-04-10 17:05:262922void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542923 RenderViewHost* render_view_host) {
2924 DidStartLoading();
2925}
2926
[email protected]b172aee2012-04-10 17:05:262927void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542928 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232929 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2930 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542931}
2932
[email protected]b172aee2012-04-10 17:05:262933void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102934 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262935 gfx::Size size = view_->GetContainerSize();
2936 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2937 // here during container initialization and normal window size will be set
2938 // later. In case of tab duplication this resizing to 0x0 prevents setting
2939 // normal size later so just ignore it.
2940 if (!size.IsEmpty())
2941 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322942}
2943
[email protected]b172aee2012-04-10 17:05:262944void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542945 NotifySwapped();
2946}
2947
[email protected]14392a52012-05-02 20:28:442948int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2949 SiteInstance* instance) {
2950 if (!opener_)
2951 return MSG_ROUTING_NONE;
2952
2953 // Recursively create RenderViews for anything else in the opener chain.
2954 return opener_->CreateOpenerRenderViews(instance);
2955}
2956
2957int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2958 int opener_route_id = MSG_ROUTING_NONE;
2959
2960 // If this tab has an opener, ensure it has a RenderView in the given
2961 // SiteInstance as well.
2962 if (opener_)
2963 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2964
2965 // Create a swapped out RenderView in the given SiteInstance if none exists,
2966 // setting its opener to the given route_id. Return the new view's route_id.
2967 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2968}
2969
[email protected]b172aee2012-04-10 17:05:262970NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202971 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542972}
2973
[email protected]b172aee2012-04-10 17:05:262974WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562975 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322976}
2977
[email protected]10f417c52011-12-28 21:04:232978NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262979 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322980 return controller_.GetLastCommittedEntry();
2981}
2982
[email protected]b172aee2012-04-10 17:05:262983bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442984 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442985 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322986 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522987
[email protected]420ae012009-04-24 05:16:322988 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442989 if (rwh_view)
2990 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322991
[email protected]74ce1ad2011-12-16 21:51:462992 // Make sure we use the correct starting page_id in the new RenderView.
2993 UpdateMaxPageIDIfNecessary(render_view_host);
2994 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582995 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462996
[email protected]7900bfdb2012-05-24 19:31:242997 std::string embedder_channel_name;
2998 int embedder_container_id;
2999 GetBrowserPluginEmbedderInfo(render_view_host,
3000 &embedder_channel_name,
3001 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583002 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493003 render_view_host)->CreateRenderView(string16(),
3004 opener_route_id,
3005 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243006 embedder_channel_name,
3007 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523008 return false;
[email protected]14392a52012-05-02 20:28:443009 }
[email protected]a4127722011-04-27 23:13:523010
[email protected]e60c0232011-11-11 19:56:353011#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503012 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3013 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443014 if (rwh_view) {
3015 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3016 render_widget_host->WasResized();
3017 }
[email protected]f8233cc2011-05-31 20:24:503018#endif
3019
[email protected]420ae012009-04-24 05:16:323020 return true;
3021}
3022
[email protected]b172aee2012-04-10 17:05:263023void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3024 IPC::Message* reply_msg,
3025 bool success,
3026 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543027 if (is_showing_before_unload_dialog_ && !success) {
3028 // If a beforeunload dialog is canceled, we need to stop the throbber from
3029 // spinning, since we forced it to start spinning in Navigate.
3030 DidStopLoading();
3031
[email protected]3bbacc5b2012-04-17 17:46:153032 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543033 }
3034 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583035 static_cast<RenderViewHostImpl*>(
3036 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543037}
3038
[email protected]b172aee2012-04-10 17:05:263039void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123040 encoding_ = content::GetContentClient()->browser()->
3041 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103042}
[email protected]f45d2a72010-03-08 23:28:353043
[email protected]b172aee2012-04-10 17:05:263044void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463045 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263046 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143047 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
3048 if (!dlm)
3049 return;
3050 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263051 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143052 const NavigationEntry* entry = controller_.GetActiveEntry();
3053 if (entry)
3054 post_id = entry->GetPostID();
3055 }
[email protected]29a5ffc82012-03-13 19:35:583056 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143057 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143058 scoped_ptr<DownloadUrlParameters> params(
3059 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493060 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143061 params->set_post_id(post_id);
3062 params->set_prefer_cache(true);
3063 if (post_id >= 0)
3064 params->set_method("POST");
3065 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143066}
3067
[email protected]b172aee2012-04-10 17:05:263068void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213069 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443070 // Can be NULL during tests.
3071 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213072 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363073}
[email protected]9f76c1e2012-03-05 15:15:583074
[email protected]b172aee2012-04-10 17:05:263075RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583076 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3077}
[email protected]7900bfdb2012-05-24 19:31:243078
3079void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3080 content::RenderViewHost* render_view_host,
3081 std::string* embedder_channel_name,
3082 int* embedder_container_id) {
3083 content::RenderProcessHost* embedder_render_process_host =
3084 browser_plugin_host()->embedder_render_process_host();
3085 *embedder_container_id = browser_plugin_host()->instance_id();
3086 int embedder_process_id =
3087 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3088 if (embedder_process_id != -1) {
3089 *embedder_channel_name =
3090 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3091 embedder_process_id);
3092 }
3093}