blob: a5debc892885d329bed4b477e394541fa484b8e6 [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
431 prefs.gl_multisampling_enabled =
432 !command_line.HasSwitch(switches::kDisableGLMultisampling);
433 prefs.privileged_webgl_extensions_enabled =
434 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
435 prefs.site_specific_quirks_enabled =
436 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
437 prefs.allow_file_access_from_file_urls =
438 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
439 prefs.show_composited_layer_borders =
440 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
441 prefs.show_composited_layer_tree =
442 command_line.HasSwitch(switches::kShowCompositedLayerTree);
443 prefs.show_fps_counter =
444 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19445 prefs.show_paint_rects =
446 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]64d69de42012-02-06 00:19:54447 prefs.accelerated_compositing_enabled =
448 GpuProcessHost::gpu_enabled() &&
449 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54450 prefs.force_compositing_mode =
451 command_line.HasSwitch(switches::kForceCompositingMode);
452 prefs.fixed_position_compositing_enabled =
453 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
454 prefs.accelerated_2d_canvas_enabled =
455 GpuProcessHost::gpu_enabled() &&
456 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58457 prefs.deferred_2d_canvas_enabled =
[email protected]00bbad22012-05-25 13:24:17458 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36459 prefs.threaded_animation_enabled =
[email protected]efcde132012-05-30 01:05:18460 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54461 prefs.accelerated_painting_enabled =
462 GpuProcessHost::gpu_enabled() &&
463 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
464 prefs.accelerated_filters_enabled =
465 GpuProcessHost::gpu_enabled() &&
466 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
467 prefs.accelerated_layers_enabled =
468 prefs.accelerated_animation_enabled =
469 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54470 prefs.accelerated_plugins_enabled =
471 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
472 prefs.accelerated_video_enabled =
473 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
474 prefs.partial_swap_enabled =
475 command_line.HasSwitch(switches::kEnablePartialSwap);
476 prefs.interactive_form_validation_enabled =
477 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
478 prefs.fullscreen_enabled =
479 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16480 prefs.css_regions_enabled =
481 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29482 prefs.css_shaders_enabled =
483 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]a08412b62012-05-29 21:28:56484 prefs.device_supports_touch =
485 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]64d69de42012-02-06 00:19:54486
487#if defined(OS_MACOSX)
488 bool default_enable_scroll_animator = true;
489#else
490 // On CrOS, the launcher always passes in the --enable flag.
491 bool default_enable_scroll_animator = false;
492#endif
493 prefs.enable_scroll_animator = default_enable_scroll_animator;
494 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
495 prefs.enable_scroll_animator = true;
496 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
497 prefs.enable_scroll_animator = false;
498
499 prefs.visual_word_movement_enabled =
500 command_line.HasSwitch(switches::kEnableVisualWordMovement);
501 prefs.per_tile_painting_enabled =
502 command_line.HasSwitch(switches::kEnablePerTilePainting);
503
504 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32505 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54506 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11507 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
508 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54509 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11510 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54511 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11512 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54513 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11514 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54515 prefs.gl_multisampling_enabled = false;
516
517 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45518 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32519 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54520 prefs.accelerated_video_enabled = false;
521 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45522 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09523 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54524 }
525 }
526
[email protected]b9535422012-02-09 01:47:59527 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58528 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54529 prefs.loads_images_automatically = true;
530 prefs.javascript_enabled = true;
531 }
532
533 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
534
535 // Force accelerated compositing and 2d canvas off for chrome:, about: and
536 // chrome-devtools: pages (unless it's specifically allowed).
537 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54538 url.SchemeIs(chrome::kChromeUIScheme) ||
539 (url.SchemeIs(chrome::kAboutScheme) &&
540 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25541 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54542 prefs.accelerated_compositing_enabled = false;
543 prefs.accelerated_2d_canvas_enabled = false;
544 }
[email protected]8b3b36152012-05-01 04:55:07545#if defined(OS_MACOSX)
546 // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
547 // crbug.com/125690.
[email protected]82c9a8e2012-05-02 01:07:23548 prefs.default_device_scale_factor =
549 gfx::Monitor::GetDefaultDeviceScaleFactor();
[email protected]8b3b36152012-05-01 04:55:07550#else
551 if (rvh->GetView()) {
552 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
553 rvh->GetView()->GetNativeView());
554 prefs.default_device_scale_factor =
555 static_cast<int>(monitor.device_scale_factor());
556 } else {
[email protected]82c9a8e2012-05-02 01:07:23557 prefs.default_device_scale_factor =
558 gfx::Monitor::GetDefaultDeviceScaleFactor();;
[email protected]8b3b36152012-05-01 04:55:07559 }
560#endif
[email protected]43d9d782012-03-01 15:40:09561
[email protected]f98f5092012-05-19 00:08:14562 if (command_line.HasSwitch(switches::kDefaultTileWidth))
563 prefs.default_tile_width =
564 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
565 if (command_line.HasSwitch(switches::kDefaultTileHeight))
566 prefs.default_tile_height =
567 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
568 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
569 prefs.max_untiled_layer_width =
570 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
571 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
572 prefs.max_untiled_layer_height =
573 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
574
[email protected]2486dce2012-05-23 17:18:19575 if (gfx::Screen::IsDIPEnabled()) {
576 // Only apply when using DIP coordinate system as this setting interferes
577 // with fixed layout mode.
578 prefs.apply_default_device_scale_factor_in_compositor = true;
579 }
580
[email protected]96bcdc102012-05-24 23:42:10581 prefs.fixed_position_creates_stacking_context =
582 command_line.HasSwitch(switches::kFixedPositionCreatesStackingContext);
583
[email protected]2e21fe292012-03-02 22:52:32584 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54585
586 return prefs;
587}
588
[email protected]b172aee2012-04-10 17:05:26589NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20590 return controller_;
591}
592
[email protected]b172aee2012-04-10 17:05:26593RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28594 return &render_manager_;
595}
596
[email protected]b172aee2012-04-10 17:05:26597bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56598 if (GetWebUI() &&
599 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17600 return true;
[email protected]d2353452012-01-19 19:53:56601 }
[email protected]f82d57b52011-04-27 19:13:17602
[email protected]d8c660432011-12-22 20:51:25603 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
604 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10605 while ((observer = it.GetNext()) != NULL)
606 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53607 return true;
[email protected]403415a2011-01-10 18:57:53608
[email protected]724159a2010-12-30 01:11:18609 bool handled = true;
610 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26611 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58612 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
613 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24614 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
615 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18616 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
617 OnDidLoadResourceFromMemoryCache)
618 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
619 OnDidDisplayInsecureContent)
620 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
621 OnDidRunInsecureContent)
622 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
623 OnDocumentLoadedInFrame)
624 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26625 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
626 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17627 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
628 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25629 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26630 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59631 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21632 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20633 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
634 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
635 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16636 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45637 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10638 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20639 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
640 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
641 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
642 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29643 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50644 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18645 IPC_MESSAGE_UNHANDLED(handled = false)
646 IPC_END_MESSAGE_MAP_EX()
647
648 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38649 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18650 GetRenderProcessHost()->ReceivedBadMessage();
651 }
652
653 return handled;
654}
655
[email protected]b172aee2012-04-10 17:05:26656void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18657 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23658 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51659 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18660}
661
[email protected]b172aee2012-04-10 17:05:26662NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56663 return controller_;
664}
665
[email protected]b172aee2012-04-10 17:05:26666const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56667 return controller_;
668}
669
[email protected]b172aee2012-04-10 17:05:26670content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55671 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30672}
673
[email protected]b172aee2012-04-10 17:05:26674const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31675 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23676 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51677 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31678}
679
680
[email protected]b172aee2012-04-10 17:05:26681const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31682 return &property_bag_;
683}
684
[email protected]b172aee2012-04-10 17:05:26685base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31686 return &property_bag_;
687}
688
[email protected]b172aee2012-04-10 17:05:26689content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31690 return delegate_;
691}
692
[email protected]b172aee2012-04-10 17:05:26693void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31694 // TODO(cbentzel): remove this debugging code?
695 if (delegate == delegate_)
696 return;
697 if (delegate_)
698 delegate_->Detach(this);
699 delegate_ = delegate;
700 if (delegate_)
701 delegate_->Attach(this);
702}
703
[email protected]b172aee2012-04-10 17:05:26704content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41705 RenderViewHostImpl* host = render_manager_.current_host();
706 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16707}
708
[email protected]b172aee2012-04-10 17:05:26709RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31710 return render_manager_.current_host();
711}
712
[email protected]b172aee2012-04-10 17:05:26713RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31714 return render_manager_.GetRenderWidgetHostView();
715}
716
[email protected]b172aee2012-04-10 17:05:26717content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31718 return view_.get();
719}
720
[email protected]b172aee2012-04-10 17:05:26721content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50722 WebUIControllerFactory* factory =
723 content::GetContentClient()->browser()->GetWebUIControllerFactory();
724 if (!factory)
725 return NULL;
[email protected]d2353452012-01-19 19:53:56726 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22727 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50728 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22729 if (controller) {
730 web_ui->SetController(controller);
731 return web_ui;
732 }
733
734 delete web_ui;
735 return NULL;
736}
737
[email protected]b172aee2012-04-10 17:05:26738content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31739 return render_manager_.web_ui() ? render_manager_.web_ui()
740 : render_manager_.pending_web_ui();
741}
742
[email protected]b172aee2012-04-10 17:05:26743content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31744 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34745}
746
[email protected]86ef6a392012-05-11 22:03:11747void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
748 user_agent_override_ = override;
749}
750
751const std::string& WebContentsImpl::GetUserAgentOverride() const {
752 return user_agent_override_;
753}
754
[email protected]b172aee2012-04-10 17:05:26755const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55756 // Transient entries take precedence. They are used for interstitial pages
757 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23758 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08759 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20760 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30761 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23762 if (entry) {
[email protected]b5cca982011-05-26 04:42:08763 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23764 }
[email protected]7ade2732011-02-10 00:13:58765 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
766 render_manager_.pending_web_ui() : render_manager_.web_ui();
767 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54768 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55769 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54770 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35771 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22772 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54773 if (!title.empty())
774 return title;
775 }
776 }
777
778 // We use the title for the last committed entry rather than a pending
779 // navigation entry. For example, when the user types in a URL, we want to
780 // keep the old page's title until the new load has committed and we get a new
781 // title.
[email protected]96d185d2009-04-24 03:28:54782 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23783 if (entry) {
[email protected]b5cca982011-05-26 04:42:08784 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23785 }
[email protected]987fc3a2011-05-26 14:18:09786
787 // |page_title_when_no_navigation_entry_| is finally used
788 // if no title cannot be retrieved.
789 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54790}
791
[email protected]b172aee2012-04-10 17:05:26792int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46793 return GetMaxPageIDForSiteInstance(GetSiteInstance());
794}
795
[email protected]b172aee2012-04-10 17:05:26796int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
797 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33798 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
799 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46800
[email protected]b6583592012-01-25 19:52:33801 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34802}
803
[email protected]b172aee2012-04-10 17:05:26804void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46805 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
806}
807
[email protected]b172aee2012-04-10 17:05:26808void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33809 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46810 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33811 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34812}
813
[email protected]b172aee2012-04-10 17:05:26814void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
815 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57816}
817
[email protected]b172aee2012-04-10 17:05:26818SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58819 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54820}
821
[email protected]b172aee2012-04-10 17:05:26822SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38823 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
824 render_manager_.pending_render_view_host() :
825 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58826 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38827}
828
[email protected]b172aee2012-04-10 17:05:26829bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31830 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49831}
832
[email protected]b172aee2012-04-10 17:05:26833bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31834 return waiting_for_response_;
835}
836
[email protected]b172aee2012-04-10 17:05:26837const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31838 return load_state_;
839}
840
[email protected]b172aee2012-04-10 17:05:26841const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31842 return load_state_host_;
843}
844
[email protected]b172aee2012-04-10 17:05:26845uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31846 return upload_size_;
847}
848
[email protected]b172aee2012-04-10 17:05:26849uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31850 return upload_position_;
851}
852
[email protected]b172aee2012-04-10 17:05:26853const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31854 return encoding_;
855}
856
[email protected]b172aee2012-04-10 17:05:26857bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31858 return displayed_insecure_content_;
859}
860
[email protected]b172aee2012-04-10 17:05:26861void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31862 capturing_contents_ = cap;
863}
864
[email protected]b172aee2012-04-10 17:05:26865bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31866 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
867 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
868 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49869}
870
[email protected]b172aee2012-04-10 17:05:26871void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
872 int error_code) {
[email protected]443b80e2010-12-14 00:42:23873 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34874 return;
875
[email protected]443b80e2010-12-14 00:42:23876 crashed_status_ = status;
877 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46878 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34879}
880
[email protected]b172aee2012-04-10 17:05:26881base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31882 return crashed_status_;
883}
884
[email protected]b172aee2012-04-10 17:05:26885bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31886 return is_being_destroyed_;
887}
888
[email protected]b172aee2012-04-10 17:05:26889void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34890 if (delegate_)
891 delegate_->NavigationStateChanged(this, changed_flags);
892}
893
[email protected]b172aee2012-04-10 17:05:26894void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54895 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04896 RenderWidgetHostViewPort* rwhv =
897 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16898 if (rwhv) {
899 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43900#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16901 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43902#endif
903 }
[email protected]96d185d2009-04-24 03:28:54904
[email protected]5ac20162010-11-24 23:33:11905 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38906
[email protected]d8c660432011-12-22 20:51:25907 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59908
909 // The resize rect might have changed while this was inactive -- send the new
910 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58911 RenderViewHostImpl* rvh =
912 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59913 if (rvh) {
914 rvh->ResizeRectChanged(GetRootWindowResizerRect());
915 }
[email protected]96d185d2009-04-24 03:28:54916}
917
[email protected]be1f56ab2011-12-22 06:55:31918
[email protected]b172aee2012-04-10 17:05:26919base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31920 return last_selected_time_;
921}
922
[email protected]b172aee2012-04-10 17:05:26923void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31924 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52925 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
926 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26927 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52928 // removes the |GetRenderViewHost()|; then when we actually destroy the
929 // window, OnWindowPosChanged() notices and calls HideContents() (which
930 // calls us).
[email protected]c30585c2012-02-16 15:02:04931 RenderWidgetHostViewPort* rwhv =
932 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16933 if (rwhv)
934 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54935 }
936
[email protected]375fa1b2012-05-22 22:05:37937 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07938 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37939 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09940 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37941 content::Details<bool>(&is_visible));
942}
943
944void WebContentsImpl::WasRestored() {
945 bool is_visible = true;
946 content::NotificationService::current()->Notify(
947 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
948 content::Source<WebContents>(this),
949 content::Details<bool>(&is_visible));
[email protected]96d185d2009-04-24 03:28:54950}
951
[email protected]b172aee2012-04-10 17:05:26952void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04953 RenderWidgetHostViewPort* rwhv =
954 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31955 if (rwhv)
956 rwhv->DidBecomeSelected();
[email protected]375fa1b2012-05-22 22:05:37957 WasRestored();
[email protected]be1f56ab2011-12-22 06:55:31958}
959
[email protected]b172aee2012-04-10 17:05:26960void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31961 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
962 // our superclass HideContents(), because some callers want to be very picky
963 // about the order in which these get called. In addition to making the code
964 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26965 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
966 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31967 WasHidden();
968}
969
[email protected]b172aee2012-04-10 17:05:26970bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31971 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27972 return WillNotifyDisconnection() &&
973 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58974 !static_cast<RenderViewHostImpl*>(
975 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31976}
977
[email protected]b172aee2012-04-10 17:05:26978void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27979 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25980 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27981}
982
[email protected]b172aee2012-04-10 17:05:26983WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44984 // We use our current SiteInstance since the cloned entry will use it anyway.
985 // We pass |this| for the |base_web_contents| to size the view correctly, and
986 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26987 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44988 GetBrowserContext(), GetSiteInstance(),
989 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20990 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27991 return tc;
992}
993
[email protected]b172aee2012-04-10 17:05:26994void WebContentsImpl::AddNewContents(WebContents* new_contents,
995 WindowOpenDisposition disposition,
996 const gfx::Rect& initial_pos,
997 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27998 if (!delegate_)
999 return;
1000
1001 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1002 user_gesture);
1003}
1004
[email protected]b172aee2012-04-10 17:05:261005gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271006 return view_->GetContentNativeView();
1007}
1008
[email protected]b172aee2012-04-10 17:05:261009gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271010 return view_->GetNativeView();
1011}
1012
[email protected]b172aee2012-04-10 17:05:261013void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271014 view_->GetContainerBounds(out);
1015}
1016
[email protected]b172aee2012-04-10 17:05:261017void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271018 view_->Focus();
1019}
1020
[email protected]14392a52012-05-02 20:28:441021void WebContentsImpl::Observe(int type,
1022 const content::NotificationSource& source,
1023 const content::NotificationDetails& details) {
1024 switch (type) {
1025 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1026 OnWebContentsDestroyed(
1027 content::Source<content::WebContents>(source).ptr());
1028 break;
[email protected]bafe6cd2012-05-23 23:09:501029 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1030 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1031 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1032 i != pending_widget_views_.end(); ++i) {
1033 if (host->GetView() == i->second) {
1034 pending_widget_views_.erase(i);
1035 break;
1036 }
1037 }
1038 break;
1039 }
[email protected]14392a52012-05-02 20:28:441040 default:
1041 NOTREACHED();
1042 }
1043}
1044
1045void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1046 // Clear the opener if it has been closed.
1047 if (web_contents == opener_) {
1048 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1049 content::Source<WebContents>(opener_));
1050 opener_ = NULL;
1051 }
1052}
1053
[email protected]b172aee2012-04-10 17:05:261054void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311055 observers_.AddObserver(observer);
1056}
1057
[email protected]b172aee2012-04-10 17:05:261058void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311059 observers_.RemoveObserver(observer);
1060}
1061
[email protected]b172aee2012-04-10 17:05:261062void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341063 if (delegate_)
1064 delegate_->ActivateContents(this);
1065}
1066
[email protected]b172aee2012-04-10 17:05:261067void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121068 if (delegate_)
1069 delegate_->DeactivateContents(this);
1070}
1071
[email protected]b172aee2012-04-10 17:05:261072void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481073 if (delegate_)
1074 delegate_->LostCapture();
1075}
1076
[email protected]b172aee2012-04-10 17:05:261077bool WebContentsImpl::PreHandleKeyboardEvent(
1078 const NativeWebKeyboardEvent& event,
1079 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481080 return delegate_ &&
1081 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1082}
1083
[email protected]b172aee2012-04-10 17:05:261084void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481085 if (delegate_)
1086 delegate_->HandleKeyboardEvent(event);
1087}
1088
[email protected]b172aee2012-04-10 17:05:261089void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431090 if (delegate_)
1091 delegate_->HandleMouseDown();
1092}
1093
[email protected]b172aee2012-04-10 17:05:261094void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481095 if (delegate_)
1096 delegate_->HandleMouseUp();
1097}
1098
[email protected]b172aee2012-04-10 17:05:261099void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481100 if (delegate_)
1101 delegate_->HandleMouseActivate();
1102}
1103
[email protected]b172aee2012-04-10 17:05:261104void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471105 if (delegate_)
1106 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1107}
1108
[email protected]b172aee2012-04-10 17:05:261109bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381110 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121111}
1112
[email protected]a9c81f02012-06-01 00:15:441113void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1114 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371115 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441116 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371117 } else {
1118 GotResponseToLockMouseRequest(false);
1119 }
1120}
1121
[email protected]b172aee2012-04-10 17:05:261122void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371123 if (delegate_)
1124 delegate_->LostMouseLock();
1125}
1126
[email protected]bafe6cd2012-05-23 23:09:501127void WebContentsImpl::CreateNewWindow(
1128 int route_id,
1129 const ViewHostMsg_CreateWindow_Params& params) {
1130 if (delegate_ && !delegate_->ShouldCreateWebContents(
1131 this, route_id, params.window_container_type, params.frame_name,
1132 params.target_url)) {
1133 return;
1134 }
1135
1136 // We usually create the new window in the same BrowsingInstance (group of
1137 // script-related windows), by passing in the current SiteInstance. However,
1138 // if the opener is being suppressed, we create a new SiteInstance in its own
1139 // BrowsingInstance.
1140 scoped_refptr<SiteInstance> site_instance =
1141 params.opener_suppressed ?
1142 SiteInstance::Create(GetBrowserContext()) :
1143 GetSiteInstance();
1144
1145 // Create the new web contents. This will automatically create the new
1146 // WebContentsView. In the future, we may want to create the view separately.
1147 WebContentsImpl* new_contents =
1148 new WebContentsImpl(GetBrowserContext(),
1149 site_instance,
1150 route_id,
1151 this,
1152 params.opener_suppressed ? NULL : this,
1153 NULL);
1154 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1155
1156 if (!params.opener_suppressed) {
1157 content::WebContentsView* new_view = new_contents->GetView();
1158
1159 // TODO(brettw): It seems bogus that we have to call this function on the
1160 // newly created object and give it one of its own member variables.
1161 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1162
1163 // Save the created window associated with the route so we can show it
1164 // later.
1165 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1166 pending_contents_[route_id] = new_contents;
1167 }
1168
1169 if (delegate_) {
1170 delegate_->WebContentsCreated(
1171 this, params.opener_frame_id, params.target_url, new_contents);
1172 }
1173
1174 if (params.opener_suppressed) {
1175 // When the opener is suppressed, the original renderer cannot access the
1176 // new window. As a result, we need to show and navigate the window here.
1177 gfx::Rect initial_pos;
1178 AddNewContents(
1179 new_contents, params.disposition, initial_pos, params.user_gesture);
1180
1181 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1182 CURRENT_TAB,
1183 content::PAGE_TRANSITION_LINK,
1184 true /* is_renderer_initiated */);
1185 new_contents->OpenURL(open_params);
1186 }
1187}
1188
1189void WebContentsImpl::CreateNewWidget(int route_id,
1190 WebKit::WebPopupType popup_type) {
1191 CreateNewWidget(route_id, false, popup_type);
1192}
1193
1194void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1195 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1196}
1197
1198void WebContentsImpl::CreateNewWidget(int route_id,
1199 bool is_fullscreen,
1200 WebKit::WebPopupType popup_type) {
1201 content::RenderProcessHost* process = GetRenderProcessHost();
1202 RenderWidgetHostImpl* widget_host =
1203 new RenderWidgetHostImpl(this, process, route_id);
1204 RenderWidgetHostViewPort* widget_view =
1205 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1206 if (!is_fullscreen) {
1207 // Popups should not get activated.
1208 widget_view->SetPopupType(popup_type);
1209 }
1210 // Save the created widget associated with the route so we can show it later.
1211 pending_widget_views_[route_id] = widget_view;
1212
1213#if defined(OS_MACOSX)
1214 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1215 // to allow it to survive the trip without being hosted.
1216 base::mac::NSObjectRetain(widget_view->GetNativeView());
1217#endif
1218}
1219
1220void WebContentsImpl::ShowCreatedWindow(int route_id,
1221 WindowOpenDisposition disposition,
1222 const gfx::Rect& initial_pos,
1223 bool user_gesture) {
1224 WebContentsImpl* contents = GetCreatedWindow(route_id);
1225 if (contents)
1226 AddNewContents(contents, disposition, initial_pos, user_gesture);
1227}
1228
1229void WebContentsImpl::ShowCreatedWidget(int route_id,
1230 const gfx::Rect& initial_pos) {
1231 ShowCreatedWidget(route_id, false, initial_pos);
1232}
1233
1234void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1235 ShowCreatedWidget(route_id, true, gfx::Rect());
1236}
1237
1238void WebContentsImpl::ShowCreatedWidget(int route_id,
1239 bool is_fullscreen,
1240 const gfx::Rect& initial_pos) {
1241 if (delegate_)
1242 delegate_->RenderWidgetShowing();
1243
1244 RenderWidgetHostViewPort* widget_host_view =
1245 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1246 if (!widget_host_view)
1247 return;
1248 if (is_fullscreen) {
1249 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1250 } else {
1251 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1252 }
[email protected]89054502012-06-03 10:29:241253
1254 RenderWidgetHostImpl* render_widget_host_impl =
1255 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1256 render_widget_host_impl->Init();
1257 // Only allow privileged mouse lock for fullscreen render widget, which is
1258 // used to implement Pepper Flash fullscreen.
1259 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501260
1261#if defined(OS_MACOSX)
1262 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1263 // properly embedded (or purposefully ignored) we can release the retain we
1264 // took in CreateNewWidget().
1265 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1266#endif
1267}
1268
1269WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1270 PendingContents::iterator iter = pending_contents_.find(route_id);
1271
1272 // Certain systems can block the creation of new windows. If we didn't succeed
1273 // in creating one, just return NULL.
1274 if (iter == pending_contents_.end()) {
1275 return NULL;
1276 }
1277
1278 WebContentsImpl* new_contents = iter->second;
1279 pending_contents_.erase(route_id);
1280
1281 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1282 !new_contents->GetRenderViewHost()->GetView())
1283 return NULL;
1284
1285 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1286 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1287 return new_contents;
1288}
1289
1290RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1291 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1292 if (iter == pending_widget_views_.end()) {
1293 DCHECK(false);
1294 return NULL;
1295 }
1296
1297 RenderWidgetHostView* widget_host_view = iter->second;
1298 pending_widget_views_.erase(route_id);
1299
1300 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1301 if (!widget_host->GetProcess()->HasConnection()) {
1302 // The view has gone away or the renderer crashed. Nothing to do.
1303 return NULL;
1304 }
1305
1306 return widget_host_view;
1307}
1308
1309void WebContentsImpl::ShowContextMenu(
1310 const content::ContextMenuParams& params) {
1311 // Allow WebContentsDelegates to handle the context menu operation first.
1312 if (delegate_ && delegate_->HandleContextMenu(params))
1313 return;
1314
[email protected]5a3bdf52012-05-24 15:12:571315 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501316}
1317
[email protected]b172aee2012-04-10 17:05:261318void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231319 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331320 if (delegate_)
1321 delegate_->UpdatePreferredSize(this, pref_size);
1322}
1323
[email protected]b172aee2012-04-10 17:05:261324void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341325 if (delegate_)
1326 delegate_->ResizeDueToAutoResize(this, new_size);
1327}
1328
[email protected]b172aee2012-04-10 17:05:261329WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201330 if (!delegate_)
1331 return NULL;
[email protected]00c37fc2011-08-02 00:22:501332
[email protected]e5d549d2011-12-28 01:29:201333 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1334 // Notify observers.
1335 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1336 DidOpenURL(params.url, params.referrer,
1337 params.disposition, params.transition));
1338 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341339}
1340
[email protected]b172aee2012-04-10 17:05:261341bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501342 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251343 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231344 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251345 reload_type);
[email protected]876bc832010-09-07 16:29:541346}
[email protected]96d185d2009-04-24 03:28:541347
[email protected]ba45bfd2012-05-22 21:51:441348void WebContentsImpl::RenderViewForInterstitialPageCreated(
1349 content::RenderViewHost* render_view_host) {
1350 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1351 RenderViewForInterstitialPageCreated(render_view_host));
1352}
1353
[email protected]b172aee2012-04-10 17:05:261354bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231355 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501356 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401357 // The renderer will reject IPC messages with URLs longer than
1358 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511359 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401360 return false;
1361
[email protected]9f76c1e2012-03-05 15:15:581362 RenderViewHostImpl* dest_render_view_host =
1363 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401364 if (!dest_render_view_host)
1365 return false; // Unable to create the desired render view host.
1366
[email protected]80a8fad2011-01-29 04:02:381367 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071368 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581369 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501370 WebUIControllerFactory* factory =
1371 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271372 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501373 bool is_allowed_in_web_ui_renderer =
1374 factory &&
[email protected]24e18252012-04-16 21:26:271375 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1376 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231377 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1378 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271379 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231380 content::GetContentClient()->SetActiveURL(entry.GetURL());
1381 CHECK(0);
1382 }
[email protected]54ec6472010-04-09 19:39:581383
[email protected]96d185d2009-04-24 03:28:541384 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441385 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521386 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441387 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511388 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541389
1390 // Used for page load time metrics.
1391 current_load_start_ = base::TimeTicks::Now();
1392
1393 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241394 std::string embedder_channel_name;
1395 int embedder_container_id;
1396 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1397 &embedder_channel_name,
1398 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341399 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271400 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241401 embedder_channel_name,
1402 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471403 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341404 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541405
[email protected]36fc0392011-12-25 03:59:511406 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541407 // HACK!! This code suppresses javascript: URLs from being added to
1408 // session history, which is what we want to do for javascript: URLs that
1409 // do not generate content. What we really need is a message from the
1410 // renderer telling us that a new page was not created. The same message
1411 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511412 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541413 return false;
1414 }
1415
[email protected]3c9e1872010-11-18 16:17:491416 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251417 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041418 observers_,
[email protected]36fc0392011-12-25 03:59:511419 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541420
[email protected]09b29342011-06-24 19:18:481421 if (delegate_)
1422 delegate_->DidNavigateToPendingEntry(this);
1423
[email protected]d5f942ba2008-09-26 19:30:341424 return true;
1425}
1426
[email protected]b172aee2012-04-10 17:05:261427void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331428 const SiteInstance* site_instance,
1429 int history_length,
1430 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411431 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1432 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191433 if (render_manager_.pending_render_view_host()) {
1434 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141435 return;
[email protected]9e1ad4b2011-08-14 16:49:191436 }
[email protected]9f76c1e2012-03-05 15:15:581437 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191438 if (!rvh) {
1439 NOTREACHED();
1440 return;
1441 }
[email protected]9f76c1e2012-03-05 15:15:581442 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191443 NOTREACHED();
1444 return;
1445 }
[email protected]9f76c1e2012-03-05 15:15:581446 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191447 history_length,
1448 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141449}
1450
[email protected]b172aee2012-04-10 17:05:261451void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271452 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541453 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1454 return;
1455 }
[email protected]9f76c1e2012-03-05 15:15:581456 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541457}
1458
[email protected]b172aee2012-04-10 17:05:261459bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271460 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541461}
1462
[email protected]b172aee2012-04-10 17:05:261463InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271464 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221465}
1466
[email protected]b172aee2012-04-10 17:05:261467bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161468 // WebKit creates Document object when MIME type is application/xhtml+xml,
1469 // so we also support this MIME type.
1470 return contents_mime_type_ == "text/html" ||
1471 contents_mime_type_ == "text/xml" ||
1472 contents_mime_type_ == "application/xhtml+xml" ||
1473 contents_mime_type_ == "text/plain" ||
1474 contents_mime_type_ == "text/css" ||
1475 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1476}
1477
[email protected]b172aee2012-04-10 17:05:261478void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591479 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161480 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481481 download_stats::RecordDownloadSource(
1482 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461483 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141484 return;
[email protected]c7dd2f62011-07-18 15:57:591485 }
1486
1487 Stop();
1488
1489 // Create the save package and possibly prompt the user for the name to save
1490 // the page as. The user prompt is an asynchronous operation that runs on
1491 // another thread.
1492 save_package_ = new SavePackage(this);
1493 save_package_->GetSaveInfo();
1494}
1495
1496// Used in automated testing to bypass prompting the user for file names.
1497// Instead, the names and paths are hard coded rather than running them through
1498// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261499bool WebContentsImpl::SavePage(const FilePath& main_file,
1500 const FilePath& dir_path,
1501 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591502 // Stop the page from navigating.
1503 Stop();
1504
1505 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271506 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591507}
1508
[email protected]b172aee2012-04-10 17:05:261509void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121510 const FilePath& file,
1511 const base::Callback<void(const FilePath&, int64)>& callback) {
1512 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1513}
1514
[email protected]b172aee2012-04-10 17:05:261515bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231516 NavigationEntryImpl* active_entry =
1517 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321518 return (active_entry != NULL &&
1519 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511520 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321521}
1522
[email protected]b172aee2012-04-10 17:05:261523const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271524 return contents_mime_type_;
1525}
1526
[email protected]b172aee2012-04-10 17:05:261527bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271528 return notify_disconnection_;
1529}
1530
[email protected]b172aee2012-04-10 17:05:261531void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311532 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581533 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1534 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161535}
1536
[email protected]b172aee2012-04-10 17:05:261537void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311538 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581539 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1540 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161541}
1542
[email protected]b172aee2012-04-10 17:05:261543content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271544 return &renderer_preferences_;
1545}
1546
[email protected]b172aee2012-04-10 17:05:261547void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271548 new_tab_start_time_ = time;
1549}
1550
[email protected]b172aee2012-04-10 17:05:261551base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271552 return new_tab_start_time_;
1553}
1554
[email protected]e35ccd52012-05-23 16:22:471555void WebContentsImpl::Close() {
1556 Close(GetRenderViewHost());
1557}
1558
[email protected]b172aee2012-04-10 17:05:261559void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151560 if (close_start_time_.is_null())
1561 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011562}
1563
[email protected]b172aee2012-04-10 17:05:261564bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191565#if defined(OS_CHROMEOS)
1566 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1567 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511568 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201569 return false;
1570 return true;
[email protected]46624bf2010-06-09 16:04:191571#else
1572 return true;
1573#endif
1574}
1575
[email protected]b172aee2012-04-10 17:05:261576void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521577 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581578 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511579 if (delegate_)
1580 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341581}
1582
[email protected]e35ccd52012-05-23 16:22:471583void WebContentsImpl::UserGestureDone() {
1584 OnUserGesture();
1585}
1586
[email protected]b172aee2012-04-10 17:05:261587void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271588 closed_by_user_gesture_ = value;
1589}
1590
[email protected]b172aee2012-04-10 17:05:261591bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271592 return closed_by_user_gesture_;
1593}
1594
[email protected]b172aee2012-04-10 17:05:261595double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051596 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561597 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251598 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171599 return 0;
[email protected]b75b8292010-10-01 07:28:251600
1601 double zoom_level;
1602 if (temporary_zoom_settings_) {
1603 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581604 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251605 } else {
[email protected]2ae88d12011-10-14 09:11:191606 GURL url;
[email protected]10f417c52011-12-28 21:04:231607 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191608 // Since zoom map is updated using rewritten URL, use rewritten URL
1609 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511610 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191611 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251612 }
[email protected]d0b8d092010-10-25 04:05:171613 return zoom_level;
1614}
[email protected]b75b8292010-10-01 07:28:251615
[email protected]b172aee2012-04-10 17:05:261616int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1617 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171618 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011619 // Calculate the zoom percent from the factor. Round up to the nearest whole
1620 // number.
[email protected]b75b8292010-10-01 07:28:251621 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011622 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251623 *enable_decrement = percent > minimum_zoom_percent_;
1624 *enable_increment = percent < maximum_zoom_percent_;
1625 return percent;
1626}
1627
[email protected]b172aee2012-04-10 17:05:261628void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501629 if (!delegate_)
1630 return;
1631
[email protected]10f417c52011-12-28 21:04:231632 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501633 if (!active_entry)
1634 return;
1635
[email protected]36fc0392011-12-25 03:59:511636 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121637}
1638
[email protected]b172aee2012-04-10 17:05:261639void WebContentsImpl::ViewFrameSource(const GURL& url,
1640 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271641 if (!delegate_)
1642 return;
1643
1644 delegate_->ViewSourceForFrame(this, url, content_state);
1645}
1646
[email protected]b172aee2012-04-10 17:05:261647int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271648 return minimum_zoom_percent_;
1649}
1650
[email protected]b172aee2012-04-10 17:05:261651int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271652 return maximum_zoom_percent_;
1653}
1654
[email protected]b172aee2012-04-10 17:05:261655gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231656 return preferred_size_;
1657}
1658
[email protected]b172aee2012-04-10 17:05:261659int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271660 return content_restrictions_;
1661}
1662
[email protected]b172aee2012-04-10 17:05:261663WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501664 WebUIControllerFactory* factory =
1665 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1666 if (!factory)
1667 return WebUI::kNoWebUI;
1668 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271669}
1670
[email protected]b172aee2012-04-10 17:05:261671content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271672 // When there is a pending navigation entry, we want to use the pending WebUI
1673 // that goes along with it to control the basic flags. For example, we want to
1674 // show the pending URL in the URL bar, so we want the display_url flag to
1675 // be from the pending entry.
1676 //
1677 // The confusion comes because there are multiple possibilities for the
1678 // initial load in a tab as a side effect of the way the RenderViewHostManager
1679 // works.
1680 //
1681 // - For the very first tab the load looks "normal". The new tab Web UI is
1682 // the pending one, and we want it to apply here.
1683 //
1684 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1685 // get switched to the one previously associated with the new tab pages.
1686 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1687 // have a committed Web UI in this case.
1688 //
1689 // This condition handles all of these cases:
1690 //
1691 // - First load in first tab: no committed nav entry + pending nav entry +
1692 // pending dom ui:
1693 // -> Use pending Web UI if any.
1694 //
1695 // - First load in second tab: no committed nav entry + pending nav entry +
1696 // no pending Web UI:
1697 // -> Use the committed Web UI if any.
1698 //
1699 // - Second navigation in any tab: committed nav entry + pending nav entry:
1700 // -> Use pending Web UI if any.
1701 //
1702 // - Normal state with no load: committed nav entry + no pending nav entry:
1703 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251704 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271705 (controller_.GetLastCommittedEntry() ||
1706 render_manager_.pending_web_ui()))
1707 return render_manager_.pending_web_ui();
1708 return render_manager_.web_ui();
1709}
1710
[email protected]b172aee2012-04-10 17:05:261711bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271712 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581713 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271714}
1715
[email protected]b172aee2012-04-10 17:05:261716bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441717 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501718}
1719
[email protected]b172aee2012-04-10 17:05:261720void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321721 SkColor color) {
[email protected]da8543762012-03-20 08:52:201722 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1723 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1724}
1725
[email protected]b172aee2012-04-10 17:05:261726void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201727 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1728 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1729 if (delegate_)
1730 delegate_->DidEndColorChooser();
1731 color_chooser_ = NULL;
1732}
1733
[email protected]b172aee2012-04-10 17:05:261734bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471735 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271736 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221737 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231738 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411739 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271740}
1741
[email protected]b172aee2012-04-10 17:05:261742void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271743 if (delegate_)
1744 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211745}
1746
[email protected]3a3b75a2012-06-01 08:38:361747void WebContentsImpl::OnRegisterIntentService(
1748 const webkit_glue::WebIntentServiceData& data,
1749 bool user_gesture) {
1750 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301751}
1752
[email protected]b172aee2012-04-10 17:05:261753void WebContentsImpl::OnWebIntentDispatch(
1754 const webkit_glue::WebIntentData& intent,
1755 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001756 WebIntentsDispatcherImpl* intents_dispatcher =
1757 new WebIntentsDispatcherImpl(this, intent, intent_id);
1758 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301759}
1760
[email protected]54047eb52012-05-08 21:45:571761void WebContentsImpl::DidStartProvisionalLoadForFrame(
1762 content::RenderViewHost* render_view_host,
1763 int64 frame_id,
1764 bool is_main_frame,
1765 const GURL& opener_url,
1766 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281767 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181768 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451769 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571770 content::RenderProcessHost* render_process_host =
1771 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161772 RenderViewHostImpl::FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581773 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571774 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451775 false,
[email protected]9f76c1e2012-03-05 15:15:581776 &validated_url);
[email protected]97d402f32012-06-01 02:55:161777 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451778 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571779 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451780 true,
1781 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181782
[email protected]0d60f0192011-04-14 12:40:101783 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251784 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101785 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571786 validated_url, is_error_page, render_view_host));
[email protected]0d60f0192011-04-14 12:40:101787
[email protected]724159a2010-12-30 01:11:181788 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591789 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251790 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451791 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]ef16c3e2012-05-16 22:13:461792 validated_opener_url,
1793 render_view_host));
[email protected]724159a2010-12-30 01:11:181794 }
1795}
1796
[email protected]54047eb52012-05-08 21:45:571797void WebContentsImpl::DidRedirectProvisionalLoad(
1798 content::RenderViewHost* render_view_host,
1799 int32 page_id,
1800 const GURL& opener_url,
1801 const GURL& source_url,
1802 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491803 // TODO(creis): Remove this method and have the pre-rendering code listen to
1804 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1805 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451806 GURL validated_source_url(source_url);
1807 GURL validated_target_url(target_url);
1808 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571809 content::RenderProcessHost* render_process_host =
1810 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161811 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451812 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571813 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451814 false,
1815 &validated_source_url);
[email protected]97d402f32012-06-01 02:55:161816 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451817 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571818 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451819 false,
1820 &validated_target_url);
[email protected]97d402f32012-06-01 02:55:161821 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451822 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571823 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451824 true,
1825 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231826 NavigationEntry* entry;
[email protected]54047eb52012-05-08 21:45:571827 if (page_id == -1) {
[email protected]022af742011-12-28 18:37:251828 entry = controller_.GetPendingEntry();
[email protected]54047eb52012-05-08 21:45:571829 } else {
1830 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1831 page_id);
1832 }
[email protected]6b7cd8f2012-03-21 21:02:451833 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181834 return;
[email protected]e7d50892011-01-19 21:47:381835
[email protected]4850a7f2011-03-08 23:36:591836 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251837 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451838 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]ef16c3e2012-05-16 22:13:461839 validated_opener_url,
1840 render_view_host));
[email protected]724159a2010-12-30 01:11:181841}
1842
[email protected]54047eb52012-05-08 21:45:571843void WebContentsImpl::DidFailProvisionalLoadWithError(
1844 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581845 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1846 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1847 << ", error_code: " << params.error_code
1848 << ", error_description: " << params.error_description
1849 << ", is_main_frame: " << params.is_main_frame
1850 << ", showing_repost_interstitial: " <<
1851 params.showing_repost_interstitial
1852 << ", frame_id: " << params.frame_id;
1853 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571854 content::RenderProcessHost* render_process_host =
1855 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161856 RenderViewHostImpl::FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581857 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571858 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451859 false,
[email protected]9f76c1e2012-03-05 15:15:581860 &validated_url);
[email protected]724159a2010-12-30 01:11:181861
[email protected]d7b175e2011-10-11 15:31:581862 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181863 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1864 // This means that the interstitial won't be torn down properly, which is
1865 // bad. But if we have an interstitial, go back to another tab type, and
1866 // then load the same interstitial again, we could end up getting the first
1867 // interstitial's "failed" message (as a result of the cancel) when we're on
1868 // the second one.
1869 //
1870 // We can't tell this apart, so we think we're tearing down the current page
1871 // which will cause a crash later one. There is also some code in
1872 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1873 // out because of this problem.
1874 //
1875 // http://code.google.com/p/chromium/issues/detail?id=2855
1876 // Because this will not tear down the interstitial properly, if "back" is
1877 // back to another tab type, the interstitial will still be somewhat alive
1878 // in the previous tab type. If you navigate somewhere that activates the
1879 // tab with the interstitial again, you'll see a flash before the new load
1880 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271881 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181882 LOG(WARNING) << "Discarding message during interstitial.";
1883 return;
1884 }
1885
[email protected]02102f82011-06-13 20:37:021886 // Discard our pending entry if the load canceled (e.g. if we decided to
1887 // download the file instead of load it). We do not verify that the URL
1888 // being canceled matches the pending entry's URL because they will not
1889 // match if a redirect occurred (in which case we do not want to leave a
1890 // stale redirect URL showing). This means that we also cancel the pending
1891 // entry if the user started a new navigation. As a result, the navigation
1892 // controller may not remember that a load is in progress, but the
1893 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251894 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161895 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181896
[email protected]54047eb52012-05-08 21:45:571897 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181898 }
1899
[email protected]d8c660432011-12-22 20:51:251900 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581901 observers_,
1902 DidFailProvisionalLoad(params.frame_id,
1903 params.is_main_frame,
1904 validated_url,
1905 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461906 params.error_description,
1907 render_view_host));
[email protected]724159a2010-12-30 01:11:181908}
1909
[email protected]b172aee2012-04-10 17:05:261910void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181911 const GURL& url,
[email protected]70435962011-08-02 20:13:281912 const std::string& security_info,
1913 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181914 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281915 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191916 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181917 cache.Increment();
1918
1919 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081920 int cert_id = 0;
1921 net::CertStatus cert_status = 0;
1922 int security_bits = -1;
1923 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511924 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1925 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301926 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]6d6cfb3a2012-05-23 22:53:181927 cert_id, cert_status, http_method,
1928 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181929
[email protected]ad50def52011-10-19 23:17:071930 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271931 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501932 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531933 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181934}
1935
[email protected]b172aee2012-04-10 17:05:261936void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381937 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181938 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201939 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181940}
1941
[email protected]b172aee2012-04-10 17:05:261942void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021943 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231944 LOG(INFO) << security_origin << " ran insecure content from "
1945 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381946 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411947 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1948 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181949 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411950 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201951 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181952}
1953
[email protected]b172aee2012-04-10 17:05:261954void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181955 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251956 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101957 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181958}
1959
[email protected]b172aee2012-04-10 17:05:261960void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311961 int64 frame_id,
1962 const GURL& validated_url,
1963 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251964 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311965 DidFinishLoad(frame_id, validated_url, is_main_frame));
1966}
1967
[email protected]b172aee2012-04-10 17:05:261968void WebContentsImpl::OnDidFailLoadWithError(
1969 int64 frame_id,
1970 const GURL& validated_url,
1971 bool is_main_frame,
1972 int error_code,
1973 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251974 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311975 DidFailLoad(frame_id, validated_url, is_main_frame,
1976 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181977}
1978
[email protected]b172aee2012-04-10 17:05:261979void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271980 content_restrictions_ = restrictions;
1981 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171982}
1983
[email protected]b172aee2012-04-10 17:05:261984void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261985 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231986 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251987 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261988 if (!entry)
1989 return;
1990 // Note that we don't call NavigationController::GotToOffset() as we don't
1991 // want to create a pending navigation entry (it might end up lingering
1992 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251993 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581994 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511995 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581996 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471997 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:571998
1999 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2000 // it in now that we know. This allows us to find the entry when it commits.
2001 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232002 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332003 entry->set_site_instance(
2004 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572005 }
[email protected]216813952011-05-19 22:21:262006 }
2007}
2008
[email protected]b172aee2012-04-10 17:05:262009void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2010 int maximum_percent,
2011 bool remember) {
[email protected]216813952011-05-19 22:21:262012 minimum_zoom_percent_ = minimum_percent;
2013 maximum_zoom_percent_ = maximum_percent;
2014 temporary_zoom_settings_ = !remember;
2015}
2016
[email protected]20b433a2012-05-15 21:23:462017void WebContentsImpl::OnSaveURL(const GURL& url,
2018 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482019 download_stats::RecordDownloadSource(
2020 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262021 // Check if the URL to save matches the URL of the main frame. Since this
2022 // message originates from Pepper plugins, it may not be the case if the
2023 // plugin is an embedded element.
2024 GURL main_frame_url = GetURL();
2025 if (!main_frame_url.is_valid())
2026 return;
2027 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462028 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272029}
2030
[email protected]b172aee2012-04-10 17:05:262031void WebContentsImpl::OnEnumerateDirectory(int request_id,
2032 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:592033 ChildProcessSecurityPolicyImpl* policy =
2034 ChildProcessSecurityPolicyImpl::GetInstance();
2035 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2036 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212037}
2038
[email protected]b172aee2012-04-10 17:05:262039void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:512040 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202041}
2042
[email protected]b172aee2012-04-10 17:05:262043void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2044 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362045 const string16& title,
2046 bool user_gesture) {
[email protected]b9535422012-02-09 01:47:592047 ChildProcessSecurityPolicyImpl* policy =
2048 ChildProcessSecurityPolicyImpl::GetInstance();
2049 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2050 return;
[email protected]3a3b75a2012-06-01 08:38:362051 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202052}
2053
[email protected]b172aee2012-04-10 17:05:262054void WebContentsImpl::OnFindReply(int request_id,
2055 int number_of_matches,
2056 const gfx::Rect& selection_rect,
2057 int active_match_ordinal,
2058 bool final_update) {
[email protected]6934a702011-12-20 00:04:512059 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2060 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:002061 // Send a notification to the renderer that we are ready to receive more
2062 // results from the scoping effort of the Find operation. The FindInPage
2063 // scoping is asynchronous and periodically sends results back up to the
2064 // browser using IPC. In an effort to not spam the browser we have the
2065 // browser send an ACK for each FindReply message and have the renderer
2066 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582067 GetRenderViewHostImpl()->Send(
2068 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162069}
2070
[email protected]b172aee2012-04-10 17:05:262071void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442072 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2073 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452074}
2075
[email protected]b172aee2012-04-10 17:05:262076void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2077 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102078 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252079 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102080 AppCacheAccessed(manifest_url, blocked_by_policy));
2081}
2082
[email protected]b172aee2012-04-10 17:05:262083void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322084 SkColor color) {
[email protected]da8543762012-03-20 08:52:202085 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
2086}
2087
[email protected]b172aee2012-04-10 17:05:262088void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202089 if (color_chooser_ &&
2090 color_chooser_id == color_chooser_->identifier())
2091 color_chooser_->End();
2092}
2093
[email protected]b172aee2012-04-10 17:05:262094void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322095 SkColor color) {
[email protected]da8543762012-03-20 08:52:202096 if (color_chooser_ &&
2097 color_chooser_id == color_chooser_->identifier())
2098 color_chooser_->SetSelectedColor(color);
2099}
2100
[email protected]9f2a9d72012-04-16 16:02:222101void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2102 const FilePath& path,
2103 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442104 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2105 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292106}
2107
[email protected]d0759f492012-04-19 22:50:502108// This exists for render views that don't have a WebUI, but do have WebUI
2109// bindings enabled.
2110void WebContentsImpl::OnWebUISend(const GURL& source_url,
2111 const std::string& name,
2112 const base::ListValue& args) {
2113 if (delegate_)
2114 delegate_->WebUISend(this, source_url, name, args);
2115}
2116
[email protected]96d185d2009-04-24 03:28:542117// Notifies the RenderWidgetHost instance about the fact that the page is
2118// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262119void WebContentsImpl::SetIsLoading(bool is_loading,
2120 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542121 if (is_loading == is_loading_)
2122 return;
2123
2124 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212125 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542126 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562127 upload_size_ = 0;
2128 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542129 }
2130
2131 render_manager_.SetIsLoading(is_loading);
2132
2133 is_loading_ = is_loading;
2134 waiting_for_response_ = is_loading;
2135
[email protected]6ebdc9b2010-09-27 16:55:572136 if (delegate_)
2137 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462138 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542139
[email protected]432115822011-07-10 15:52:272140 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2141 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072142 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542143 if (details)
[email protected]6c2381d2011-10-19 02:52:532144 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072145 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502146 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542147 det);
2148}
2149
[email protected]b172aee2012-04-10 17:05:262150void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132151 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322152 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562153 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382154 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442155 // that opened the window, as long as both renderers have the same
2156 // privileges.
[email protected]1fd1a502011-03-30 16:55:562157 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562158 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582159 // web_ui might be NULL if the URL refers to a non-existent extension.
2160 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402161 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522162 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442163 }
2164 }
[email protected]1fd1a502011-03-30 16:55:562165 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442166 }
2167
[email protected]4e697b042011-07-08 06:44:562168 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322169 // Clear the status bubble. This is a workaround for a bug where WebKit
2170 // doesn't let us know that the cursor left an element during a
2171 // transition (this is also why the mouse cursor remains as a hand after
2172 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2173 // clear the bubble when a user navigates to a named anchor in the same
2174 // page.
[email protected]36fc0392011-12-25 03:59:512175 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322176 }
2177
[email protected]a6e82fc2010-02-24 22:28:142178 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472179 // Once the main frame is navigated, we're no longer considered to have
2180 // displayed insecure content.
2181 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172182 }
[email protected]ce5c4502009-05-06 16:46:112183
[email protected]3c9e1872010-11-18 16:17:492184 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252185 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042186 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322187}
2188
[email protected]b172aee2012-04-10 17:05:262189void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322190 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132191 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322192 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062193 // If we navigate off the page, reset JavaScript state. This does nothing
2194 // to prevent a malicious script from spamming messages, since the script
2195 // could just reload the page to stop blocking.
2196 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552197 dialog_creator_->ResetJavaScriptState(this);
2198 dialog_creator_ = NULL;
2199 }
[email protected]420ae012009-04-24 05:16:322200
[email protected]3c9e1872010-11-18 16:17:492201 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252202 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042203 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322204}
2205
[email protected]b172aee2012-04-10 17:05:262206void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462207 // If we are creating a RVH for a restored controller, then we need to make
2208 // sure the RenderView starts with a next_page_id_ larger than the number
2209 // of restored entries. This must be called before the RenderView starts
2210 // navigating (to avoid a race between the browser updating max_page_id and
2211 // the renderer updating next_page_id_). Because of this, we only call this
2212 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562213 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582214 if (max_restored_page_id >
2215 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2216 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2217 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322218}
2219
[email protected]b172aee2012-04-10 17:05:262220bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2221 const string16& title) {
[email protected]420ae012009-04-24 05:16:322222 // For file URLs without a title, use the pathname instead. In the case of a
2223 // synthesized title, we don't want the update to count toward the "one set
2224 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512225 string16 final_title;
[email protected]420ae012009-04-24 05:16:322226 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512227 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2228 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322229 explicit_set = false; // Don't count synthetic titles toward the set limit.
2230 } else {
[email protected]acafd272011-07-26 17:35:572231 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322232 explicit_set = true;
2233 }
2234
[email protected]987fc3a2011-05-26 14:18:092235 // If a page is created via window.open and never navigated,
2236 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552237 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092238 if (entry) {
[email protected]36fc0392011-12-25 03:59:512239 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092240 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322241
[email protected]36fc0392011-12-25 03:59:512242 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092243 } else {
2244 if (page_title_when_no_navigation_entry_ == final_title)
2245 return false; // Nothing changed, don't bother.
2246
2247 page_title_when_no_navigation_entry_ = final_title;
2248 }
[email protected]420ae012009-04-24 05:16:322249
[email protected]420ae012009-04-24 05:16:322250 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232251 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322252
[email protected]2bb171882012-03-07 02:09:462253 std::pair<content::NavigationEntry*, bool> details =
2254 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142255
[email protected]ad50def52011-10-19 23:17:072256 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442257 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2258 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462259 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042260
[email protected]420ae012009-04-24 05:16:322261 return true;
2262}
2263
[email protected]b172aee2012-04-10 17:05:262264void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322265 // After sending out a swap notification, we need to send a disconnect
2266 // notification so that clients that pick up a pointer to |this| can NULL the
2267 // pointer. See Bug 1230284.
2268 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072269 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202270 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2271 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072272 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322273}
2274
[email protected]b172aee2012-04-10 17:05:262275void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322276 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072277 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122278 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
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::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322284 if (!notify_disconnection_)
2285 return;
2286
2287 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072288 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322289 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2290 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072291 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322292}
2293
[email protected]5a3bdf52012-05-24 15:12:572294RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2295 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322296}
2297
[email protected]8d3347f2009-07-09 22:00:212298RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262299WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212300 return &render_manager_;
2301}
2302
[email protected]b172aee2012-04-10 17:05:262303content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372304 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462305 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512306}
2307
[email protected]b172aee2012-04-10 17:05:262308WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172309 return this;
2310}
2311
[email protected]b172aee2012-04-10 17:05:262312gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172313 if (delegate_)
2314 return delegate_->GetRootWindowResizerRect();
2315 return gfx::Rect();
2316}
2317
[email protected]b172aee2012-04-10 17:05:262318void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442319 // Don't send notifications if we are just creating a swapped-out RVH for
2320 // the opener chain. These won't be used for view-source or WebUI, so it's
2321 // ok to return early.
2322 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2323 return;
2324
[email protected]ad50def52011-10-19 23:17:072325 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272326 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322327 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532328 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232329 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322330 if (!entry)
2331 return;
2332
2333 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352334 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562335 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582336 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322337
2338 if (entry->IsViewSourceMode()) {
2339 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582340 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2341 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322342 }
[email protected]0666aef2009-05-13 19:48:082343
[email protected]d487beefe2011-12-21 05:41:212344 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262345
2346 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252347 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322348}
2349
[email protected]b172aee2012-04-10 17:05:262350void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522351 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322352 // Don't notify the world, since this came from a renderer in the
2353 // background.
2354 return;
2355 }
2356
2357 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312358 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232359 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302360
2361 // Restore the focus to the tab (otherwise the focus will be on the top
2362 // window).
[email protected]484ae5912010-09-29 19:16:142363 if (was_crashed && !FocusLocationBarByDefault() &&
2364 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302365 Focus();
[email protected]484ae5912010-09-29 19:16:142366 }
[email protected]32ded2212011-11-10 18:51:432367
[email protected]d8c660432011-12-22 20:51:252368 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322369}
2370
[email protected]b172aee2012-04-10 17:05:262371void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2372 base::TerminationStatus status,
2373 int error_code) {
[email protected]151a63d2011-12-20 22:32:522374 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322375 // The pending page's RenderViewHost is gone.
2376 return;
2377 }
2378
2379 SetIsLoading(false, NULL);
2380 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232381 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312382 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322383
[email protected]d8c660432011-12-22 20:51:252384 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272385 observers_,
[email protected]be1f56ab2011-12-22 06:55:312386 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322387}
2388
[email protected]b172aee2012-04-10 17:05:262389void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482390 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252391 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062392}
2393
[email protected]b172aee2012-04-10 17:05:262394void WebContentsImpl::DidNavigate(
2395 RenderViewHost* rvh,
2396 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582397 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322398 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372399
[email protected]434f69f2012-02-06 21:56:522400 // Update the site of the SiteInstance if it doesn't have one yet, unless
2401 // this is for about:blank. In that case, the SiteInstance can still be
2402 // considered unused until a navigation to a real page.
2403 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2404 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332405 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522406 }
[email protected]420ae012009-04-24 05:16:322407
2408 // Need to update MIME type here because it's referred to in
2409 // UpdateNavigationCommands() called by RendererDidNavigate() to
2410 // determine whether or not to enable the encoding menu.
2411 // It's updated only for the main frame. For a subframe,
2412 // RenderView::UpdateURL does not set params.contents_mime_type.
2413 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2414 // TODO(jungshik): Add a test for the encoding menu to avoid
2415 // regressing it again.
[email protected]2905f742011-10-13 03:51:582416 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322417 contents_mime_type_ = params.contents_mime_type;
2418
[email protected]8286f51a2011-05-31 17:39:132419 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002420 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392421
[email protected]a9c0bfe2010-09-17 08:35:222422 // Send notification about committed provisional loads. This notification is
2423 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2424 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082425 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072426 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2427 // that is not recorded in the navigation history. For the purpose of
2428 // tracking navigation events, we treat this event as a sub frame navigation
2429 // event.
2430 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582431 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222432 // Whether or not a page transition was triggered by going backward or
2433 // forward in the history is only stored in the navigation controller's
2434 // entry list.
2435 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512436 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582437 content::PAGE_TRANSITION_FORWARD_BACK)) {
2438 transition_type = content::PageTransitionFromInt(
2439 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222440 }
[email protected]0d60f0192011-04-14 12:40:102441 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252442 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102443 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462444 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222445 }
2446
[email protected]76543b92009-08-31 17:27:452447 if (!did_navigate)
2448 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322449
2450 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2451 // for the appropriate notification (best) or you can add it to
2452 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2453 // necessary, please).
2454
2455 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002456 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322457 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512458 if (delegate_)
2459 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002460 }
[email protected]420ae012009-04-24 05:16:322461 DidNavigateAnyFramePostCommit(rvh, details, params);
2462}
2463
[email protected]b172aee2012-04-10 17:05:262464void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2465 int32 page_id,
2466 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152467 // Ensure that this state update comes from either the active RVH or one of
2468 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522469 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322470
2471 // We must be prepared to handle state updates for any page, these occur
2472 // when the user is scrolling and entering form data, as well as when we're
2473 // leaving a page, in which case our state may have already been moved to
2474 // the next page. The navigation controller will look up the appropriate
2475 // NavigationEntry and update it when it is notified via the delegate.
2476
2477 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582478 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322479 if (entry_index < 0)
2480 return;
[email protected]10f417c52011-12-28 21:04:232481 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322482
[email protected]36fc0392011-12-25 03:59:512483 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322484 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512485 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322486 controller_.NotifyEntryChanged(entry, entry_index);
2487}
2488
[email protected]b172aee2012-04-10 17:05:262489void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2490 int32 page_id,
2491 const string16& title,
2492 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322493 // If we have a title, that's a pretty good indication that we've started
2494 // getting useful data.
2495 SetNotWaitingForResponse();
2496
[email protected]73eb2602012-02-09 19:50:552497 // Try to find the navigation entry, which might not be the current one.
2498 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232499 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582500 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092501
[email protected]73eb2602012-02-09 19:50:552502 // We can handle title updates when we don't have an entry in
2503 // UpdateTitleForEntry, but only if the update is from the current RVH.
2504 if (!entry && rvh != GetRenderViewHost())
2505 return;
2506
[email protected]a49e10b2011-08-01 23:57:462507 // TODO(evan): make use of title_direction.
2508 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092509 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322510 return;
2511
2512 // Broadcast notifications when the UI should be updated.
2513 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462514 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322515}
2516
[email protected]b172aee2012-04-10 17:05:262517void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2518 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312519 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322520}
2521
[email protected]b172aee2012-04-10 17:05:262522void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512523 if (delegate_)
2524 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322525}
2526
[email protected]b172aee2012-04-10 17:05:262527void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292528 // The UI may be in an event-tracking loop, such as between the
2529 // mouse-down and mouse-up in text selection or a button click.
2530 // Defer the close until after tracking is complete, so that we
2531 // don't free objects out from under the UI.
2532 // TODO(shess): This could probably be integrated with the
2533 // IsDoingDrag() test below. Punting for now because I need more
2534 // research to understand how this impacts platforms other than Mac.
2535 // TODO(shess): This could get more fine-grained. For instance,
2536 // closing a tab in another window while selecting text in the
2537 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212538 if (GetView()->IsEventTracking()) {
2539 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292540 return;
2541 }
2542
[email protected]24a4d1062009-07-10 23:10:422543 // If we close the tab while we're in the middle of a drag, we'll crash.
2544 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212545 if (GetView()->IsDoingDrag()) {
2546 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422547 return;
2548 }
2549
[email protected]420ae012009-04-24 05:16:322550 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522551 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512552 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322553}
2554
[email protected]b172aee2012-04-10 17:05:262555void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522556 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512557 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572558}
2559
[email protected]b172aee2012-04-10 17:05:262560void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512561 if (delegate_ && delegate_->IsPopupOrPanel(this))
2562 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322563}
2564
[email protected]b172aee2012-04-10 17:05:262565void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322566 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492567
[email protected]82114f52012-03-20 22:53:412568 if (delegate_ && content_restrictions_)
2569 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492570
2571 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252572 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322573}
2574
[email protected]b172aee2012-04-10 17:05:262575void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322576 scoped_ptr<LoadNotificationDetails> details;
2577
[email protected]10f417c52011-12-28 21:04:232578 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322579 // An entry may not exist for a stop when loading an initial blank page or
2580 // if an iframe injected by script into a blank page finishes loading.
2581 if (entry) {
[email protected]420ae012009-04-24 05:16:322582 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2583
2584 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512585 entry->GetVirtualURL(),
2586 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322587 elapsed,
2588 &controller_,
2589 controller_.GetCurrentEntryIndex()));
2590 }
2591
[email protected]420ae012009-04-24 05:16:322592 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492593
2594 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252595 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322596}
2597
[email protected]b172aee2012-04-10 17:05:262598void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162599 controller_.DiscardNonCommittedEntries();
2600
2601 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462602 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162603}
2604
[email protected]b172aee2012-04-10 17:05:262605void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512606 if (delegate_)
2607 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402608}
2609
[email protected]87717d0e2012-04-26 02:58:432610void WebContentsImpl::DocumentAvailableInMainFrame(
2611 RenderViewHost* render_view_host) {
2612 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2613 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102614}
2615
[email protected]b172aee2012-04-10 17:05:262616void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082617 RenderViewHost* render_view_host,
2618 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072619 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272620 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322621 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532622 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082623}
2624
[email protected]196159d2012-05-04 17:26:542625void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2626 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262627 const content::Referrer& referrer,
2628 WindowOpenDisposition disposition,
2629 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542630 // If this came from a swapped out RenderViewHost, we only allow the request
2631 // if we are still in the same BrowsingInstance.
2632 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2633 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2634 return;
2635 }
2636
[email protected]4ad5d77d2011-12-03 02:00:482637 // Delegate to RequestTransferURL because this is just the generic
2638 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582639 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482640 GlobalRequestID());
2641}
2642
[email protected]b172aee2012-04-10 17:05:262643void WebContentsImpl::RequestTransferURL(
2644 const GURL& url,
2645 const content::Referrer& referrer,
2646 WindowOpenDisposition disposition,
2647 int64 source_frame_id,
2648 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202649 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582650 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582651 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352652 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322653 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2654 // generated suggestions).
2655 //
[email protected]e0112912011-02-02 22:54:352656 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162657 // want web sites to see a referrer of "chrome://blah" (and some
2658 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322659 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432660 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222661 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482662 false /* is_renderer_initiated */);
2663 params.transferred_global_request_id = old_request_id;
2664 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222665 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322666 } else {
[email protected]6bf6a6b52012-02-03 15:41:432667 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482668 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2669 params.transferred_global_request_id = old_request_id;
2670 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582671 }
2672 if (new_contents) {
2673 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252674 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582675 DidOpenRequestedURL(new_contents,
2676 url,
2677 referrer,
2678 disposition,
2679 transition_type,
2680 source_frame_id));
[email protected]420ae012009-04-24 05:16:322681 }
2682}
2683
[email protected]e1c3a552012-05-04 20:51:322684void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2685 // Tell the active RenderViewHost to run unload handlers and close, as long
2686 // as the request came from a RenderViewHost in the same BrowsingInstance.
2687 // In most cases, we receive this from a swapped out RenderViewHost.
2688 // It is possible to receive it from one that has just been swapped in,
2689 // in which case we might as well deliver the message anyway.
2690 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2691 GetRenderViewHost()->ClosePage();
2692}
2693
[email protected]f546640b2012-05-15 00:03:492694void WebContentsImpl::RouteMessageEvent(
2695 RenderViewHost* rvh,
2696 const ViewMsg_PostMessage_Params& params) {
2697 // Only deliver the message to the active RenderViewHost if the request
2698 // came from a RenderViewHost in the same BrowsingInstance.
2699 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2700 return;
2701
2702 ViewMsg_PostMessage_Params new_params(params);
2703
2704 // If there is a source_routing_id, translate it to the routing ID for
2705 // the equivalent swapped out RVH in the target process. If we need
2706 // to create a swapped out RVH for the source tab, we create its opener
2707 // chain as well, since those will also be accessible to the target page.
2708 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2709 // Try to look up the WebContents for the source page.
2710 WebContentsImpl* source_contents = NULL;
2711 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2712 rvh->GetProcess()->GetID(), params.source_routing_id);
2713 if (source_rvh) {
2714 source_contents = static_cast<WebContentsImpl*>(
2715 source_rvh->GetDelegate()->GetAsWebContents());
2716 }
2717
2718 if (source_contents) {
2719 new_params.source_routing_id =
2720 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2721 } else {
2722 // We couldn't find it, so don't pass a source frame.
2723 new_params.source_routing_id = MSG_ROUTING_NONE;
2724 }
2725 }
2726
2727 // In most cases, we receive this from a swapped out RenderViewHost.
2728 // It is possible to receive it from one that has just been swapped in,
2729 // in which case we might as well deliver the message anyway.
2730 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2731 GetRenderViewHost()->GetRoutingID(), new_params));
2732}
2733
[email protected]b172aee2012-04-10 17:05:262734void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342735 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412736 const string16& message,
2737 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322738 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142739 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322740 IPC::Message* reply_msg,
2741 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072742 // Suppress JavaScript dialogs when requested. Also suppress messages when
2743 // showing an interstitial as it's shown over the previous page and we don't
2744 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502745 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582746 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272747 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072748 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522749 delegate_->ShouldSuppressDialogs() ||
2750 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322751
2752 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432753 std::string accept_lang = content::GetContentClient()->browser()->
2754 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552755 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522756 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432757 this,
2758 frame_url.GetOrigin(),
2759 accept_lang,
2760 javascript_message_type,
2761 message,
[email protected]51da7e32012-01-30 19:24:522762 default_prompt,
[email protected]b172aee2012-04-10 17:05:262763 base::Bind(&WebContentsImpl::OnDialogClosed,
2764 base::Unretained(this),
2765 rvh,
2766 reply_msg),
[email protected]51da7e32012-01-30 19:24:522767 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322768 }
[email protected]3ab9cb82011-06-03 18:02:072769
2770 if (suppress_this_message) {
2771 // If we are suppressing messages, just reply as if the user immediately
2772 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342773 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072774 }
2775
2776 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322777}
2778
[email protected]b172aee2012-04-10 17:05:262779void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2780 const string16& message,
2781 bool is_reload,
2782 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582783 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512784 if (delegate_)
2785 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072786
2787 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582788 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072789 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522790 delegate_->ShouldSuppressDialogs() ||
2791 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152792 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342793 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582794 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502795 return;
2796 }
[email protected]3ab9cb82011-06-03 18:02:072797
[email protected]7ab1e7d62009-10-14 23:32:012798 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552799 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522800 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322801 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262802 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522803 reply_msg));
[email protected]420ae012009-04-24 05:16:322804}
2805
[email protected]a796f202012-05-30 14:14:252806bool WebContentsImpl::AddMessageToConsole(int32 level,
2807 const string16& message,
2808 int32 line_no,
2809 const string16& source_id) {
2810 if (!delegate_)
2811 return false;
2812 return delegate_->AddMessageToConsole(this, level, message, line_no,
2813 source_id);
2814}
2815
[email protected]b172aee2012-04-10 17:05:262816WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332817 // We want to base the page config off of the real URL, rather than the
2818 // display URL.
2819 GURL url = controller_.GetActiveEntry()
2820 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2821 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322822}
2823
[email protected]b172aee2012-04-10 17:05:262824void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272825 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252826 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222827
[email protected]ea114722012-03-12 01:11:252828 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172829 if (rdh) // NULL in unittests.
2830 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252831}
2832
[email protected]b172aee2012-04-10 17:05:262833void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442834 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252835 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442836}
2837
[email protected]b172aee2012-04-10 17:05:262838void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2839 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152840 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522841 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152842 return;
2843
[email protected]9f76c1e2012-03-05 15:15:582844 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2845
[email protected]e5fc1632011-08-08 07:51:532846 // Ignore renderer unresponsive event if debugger is attached to the tab
2847 // since the event may be a result of the renderer sitting on a breakpoint.
2848 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442849 DevToolsAgentHost* agent =
2850 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2851 if (agent &&
2852 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532853 return;
2854
[email protected]420ae012009-04-24 05:16:322855 if (is_during_unload) {
2856 // Hang occurred while firing the beforeunload/unload handler.
2857 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582858 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322859
2860 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2861 return;
2862
2863 // If the tab hangs in the beforeunload/unload handler there's really
2864 // nothing we can do to recover. Pretend the unload listeners have
2865 // all fired and close the tab. If the hang is in the beforeunload handler
2866 // then the user will not have the option of cancelling the close.
2867 Close(rvh);
2868 return;
2869 }
2870
[email protected]9f76c1e2012-03-05 15:15:582871 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472872 return;
2873
[email protected]6934a702011-12-20 00:04:512874 if (delegate_)
2875 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322876}
2877
[email protected]b172aee2012-04-10 17:05:262878void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512879 if (delegate_)
2880 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322881}
2882
[email protected]b172aee2012-04-10 17:05:262883void WebContentsImpl::LoadStateChanged(
2884 const GURL& url,
2885 const net::LoadStateWithParam& load_state,
2886 uint64 upload_position,
2887 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322888 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562889 upload_position_ = upload_position;
2890 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502891 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202892 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302893 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212894 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322895 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462896 if (IsLoading()) {
2897 NotifyNavigationStateChanged(
2898 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2899 }
[email protected]420ae012009-04-24 05:16:322900}
2901
[email protected]b172aee2012-04-10 17:05:262902void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512903 if (delegate_)
2904 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252905}
2906
[email protected]b172aee2012-04-10 17:05:262907void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322908 bool proceed,
2909 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512910 if (delegate_)
2911 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322912}
2913
[email protected]b172aee2012-04-10 17:05:262914void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542915 RenderViewHost* render_view_host) {
2916 DidStartLoading();
2917}
2918
[email protected]b172aee2012-04-10 17:05:262919void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542920 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232921 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2922 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542923}
2924
[email protected]b172aee2012-04-10 17:05:262925void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102926 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262927 gfx::Size size = view_->GetContainerSize();
2928 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2929 // here during container initialization and normal window size will be set
2930 // later. In case of tab duplication this resizing to 0x0 prevents setting
2931 // normal size later so just ignore it.
2932 if (!size.IsEmpty())
2933 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322934}
2935
[email protected]b172aee2012-04-10 17:05:262936void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542937 NotifySwapped();
2938}
2939
[email protected]14392a52012-05-02 20:28:442940int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2941 SiteInstance* instance) {
2942 if (!opener_)
2943 return MSG_ROUTING_NONE;
2944
2945 // Recursively create RenderViews for anything else in the opener chain.
2946 return opener_->CreateOpenerRenderViews(instance);
2947}
2948
2949int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2950 int opener_route_id = MSG_ROUTING_NONE;
2951
2952 // If this tab has an opener, ensure it has a RenderView in the given
2953 // SiteInstance as well.
2954 if (opener_)
2955 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2956
2957 // Create a swapped out RenderView in the given SiteInstance if none exists,
2958 // setting its opener to the given route_id. Return the new view's route_id.
2959 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2960}
2961
[email protected]b172aee2012-04-10 17:05:262962NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202963 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542964}
2965
[email protected]b172aee2012-04-10 17:05:262966WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562967 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322968}
2969
[email protected]10f417c52011-12-28 21:04:232970NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262971 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322972 return controller_.GetLastCommittedEntry();
2973}
2974
[email protected]b172aee2012-04-10 17:05:262975bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442976 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442977 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322978 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522979
[email protected]420ae012009-04-24 05:16:322980 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442981 if (rwh_view)
2982 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322983
[email protected]74ce1ad2011-12-16 21:51:462984 // Make sure we use the correct starting page_id in the new RenderView.
2985 UpdateMaxPageIDIfNecessary(render_view_host);
2986 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582987 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462988
[email protected]7900bfdb2012-05-24 19:31:242989 std::string embedder_channel_name;
2990 int embedder_container_id;
2991 GetBrowserPluginEmbedderInfo(render_view_host,
2992 &embedder_channel_name,
2993 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:582994 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:492995 render_view_host)->CreateRenderView(string16(),
2996 opener_route_id,
2997 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:242998 embedder_channel_name,
2999 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523000 return false;
[email protected]14392a52012-05-02 20:28:443001 }
[email protected]a4127722011-04-27 23:13:523002
[email protected]e60c0232011-11-11 19:56:353003#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503004 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3005 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443006 if (rwh_view) {
3007 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3008 render_widget_host->WasResized();
3009 }
[email protected]f8233cc2011-05-31 20:24:503010#endif
3011
[email protected]420ae012009-04-24 05:16:323012 return true;
3013}
3014
[email protected]b172aee2012-04-10 17:05:263015void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3016 IPC::Message* reply_msg,
3017 bool success,
3018 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543019 if (is_showing_before_unload_dialog_ && !success) {
3020 // If a beforeunload dialog is canceled, we need to stop the throbber from
3021 // spinning, since we forced it to start spinning in Navigate.
3022 DidStopLoading();
3023
[email protected]3bbacc5b2012-04-17 17:46:153024 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543025 }
3026 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583027 static_cast<RenderViewHostImpl*>(
3028 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543029}
3030
[email protected]b172aee2012-04-10 17:05:263031void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123032 encoding_ = content::GetContentClient()->browser()->
3033 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103034}
[email protected]f45d2a72010-03-08 23:28:353035
[email protected]b172aee2012-04-10 17:05:263036void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463037 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263038 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143039 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
3040 if (!dlm)
3041 return;
3042 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263043 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143044 const NavigationEntry* entry = controller_.GetActiveEntry();
3045 if (entry)
3046 post_id = entry->GetPostID();
3047 }
[email protected]29a5ffc82012-03-13 19:35:583048 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143049 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143050 scoped_ptr<DownloadUrlParameters> params(
3051 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493052 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143053 params->set_post_id(post_id);
3054 params->set_prefer_cache(true);
3055 if (post_id >= 0)
3056 params->set_method("POST");
3057 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143058}
3059
[email protected]b172aee2012-04-10 17:05:263060void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213061 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443062 // Can be NULL during tests.
3063 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213064 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363065}
[email protected]9f76c1e2012-03-05 15:15:583066
[email protected]b172aee2012-04-10 17:05:263067RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583068 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3069}
[email protected]7900bfdb2012-05-24 19:31:243070
3071void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3072 content::RenderViewHost* render_view_host,
3073 std::string* embedder_channel_name,
3074 int* embedder_container_id) {
3075 content::RenderProcessHost* embedder_render_process_host =
3076 browser_plugin_host()->embedder_render_process_host();
3077 *embedder_container_id = browser_plugin_host()->instance_id();
3078 int embedder_process_id =
3079 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3080 if (embedder_process_id != -1) {
3081 *embedder_channel_name =
3082 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3083 embedder_process_id);
3084 }
3085}