blob: 3bb76232d68176d69e78fed464264d7b9fd2fd5b [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]3c733bde2010-12-21 19:56:3175#include "webkit/glue/webpreferences.h"
76
[email protected]f66df822012-05-18 16:52:1777#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5078#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4179#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5780#endif
[email protected]3e45ba92009-02-20 21:09:0081
[email protected]420ae012009-04-24 05:16:3282// Cross-Site Navigations
83//
[email protected]b172aee2012-04-10 17:05:2684// If a WebContentsImpl is told to navigate to a different web site (as
85// determined by SiteInstance), it will replace its current RenderViewHost with
86// a new RenderViewHost dedicated to the new SiteInstance. This works as
87// follows:
[email protected]420ae012009-04-24 05:16:3288//
89// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4690// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3291// - The pending RVH is "suspended," so that no navigation messages are sent to
92// its renderer until the onbeforeunload JavaScript handler has a chance to
93// run in the current RVH.
94// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
95// that it has a pending cross-site request. ResourceDispatcherHost will
96// check for this when the response arrives.
97// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4698// cancel all the pending logic. Otherwise we allow the pending RVH to send
99// the navigation request to its renderer.
100// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
101// main resource load on the pending RVH. It checks CrossSiteRequestManager
102// to see that it is a cross-site request, and installs a
103// CrossSiteResourceHandler.
104// - When RDH receives a response, the BufferedResourceHandler determines
105// whether it is a download. If so, it sends a message to the new renderer
106// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26107// pending RVH remains until the next DidNavigate event for this
108// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32109// - After RDH receives a response and determines that it is safe and not a
110// download, it pauses the response to first run the old page's onunload
111// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26112// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32113// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15114// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32115// the ResourceDispatcherHost, who unpauses the response. Data is then sent
116// to the pending RVH.
117// - The pending renderer sends a FrameNavigate message that invokes the
118// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46119// pending RVH.
[email protected]992db4c2011-05-12 15:37:15120// - The previous renderer is kept swapped out in RenderViewHostManager in case
121// the user goes back. The process only stays live if another tab is using
122// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32123
[email protected]0e12d7d2011-12-01 16:21:44124using content::DevToolsAgentHost;
125using content::DevToolsAgentHostRegistry;
126using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17127using content::DownloadItem;
128using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14129using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20130using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56131using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13132using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27133using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54134using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50135using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23136using content::NavigationEntry;
137using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20138using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11139using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57140using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57141using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27142using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11143using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50144using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58145using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04146using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25147using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14148using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43149using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33150using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38151using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09152using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25153using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56154using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22155using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50156using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25157using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44158
[email protected]420ae012009-04-24 05:16:32159namespace {
160
161// Amount of time we wait between when a key event is received and the renderer
162// is queried for its state and pushed to the NavigationEntry.
163const int kQueryStateDelay = 5000;
164
[email protected]6ebdc9b2010-09-27 16:55:57165const int kSyncWaitDelay = 40;
166
[email protected]82114f52012-03-20 22:53:41167const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05168
[email protected]420ae012009-04-24 05:16:32169#if defined(OS_WIN)
170
171BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
172 // Note: erase is required to properly paint some widgets borders. This can
173 // be seen with textfields.
174 InvalidateRect(hwnd, NULL, TRUE);
175 return TRUE;
176}
177#endif
178
[email protected]2c5569662011-03-22 20:45:02179ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23180 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50181 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16182 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47183 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02184 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47185 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02186 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47187 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16188 break; // Fall through to rest of function.
189 }
[email protected]5e369672009-11-03 23:48:30190
[email protected]59246c572012-02-10 13:32:13191 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
192 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23193 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13194 browser_context->DidLastSessionExitCleanly()) {
195 if (entry.GetHasPostData())
196 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02197 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13198 }
[email protected]5e369672009-11-03 23:48:30199
[email protected]2c5569662011-03-22 20:45:02200 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30201}
202
[email protected]10f417c52011-12-28 21:04:23203void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47204 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42205 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50206 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24207 const std::string& embedder_channel_name,
208 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16209 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51210 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54211 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55212 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
213 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51214 params->url = entry.GetURL();
215 params->referrer = entry.GetReferrer();
216 params->transition = entry.GetTransitionType();
217 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00218 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55219 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34220 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47221 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48222 params->transferred_request_child_id =
223 entry.transferred_global_request_id().child_id;
224 params->transferred_request_request_id =
225 entry.transferred_global_request_id().request_id;
[email protected]80744782012-05-04 01:47:00226 // Avoid downloading when in view-source mode.
227 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24228 params->embedder_channel_name = embedder_channel_name;
229 params->embedder_container_id = embedder_container_id;
[email protected]6c6b02d2011-09-02 03:36:47230
231 if (delegate)
232 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34233}
234
[email protected]f98f5092012-05-19 00:08:14235int GetSwitchValueAsInt(
236 const CommandLine& command_line,
237 const std::string& switch_string,
238 int min_value) {
239 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
240 int int_value;
241 if (base::StringToInt(string_value, &int_value))
242 return std::max(min_value, int_value);
243 else
244 return min_value;
245}
246
[email protected]420ae012009-04-24 05:16:32247} // namespace
248
[email protected]a81343d232011-12-27 07:39:20249namespace content {
250
251WebContents* WebContents::Create(
252 BrowserContext* browser_context,
253 SiteInstance* site_instance,
254 int routing_id,
[email protected]b172aee2012-04-10 17:05:26255 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20256 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26257 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43258 browser_context,
259 site_instance,
260 routing_id,
[email protected]b172aee2012-04-10 17:05:26261 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44262 NULL,
[email protected]adbfb8df2012-02-24 01:19:43263 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20264}
[email protected]746d3052012-05-22 15:15:47265
[email protected]299d7f12012-05-23 05:31:15266WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47267 return rvh->GetDelegate()->GetAsWebContents();
268}
269
[email protected]a81343d232011-12-27 07:39:20270}
[email protected]f4f50ef2011-01-21 19:01:19271
[email protected]b172aee2012-04-10 17:05:26272// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32273
[email protected]b172aee2012-04-10 17:05:26274WebContentsImpl::WebContentsImpl(
275 content::BrowserContext* browser_context,
276 SiteInstance* site_instance,
277 int routing_id,
278 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44279 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26280 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42281 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07282 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37283 this, browser_context, session_storage_namespace)),
[email protected]5a3bdf52012-05-24 15:12:57284 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44285 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05286 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34287 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23288 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
289 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34290 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21291 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56292 upload_size_(0),
293 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47294 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57295 capturing_contents_(false),
296 is_being_destroyed_(false),
297 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55298 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57299#if defined(OS_WIN)
300 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
301#endif
[email protected]7ab1e7d62009-10-14 23:32:01302 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56303 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38304 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25305 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01306 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25307 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01308 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00309 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43310 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20311 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37312 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32313
[email protected]38b098f2012-03-14 21:11:57314 view_.reset(content::GetContentClient()->browser()->
[email protected]5a3bdf52012-05-24 15:12:57315 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
316 if (view_.get()) {
317 CHECK(render_view_host_delegate_view_);
318 } else {
[email protected]38b098f2012-03-14 21:11:57319 content::WebContentsViewDelegate* delegate =
320 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
321 this);
[email protected]5a3bdf52012-05-24 15:12:57322 view_.reset(CreateWebContentsView(
323 this, delegate, &render_view_host_delegate_view_));
324 CHECK(render_view_host_delegate_view_);
[email protected]38b098f2012-03-14 21:11:57325 }
326 CHECK(view_.get());
327
[email protected]ca13a442012-04-17 14:00:12328 // We have the initial size of the view be based on the size of the view of
329 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26330 view_->CreateView(base_web_contents ?
331 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00332
[email protected]14392a52012-05-02 20:28:44333 // Listen for whether our opener gets destroyed.
334 if (opener_) {
335 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
336 content::Source<WebContents>(opener_));
337 }
338
[email protected]bafe6cd2012-05-23 23:09:50339 registrar_.Add(this,
340 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
341 content::NotificationService::AllBrowserContextsAndSources());
342
[email protected]483623eb2011-10-25 09:30:00343#if defined(ENABLE_JAVA_BRIDGE)
344 java_bridge_dispatcher_host_manager_.reset(
345 new JavaBridgeDispatcherHostManager(this));
346#endif
[email protected]172cf712012-05-23 15:07:39347
348 browser_plugin_host_.reset(new content::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35349}
initial.commit09911bf2008-07-26 23:55:29350
[email protected]b172aee2012-04-10 17:05:26351WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32352 is_being_destroyed_ = true;
353
[email protected]3ab9cb82011-06-03 18:02:07354 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55355 if (dialog_creator_)
356 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07357
[email protected]da8543762012-03-20 08:52:20358 if (color_chooser_)
359 color_chooser_->End();
360
[email protected]420ae012009-04-24 05:16:32361 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32362
[email protected]ca13a442012-04-17 14:00:12363 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07364 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09365 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
366 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07367 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32368
369 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07370#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32371 // If we still have a window handle, destroy it. GetNativeView can return
372 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42373 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52374 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58375 if (host && host->GetView())
376 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42377 }
[email protected]420ae012009-04-24 05:16:32378#endif
[email protected]7ab1e7d62009-10-14 23:32:01379
380 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15381 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01382 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15383 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01384 }
[email protected]b5a1d11c2011-02-17 03:09:42385
[email protected]2db9bd72012-04-13 20:20:56386 FOR_EACH_OBSERVER(WebContentsObserver,
387 observers_,
388 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08389
[email protected]6934a702011-12-20 00:04:51390 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42391}
392
[email protected]b172aee2012-04-10 17:05:26393WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
394 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54395 WebPreferences prefs;
396
397 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
398
399 prefs.developer_extras_enabled = true;
400 prefs.javascript_enabled =
401 !command_line.HasSwitch(switches::kDisableJavaScript);
402 prefs.web_security_enabled =
403 !command_line.HasSwitch(switches::kDisableWebSecurity);
404 prefs.plugins_enabled =
405 !command_line.HasSwitch(switches::kDisablePlugins);
406 prefs.java_enabled =
407 !command_line.HasSwitch(switches::kDisableJava);
408
409 prefs.uses_page_cache =
410 command_line.HasSwitch(switches::kEnableFastback);
411 prefs.remote_fonts_enabled =
412 !command_line.HasSwitch(switches::kDisableRemoteFonts);
413 prefs.xss_auditor_enabled =
414 !command_line.HasSwitch(switches::kDisableXSSAuditor);
415 prefs.application_cache_enabled =
416 !command_line.HasSwitch(switches::kDisableApplicationCache);
417
418 prefs.local_storage_enabled =
419 !command_line.HasSwitch(switches::kDisableLocalStorage);
420 prefs.databases_enabled =
421 !command_line.HasSwitch(switches::kDisableDatabases);
422 prefs.webaudio_enabled =
423 !command_line.HasSwitch(switches::kDisableWebAudio);
424
425 prefs.experimental_webgl_enabled =
426 GpuProcessHost::gpu_enabled() &&
427 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
428 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
429
430 prefs.gl_multisampling_enabled =
431 !command_line.HasSwitch(switches::kDisableGLMultisampling);
432 prefs.privileged_webgl_extensions_enabled =
433 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
434 prefs.site_specific_quirks_enabled =
435 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
436 prefs.allow_file_access_from_file_urls =
437 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
438 prefs.show_composited_layer_borders =
439 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
440 prefs.show_composited_layer_tree =
441 command_line.HasSwitch(switches::kShowCompositedLayerTree);
442 prefs.show_fps_counter =
443 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19444 prefs.show_paint_rects =
445 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]64d69de42012-02-06 00:19:54446 prefs.accelerated_compositing_enabled =
447 GpuProcessHost::gpu_enabled() &&
448 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54449 prefs.force_compositing_mode =
450 command_line.HasSwitch(switches::kForceCompositingMode);
451 prefs.fixed_position_compositing_enabled =
452 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
453 prefs.accelerated_2d_canvas_enabled =
454 GpuProcessHost::gpu_enabled() &&
455 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58456 prefs.deferred_2d_canvas_enabled =
[email protected]00bbad22012-05-25 13:24:17457 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36458 prefs.threaded_animation_enabled =
[email protected]efcde132012-05-30 01:05:18459 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54460 prefs.accelerated_painting_enabled =
461 GpuProcessHost::gpu_enabled() &&
462 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
463 prefs.accelerated_filters_enabled =
464 GpuProcessHost::gpu_enabled() &&
465 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
466 prefs.accelerated_layers_enabled =
467 prefs.accelerated_animation_enabled =
468 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54469 prefs.accelerated_plugins_enabled =
470 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
471 prefs.accelerated_video_enabled =
472 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
473 prefs.partial_swap_enabled =
474 command_line.HasSwitch(switches::kEnablePartialSwap);
475 prefs.interactive_form_validation_enabled =
476 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
477 prefs.fullscreen_enabled =
478 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16479 prefs.css_regions_enabled =
480 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29481 prefs.css_shaders_enabled =
482 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]a08412b62012-05-29 21:28:56483 prefs.device_supports_touch =
484 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]64d69de42012-02-06 00:19:54485
486#if defined(OS_MACOSX)
487 bool default_enable_scroll_animator = true;
488#else
489 // On CrOS, the launcher always passes in the --enable flag.
490 bool default_enable_scroll_animator = false;
491#endif
492 prefs.enable_scroll_animator = default_enable_scroll_animator;
493 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
494 prefs.enable_scroll_animator = true;
495 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
496 prefs.enable_scroll_animator = false;
497
498 prefs.visual_word_movement_enabled =
499 command_line.HasSwitch(switches::kEnableVisualWordMovement);
500 prefs.per_tile_painting_enabled =
501 command_line.HasSwitch(switches::kEnablePerTilePainting);
502
503 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32504 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54505 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11506 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
507 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54508 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11509 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54510 prefs.experimental_webgl_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11511 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54512 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11513 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54514 prefs.gl_multisampling_enabled = false;
515
516 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45517 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32518 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54519 prefs.accelerated_video_enabled = false;
520 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45521 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09522 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54523 }
524 }
525
[email protected]b9535422012-02-09 01:47:59526 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58527 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54528 prefs.loads_images_automatically = true;
529 prefs.javascript_enabled = true;
530 }
531
532 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
533
534 // Force accelerated compositing and 2d canvas off for chrome:, about: and
535 // chrome-devtools: pages (unless it's specifically allowed).
536 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54537 url.SchemeIs(chrome::kChromeUIScheme) ||
538 (url.SchemeIs(chrome::kAboutScheme) &&
539 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25540 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54541 prefs.accelerated_compositing_enabled = false;
542 prefs.accelerated_2d_canvas_enabled = false;
543 }
[email protected]8b3b36152012-05-01 04:55:07544#if defined(OS_MACOSX)
545 // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
546 // crbug.com/125690.
[email protected]82c9a8e2012-05-02 01:07:23547 prefs.default_device_scale_factor =
548 gfx::Monitor::GetDefaultDeviceScaleFactor();
[email protected]8b3b36152012-05-01 04:55:07549#else
550 if (rvh->GetView()) {
551 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
552 rvh->GetView()->GetNativeView());
553 prefs.default_device_scale_factor =
554 static_cast<int>(monitor.device_scale_factor());
555 } else {
[email protected]82c9a8e2012-05-02 01:07:23556 prefs.default_device_scale_factor =
557 gfx::Monitor::GetDefaultDeviceScaleFactor();;
[email protected]8b3b36152012-05-01 04:55:07558 }
559#endif
[email protected]43d9d782012-03-01 15:40:09560
[email protected]f98f5092012-05-19 00:08:14561 if (command_line.HasSwitch(switches::kDefaultTileWidth))
562 prefs.default_tile_width =
563 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
564 if (command_line.HasSwitch(switches::kDefaultTileHeight))
565 prefs.default_tile_height =
566 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
567 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
568 prefs.max_untiled_layer_width =
569 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
570 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
571 prefs.max_untiled_layer_height =
572 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
573
[email protected]2486dce2012-05-23 17:18:19574 if (gfx::Screen::IsDIPEnabled()) {
575 // Only apply when using DIP coordinate system as this setting interferes
576 // with fixed layout mode.
577 prefs.apply_default_device_scale_factor_in_compositor = true;
578 }
579
[email protected]96bcdc102012-05-24 23:42:10580 prefs.fixed_position_creates_stacking_context =
581 command_line.HasSwitch(switches::kFixedPositionCreatesStackingContext);
582
[email protected]2e21fe292012-03-02 22:52:32583 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54584
585 return prefs;
586}
587
[email protected]b172aee2012-04-10 17:05:26588NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20589 return controller_;
590}
591
[email protected]b172aee2012-04-10 17:05:26592RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28593 return &render_manager_;
594}
595
[email protected]b172aee2012-04-10 17:05:26596bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56597 if (GetWebUI() &&
598 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17599 return true;
[email protected]d2353452012-01-19 19:53:56600 }
[email protected]f82d57b52011-04-27 19:13:17601
[email protected]d8c660432011-12-22 20:51:25602 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
603 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10604 while ((observer = it.GetNext()) != NULL)
605 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53606 return true;
[email protected]403415a2011-01-10 18:57:53607
[email protected]724159a2010-12-30 01:11:18608 bool handled = true;
609 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26610 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58611 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
612 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24613 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
614 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18615 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
616 OnDidLoadResourceFromMemoryCache)
617 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
618 OnDidDisplayInsecureContent)
619 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
620 OnDidRunInsecureContent)
621 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
622 OnDocumentLoadedInFrame)
623 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26624 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
625 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17626 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
627 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25628 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26629 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59630 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21631 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20632 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
633 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
634 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16635 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45636 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10637 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20638 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
639 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
640 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
641 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29642 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50643 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18644 IPC_MESSAGE_UNHANDLED(handled = false)
645 IPC_END_MESSAGE_MAP_EX()
646
647 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38648 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18649 GetRenderProcessHost()->ReceivedBadMessage();
650 }
651
652 return handled;
653}
654
[email protected]b172aee2012-04-10 17:05:26655void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18656 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23657 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51658 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18659}
660
[email protected]b172aee2012-04-10 17:05:26661NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56662 return controller_;
663}
664
[email protected]b172aee2012-04-10 17:05:26665const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56666 return controller_;
667}
668
[email protected]b172aee2012-04-10 17:05:26669content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55670 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30671}
672
[email protected]b172aee2012-04-10 17:05:26673const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31674 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23675 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51676 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31677}
678
679
[email protected]b172aee2012-04-10 17:05:26680const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31681 return &property_bag_;
682}
683
[email protected]b172aee2012-04-10 17:05:26684base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31685 return &property_bag_;
686}
687
[email protected]b172aee2012-04-10 17:05:26688content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31689 return delegate_;
690}
691
[email protected]b172aee2012-04-10 17:05:26692void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31693 // TODO(cbentzel): remove this debugging code?
694 if (delegate == delegate_)
695 return;
696 if (delegate_)
697 delegate_->Detach(this);
698 delegate_ = delegate;
699 if (delegate_)
700 delegate_->Attach(this);
701}
702
[email protected]b172aee2012-04-10 17:05:26703content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41704 RenderViewHostImpl* host = render_manager_.current_host();
705 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16706}
707
[email protected]b172aee2012-04-10 17:05:26708RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31709 return render_manager_.current_host();
710}
711
[email protected]b172aee2012-04-10 17:05:26712RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31713 return render_manager_.GetRenderWidgetHostView();
714}
715
[email protected]b172aee2012-04-10 17:05:26716content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31717 return view_.get();
718}
719
[email protected]b172aee2012-04-10 17:05:26720content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50721 WebUIControllerFactory* factory =
722 content::GetContentClient()->browser()->GetWebUIControllerFactory();
723 if (!factory)
724 return NULL;
[email protected]d2353452012-01-19 19:53:56725 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22726 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50727 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22728 if (controller) {
729 web_ui->SetController(controller);
730 return web_ui;
731 }
732
733 delete web_ui;
734 return NULL;
735}
736
[email protected]b172aee2012-04-10 17:05:26737content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31738 return render_manager_.web_ui() ? render_manager_.web_ui()
739 : render_manager_.pending_web_ui();
740}
741
[email protected]b172aee2012-04-10 17:05:26742content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31743 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34744}
745
[email protected]86ef6a392012-05-11 22:03:11746void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
747 user_agent_override_ = override;
748}
749
750const std::string& WebContentsImpl::GetUserAgentOverride() const {
751 return user_agent_override_;
752}
753
[email protected]b172aee2012-04-10 17:05:26754const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55755 // Transient entries take precedence. They are used for interstitial pages
756 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23757 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08758 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20759 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30760 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23761 if (entry) {
[email protected]b5cca982011-05-26 04:42:08762 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23763 }
[email protected]7ade2732011-02-10 00:13:58764 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
765 render_manager_.pending_web_ui() : render_manager_.web_ui();
766 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54767 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55768 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54769 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35770 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22771 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54772 if (!title.empty())
773 return title;
774 }
775 }
776
777 // We use the title for the last committed entry rather than a pending
778 // navigation entry. For example, when the user types in a URL, we want to
779 // keep the old page's title until the new load has committed and we get a new
780 // title.
[email protected]96d185d2009-04-24 03:28:54781 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23782 if (entry) {
[email protected]b5cca982011-05-26 04:42:08783 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23784 }
[email protected]987fc3a2011-05-26 14:18:09785
786 // |page_title_when_no_navigation_entry_| is finally used
787 // if no title cannot be retrieved.
788 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54789}
790
[email protected]b172aee2012-04-10 17:05:26791int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46792 return GetMaxPageIDForSiteInstance(GetSiteInstance());
793}
794
[email protected]b172aee2012-04-10 17:05:26795int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
796 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33797 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
798 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46799
[email protected]b6583592012-01-25 19:52:33800 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34801}
802
[email protected]b172aee2012-04-10 17:05:26803void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46804 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
805}
806
[email protected]b172aee2012-04-10 17:05:26807void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33808 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46809 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33810 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34811}
812
[email protected]b172aee2012-04-10 17:05:26813void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
814 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57815}
816
[email protected]b172aee2012-04-10 17:05:26817SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58818 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54819}
820
[email protected]b172aee2012-04-10 17:05:26821SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38822 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
823 render_manager_.pending_render_view_host() :
824 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58825 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38826}
827
[email protected]b172aee2012-04-10 17:05:26828bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31829 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49830}
831
[email protected]b172aee2012-04-10 17:05:26832bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31833 return waiting_for_response_;
834}
835
[email protected]b172aee2012-04-10 17:05:26836const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31837 return load_state_;
838}
839
[email protected]b172aee2012-04-10 17:05:26840const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31841 return load_state_host_;
842}
843
[email protected]b172aee2012-04-10 17:05:26844uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31845 return upload_size_;
846}
847
[email protected]b172aee2012-04-10 17:05:26848uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31849 return upload_position_;
850}
851
[email protected]b172aee2012-04-10 17:05:26852const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31853 return encoding_;
854}
855
[email protected]b172aee2012-04-10 17:05:26856bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31857 return displayed_insecure_content_;
858}
859
[email protected]b172aee2012-04-10 17:05:26860void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31861 capturing_contents_ = cap;
862}
863
[email protected]b172aee2012-04-10 17:05:26864bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31865 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
866 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
867 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49868}
869
[email protected]b172aee2012-04-10 17:05:26870void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
871 int error_code) {
[email protected]443b80e2010-12-14 00:42:23872 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34873 return;
874
[email protected]443b80e2010-12-14 00:42:23875 crashed_status_ = status;
876 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46877 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34878}
879
[email protected]b172aee2012-04-10 17:05:26880base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31881 return crashed_status_;
882}
883
[email protected]b172aee2012-04-10 17:05:26884bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31885 return is_being_destroyed_;
886}
887
[email protected]b172aee2012-04-10 17:05:26888void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34889 if (delegate_)
890 delegate_->NavigationStateChanged(this, changed_flags);
891}
892
[email protected]b172aee2012-04-10 17:05:26893void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54894 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04895 RenderWidgetHostViewPort* rwhv =
896 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16897 if (rwhv) {
898 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43899#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16900 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43901#endif
902 }
[email protected]96d185d2009-04-24 03:28:54903
[email protected]5ac20162010-11-24 23:33:11904 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38905
[email protected]d8c660432011-12-22 20:51:25906 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59907
908 // The resize rect might have changed while this was inactive -- send the new
909 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58910 RenderViewHostImpl* rvh =
911 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59912 if (rvh) {
913 rvh->ResizeRectChanged(GetRootWindowResizerRect());
914 }
[email protected]96d185d2009-04-24 03:28:54915}
916
[email protected]be1f56ab2011-12-22 06:55:31917
[email protected]b172aee2012-04-10 17:05:26918base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31919 return last_selected_time_;
920}
921
[email protected]b172aee2012-04-10 17:05:26922void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31923 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52924 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
925 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26926 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52927 // removes the |GetRenderViewHost()|; then when we actually destroy the
928 // window, OnWindowPosChanged() notices and calls HideContents() (which
929 // calls us).
[email protected]c30585c2012-02-16 15:02:04930 RenderWidgetHostViewPort* rwhv =
931 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16932 if (rwhv)
933 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54934 }
935
[email protected]375fa1b2012-05-22 22:05:37936 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07937 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37938 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09939 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37940 content::Details<bool>(&is_visible));
941}
942
943void WebContentsImpl::WasRestored() {
944 bool is_visible = true;
945 content::NotificationService::current()->Notify(
946 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
947 content::Source<WebContents>(this),
948 content::Details<bool>(&is_visible));
[email protected]96d185d2009-04-24 03:28:54949}
950
[email protected]b172aee2012-04-10 17:05:26951void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04952 RenderWidgetHostViewPort* rwhv =
953 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31954 if (rwhv)
955 rwhv->DidBecomeSelected();
[email protected]375fa1b2012-05-22 22:05:37956 WasRestored();
[email protected]be1f56ab2011-12-22 06:55:31957}
958
[email protected]b172aee2012-04-10 17:05:26959void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31960 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
961 // our superclass HideContents(), because some callers want to be very picky
962 // about the order in which these get called. In addition to making the code
963 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26964 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
965 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31966 WasHidden();
967}
968
[email protected]b172aee2012-04-10 17:05:26969bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31970 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27971 return WillNotifyDisconnection() &&
972 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58973 !static_cast<RenderViewHostImpl*>(
974 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31975}
976
[email protected]b172aee2012-04-10 17:05:26977void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27978 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25979 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27980}
981
[email protected]b172aee2012-04-10 17:05:26982WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44983 // We use our current SiteInstance since the cloned entry will use it anyway.
984 // We pass |this| for the |base_web_contents| to size the view correctly, and
985 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26986 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44987 GetBrowserContext(), GetSiteInstance(),
988 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20989 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27990 return tc;
991}
992
[email protected]b172aee2012-04-10 17:05:26993void WebContentsImpl::AddNewContents(WebContents* new_contents,
994 WindowOpenDisposition disposition,
995 const gfx::Rect& initial_pos,
996 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:27997 if (!delegate_)
998 return;
999
1000 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1001 user_gesture);
1002}
1003
[email protected]b172aee2012-04-10 17:05:261004gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271005 return view_->GetContentNativeView();
1006}
1007
[email protected]b172aee2012-04-10 17:05:261008gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271009 return view_->GetNativeView();
1010}
1011
[email protected]b172aee2012-04-10 17:05:261012void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271013 view_->GetContainerBounds(out);
1014}
1015
[email protected]b172aee2012-04-10 17:05:261016void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271017 view_->Focus();
1018}
1019
[email protected]14392a52012-05-02 20:28:441020void WebContentsImpl::Observe(int type,
1021 const content::NotificationSource& source,
1022 const content::NotificationDetails& details) {
1023 switch (type) {
1024 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1025 OnWebContentsDestroyed(
1026 content::Source<content::WebContents>(source).ptr());
1027 break;
[email protected]bafe6cd2012-05-23 23:09:501028 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1029 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1030 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1031 i != pending_widget_views_.end(); ++i) {
1032 if (host->GetView() == i->second) {
1033 pending_widget_views_.erase(i);
1034 break;
1035 }
1036 }
1037 break;
1038 }
[email protected]14392a52012-05-02 20:28:441039 default:
1040 NOTREACHED();
1041 }
1042}
1043
1044void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1045 // Clear the opener if it has been closed.
1046 if (web_contents == opener_) {
1047 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1048 content::Source<WebContents>(opener_));
1049 opener_ = NULL;
1050 }
1051}
1052
[email protected]b172aee2012-04-10 17:05:261053void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311054 observers_.AddObserver(observer);
1055}
1056
[email protected]b172aee2012-04-10 17:05:261057void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311058 observers_.RemoveObserver(observer);
1059}
1060
[email protected]b172aee2012-04-10 17:05:261061void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341062 if (delegate_)
1063 delegate_->ActivateContents(this);
1064}
1065
[email protected]b172aee2012-04-10 17:05:261066void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121067 if (delegate_)
1068 delegate_->DeactivateContents(this);
1069}
1070
[email protected]b172aee2012-04-10 17:05:261071void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481072 if (delegate_)
1073 delegate_->LostCapture();
1074}
1075
[email protected]b172aee2012-04-10 17:05:261076bool WebContentsImpl::PreHandleKeyboardEvent(
1077 const NativeWebKeyboardEvent& event,
1078 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481079 return delegate_ &&
1080 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1081}
1082
[email protected]b172aee2012-04-10 17:05:261083void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481084 if (delegate_)
1085 delegate_->HandleKeyboardEvent(event);
1086}
1087
[email protected]b172aee2012-04-10 17:05:261088void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431089 if (delegate_)
1090 delegate_->HandleMouseDown();
1091}
1092
[email protected]b172aee2012-04-10 17:05:261093void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481094 if (delegate_)
1095 delegate_->HandleMouseUp();
1096}
1097
[email protected]b172aee2012-04-10 17:05:261098void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481099 if (delegate_)
1100 delegate_->HandleMouseActivate();
1101}
1102
[email protected]b172aee2012-04-10 17:05:261103void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471104 if (delegate_)
1105 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1106}
1107
[email protected]b172aee2012-04-10 17:05:261108bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381109 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121110}
1111
[email protected]a9c81f02012-06-01 00:15:441112void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1113 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371114 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441115 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371116 } else {
1117 GotResponseToLockMouseRequest(false);
1118 }
1119}
1120
[email protected]b172aee2012-04-10 17:05:261121void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371122 if (delegate_)
1123 delegate_->LostMouseLock();
1124}
1125
[email protected]bafe6cd2012-05-23 23:09:501126void WebContentsImpl::CreateNewWindow(
1127 int route_id,
1128 const ViewHostMsg_CreateWindow_Params& params) {
1129 if (delegate_ && !delegate_->ShouldCreateWebContents(
1130 this, route_id, params.window_container_type, params.frame_name,
1131 params.target_url)) {
1132 return;
1133 }
1134
1135 // We usually create the new window in the same BrowsingInstance (group of
1136 // script-related windows), by passing in the current SiteInstance. However,
1137 // if the opener is being suppressed, we create a new SiteInstance in its own
1138 // BrowsingInstance.
1139 scoped_refptr<SiteInstance> site_instance =
1140 params.opener_suppressed ?
1141 SiteInstance::Create(GetBrowserContext()) :
1142 GetSiteInstance();
1143
1144 // Create the new web contents. This will automatically create the new
1145 // WebContentsView. In the future, we may want to create the view separately.
1146 WebContentsImpl* new_contents =
1147 new WebContentsImpl(GetBrowserContext(),
1148 site_instance,
1149 route_id,
1150 this,
1151 params.opener_suppressed ? NULL : this,
1152 NULL);
1153 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1154
1155 if (!params.opener_suppressed) {
1156 content::WebContentsView* new_view = new_contents->GetView();
1157
1158 // TODO(brettw): It seems bogus that we have to call this function on the
1159 // newly created object and give it one of its own member variables.
1160 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1161
1162 // Save the created window associated with the route so we can show it
1163 // later.
1164 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1165 pending_contents_[route_id] = new_contents;
1166 }
1167
1168 if (delegate_) {
1169 delegate_->WebContentsCreated(
1170 this, params.opener_frame_id, params.target_url, new_contents);
1171 }
1172
1173 if (params.opener_suppressed) {
1174 // When the opener is suppressed, the original renderer cannot access the
1175 // new window. As a result, we need to show and navigate the window here.
1176 gfx::Rect initial_pos;
1177 AddNewContents(
1178 new_contents, params.disposition, initial_pos, params.user_gesture);
1179
1180 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1181 CURRENT_TAB,
1182 content::PAGE_TRANSITION_LINK,
1183 true /* is_renderer_initiated */);
1184 new_contents->OpenURL(open_params);
1185 }
1186}
1187
1188void WebContentsImpl::CreateNewWidget(int route_id,
1189 WebKit::WebPopupType popup_type) {
1190 CreateNewWidget(route_id, false, popup_type);
1191}
1192
1193void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1194 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1195}
1196
1197void WebContentsImpl::CreateNewWidget(int route_id,
1198 bool is_fullscreen,
1199 WebKit::WebPopupType popup_type) {
1200 content::RenderProcessHost* process = GetRenderProcessHost();
1201 RenderWidgetHostImpl* widget_host =
1202 new RenderWidgetHostImpl(this, process, route_id);
1203 RenderWidgetHostViewPort* widget_view =
1204 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1205 if (!is_fullscreen) {
1206 // Popups should not get activated.
1207 widget_view->SetPopupType(popup_type);
1208 }
1209 // Save the created widget associated with the route so we can show it later.
1210 pending_widget_views_[route_id] = widget_view;
1211
1212#if defined(OS_MACOSX)
1213 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1214 // to allow it to survive the trip without being hosted.
1215 base::mac::NSObjectRetain(widget_view->GetNativeView());
1216#endif
1217}
1218
1219void WebContentsImpl::ShowCreatedWindow(int route_id,
1220 WindowOpenDisposition disposition,
1221 const gfx::Rect& initial_pos,
1222 bool user_gesture) {
1223 WebContentsImpl* contents = GetCreatedWindow(route_id);
1224 if (contents)
1225 AddNewContents(contents, disposition, initial_pos, user_gesture);
1226}
1227
1228void WebContentsImpl::ShowCreatedWidget(int route_id,
1229 const gfx::Rect& initial_pos) {
1230 ShowCreatedWidget(route_id, false, initial_pos);
1231}
1232
1233void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1234 ShowCreatedWidget(route_id, true, gfx::Rect());
1235}
1236
1237void WebContentsImpl::ShowCreatedWidget(int route_id,
1238 bool is_fullscreen,
1239 const gfx::Rect& initial_pos) {
1240 if (delegate_)
1241 delegate_->RenderWidgetShowing();
1242
1243 RenderWidgetHostViewPort* widget_host_view =
1244 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1245 if (!widget_host_view)
1246 return;
1247 if (is_fullscreen) {
1248 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1249 } else {
1250 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1251 }
1252 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost())->Init();
1253
1254#if defined(OS_MACOSX)
1255 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1256 // properly embedded (or purposefully ignored) we can release the retain we
1257 // took in CreateNewWidget().
1258 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1259#endif
1260}
1261
1262WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1263 PendingContents::iterator iter = pending_contents_.find(route_id);
1264
1265 // Certain systems can block the creation of new windows. If we didn't succeed
1266 // in creating one, just return NULL.
1267 if (iter == pending_contents_.end()) {
1268 return NULL;
1269 }
1270
1271 WebContentsImpl* new_contents = iter->second;
1272 pending_contents_.erase(route_id);
1273
1274 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1275 !new_contents->GetRenderViewHost()->GetView())
1276 return NULL;
1277
1278 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1279 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1280 return new_contents;
1281}
1282
1283RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1284 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1285 if (iter == pending_widget_views_.end()) {
1286 DCHECK(false);
1287 return NULL;
1288 }
1289
1290 RenderWidgetHostView* widget_host_view = iter->second;
1291 pending_widget_views_.erase(route_id);
1292
1293 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1294 if (!widget_host->GetProcess()->HasConnection()) {
1295 // The view has gone away or the renderer crashed. Nothing to do.
1296 return NULL;
1297 }
1298
1299 return widget_host_view;
1300}
1301
1302void WebContentsImpl::ShowContextMenu(
1303 const content::ContextMenuParams& params) {
1304 // Allow WebContentsDelegates to handle the context menu operation first.
1305 if (delegate_ && delegate_->HandleContextMenu(params))
1306 return;
1307
[email protected]5a3bdf52012-05-24 15:12:571308 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501309}
1310
[email protected]b172aee2012-04-10 17:05:261311void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231312 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331313 if (delegate_)
1314 delegate_->UpdatePreferredSize(this, pref_size);
1315}
1316
[email protected]b172aee2012-04-10 17:05:261317void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341318 if (delegate_)
1319 delegate_->ResizeDueToAutoResize(this, new_size);
1320}
1321
[email protected]b172aee2012-04-10 17:05:261322WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201323 if (!delegate_)
1324 return NULL;
[email protected]00c37fc2011-08-02 00:22:501325
[email protected]e5d549d2011-12-28 01:29:201326 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1327 // Notify observers.
1328 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1329 DidOpenURL(params.url, params.referrer,
1330 params.disposition, params.transition));
1331 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341332}
1333
[email protected]b172aee2012-04-10 17:05:261334bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501335 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251336 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231337 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251338 reload_type);
[email protected]876bc832010-09-07 16:29:541339}
[email protected]96d185d2009-04-24 03:28:541340
[email protected]ba45bfd2012-05-22 21:51:441341void WebContentsImpl::RenderViewForInterstitialPageCreated(
1342 content::RenderViewHost* render_view_host) {
1343 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1344 RenderViewForInterstitialPageCreated(render_view_host));
1345}
1346
[email protected]b172aee2012-04-10 17:05:261347bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231348 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501349 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401350 // The renderer will reject IPC messages with URLs longer than
1351 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511352 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401353 return false;
1354
[email protected]9f76c1e2012-03-05 15:15:581355 RenderViewHostImpl* dest_render_view_host =
1356 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401357 if (!dest_render_view_host)
1358 return false; // Unable to create the desired render view host.
1359
[email protected]80a8fad2011-01-29 04:02:381360 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071361 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581362 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501363 WebUIControllerFactory* factory =
1364 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271365 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501366 bool is_allowed_in_web_ui_renderer =
1367 factory &&
[email protected]24e18252012-04-16 21:26:271368 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1369 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231370 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1371 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271372 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231373 content::GetContentClient()->SetActiveURL(entry.GetURL());
1374 CHECK(0);
1375 }
[email protected]54ec6472010-04-09 19:39:581376
[email protected]96d185d2009-04-24 03:28:541377 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441378 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521379 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441380 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511381 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541382
1383 // Used for page load time metrics.
1384 current_load_start_ = base::TimeTicks::Now();
1385
1386 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241387 std::string embedder_channel_name;
1388 int embedder_container_id;
1389 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1390 &embedder_channel_name,
1391 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341392 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271393 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241394 embedder_channel_name,
1395 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471396 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341397 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541398
[email protected]36fc0392011-12-25 03:59:511399 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541400 // HACK!! This code suppresses javascript: URLs from being added to
1401 // session history, which is what we want to do for javascript: URLs that
1402 // do not generate content. What we really need is a message from the
1403 // renderer telling us that a new page was not created. The same message
1404 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511405 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541406 return false;
1407 }
1408
[email protected]3c9e1872010-11-18 16:17:491409 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251410 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041411 observers_,
[email protected]36fc0392011-12-25 03:59:511412 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541413
[email protected]09b29342011-06-24 19:18:481414 if (delegate_)
1415 delegate_->DidNavigateToPendingEntry(this);
1416
[email protected]d5f942ba2008-09-26 19:30:341417 return true;
1418}
1419
[email protected]b172aee2012-04-10 17:05:261420void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331421 const SiteInstance* site_instance,
1422 int history_length,
1423 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411424 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1425 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191426 if (render_manager_.pending_render_view_host()) {
1427 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141428 return;
[email protected]9e1ad4b2011-08-14 16:49:191429 }
[email protected]9f76c1e2012-03-05 15:15:581430 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191431 if (!rvh) {
1432 NOTREACHED();
1433 return;
1434 }
[email protected]9f76c1e2012-03-05 15:15:581435 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191436 NOTREACHED();
1437 return;
1438 }
[email protected]9f76c1e2012-03-05 15:15:581439 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191440 history_length,
1441 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141442}
1443
[email protected]b172aee2012-04-10 17:05:261444void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271445 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541446 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1447 return;
1448 }
[email protected]9f76c1e2012-03-05 15:15:581449 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541450}
1451
[email protected]b172aee2012-04-10 17:05:261452bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271453 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541454}
1455
[email protected]b172aee2012-04-10 17:05:261456InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271457 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221458}
1459
[email protected]b172aee2012-04-10 17:05:261460bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161461 // WebKit creates Document object when MIME type is application/xhtml+xml,
1462 // so we also support this MIME type.
1463 return contents_mime_type_ == "text/html" ||
1464 contents_mime_type_ == "text/xml" ||
1465 contents_mime_type_ == "application/xhtml+xml" ||
1466 contents_mime_type_ == "text/plain" ||
1467 contents_mime_type_ == "text/css" ||
1468 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1469}
1470
[email protected]b172aee2012-04-10 17:05:261471void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591472 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161473 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481474 download_stats::RecordDownloadSource(
1475 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461476 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141477 return;
[email protected]c7dd2f62011-07-18 15:57:591478 }
1479
1480 Stop();
1481
1482 // Create the save package and possibly prompt the user for the name to save
1483 // the page as. The user prompt is an asynchronous operation that runs on
1484 // another thread.
1485 save_package_ = new SavePackage(this);
1486 save_package_->GetSaveInfo();
1487}
1488
1489// Used in automated testing to bypass prompting the user for file names.
1490// Instead, the names and paths are hard coded rather than running them through
1491// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261492bool WebContentsImpl::SavePage(const FilePath& main_file,
1493 const FilePath& dir_path,
1494 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591495 // Stop the page from navigating.
1496 Stop();
1497
1498 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271499 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591500}
1501
[email protected]b172aee2012-04-10 17:05:261502void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121503 const FilePath& file,
1504 const base::Callback<void(const FilePath&, int64)>& callback) {
1505 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1506}
1507
[email protected]b172aee2012-04-10 17:05:261508bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231509 NavigationEntryImpl* active_entry =
1510 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321511 return (active_entry != NULL &&
1512 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511513 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321514}
1515
[email protected]b172aee2012-04-10 17:05:261516const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271517 return contents_mime_type_;
1518}
1519
[email protected]b172aee2012-04-10 17:05:261520bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271521 return notify_disconnection_;
1522}
1523
[email protected]b172aee2012-04-10 17:05:261524void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311525 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581526 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1527 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161528}
1529
[email protected]b172aee2012-04-10 17:05:261530void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311531 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581532 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1533 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161534}
1535
[email protected]b172aee2012-04-10 17:05:261536content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271537 return &renderer_preferences_;
1538}
1539
[email protected]b172aee2012-04-10 17:05:261540void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271541 new_tab_start_time_ = time;
1542}
1543
[email protected]b172aee2012-04-10 17:05:261544base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271545 return new_tab_start_time_;
1546}
1547
[email protected]e35ccd52012-05-23 16:22:471548void WebContentsImpl::Close() {
1549 Close(GetRenderViewHost());
1550}
1551
[email protected]b172aee2012-04-10 17:05:261552void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151553 if (close_start_time_.is_null())
1554 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011555}
1556
[email protected]b172aee2012-04-10 17:05:261557bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191558#if defined(OS_CHROMEOS)
1559 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1560 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511561 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201562 return false;
1563 return true;
[email protected]46624bf2010-06-09 16:04:191564#else
1565 return true;
1566#endif
1567}
1568
[email protected]b172aee2012-04-10 17:05:261569void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521570 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581571 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511572 if (delegate_)
1573 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341574}
1575
[email protected]e35ccd52012-05-23 16:22:471576void WebContentsImpl::UserGestureDone() {
1577 OnUserGesture();
1578}
1579
[email protected]b172aee2012-04-10 17:05:261580void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271581 closed_by_user_gesture_ = value;
1582}
1583
[email protected]b172aee2012-04-10 17:05:261584bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271585 return closed_by_user_gesture_;
1586}
1587
[email protected]b172aee2012-04-10 17:05:261588double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051589 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561590 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251591 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171592 return 0;
[email protected]b75b8292010-10-01 07:28:251593
1594 double zoom_level;
1595 if (temporary_zoom_settings_) {
1596 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581597 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251598 } else {
[email protected]2ae88d12011-10-14 09:11:191599 GURL url;
[email protected]10f417c52011-12-28 21:04:231600 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191601 // Since zoom map is updated using rewritten URL, use rewritten URL
1602 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511603 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191604 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251605 }
[email protected]d0b8d092010-10-25 04:05:171606 return zoom_level;
1607}
[email protected]b75b8292010-10-01 07:28:251608
[email protected]b172aee2012-04-10 17:05:261609int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1610 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171611 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011612 // Calculate the zoom percent from the factor. Round up to the nearest whole
1613 // number.
[email protected]b75b8292010-10-01 07:28:251614 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011615 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251616 *enable_decrement = percent > minimum_zoom_percent_;
1617 *enable_increment = percent < maximum_zoom_percent_;
1618 return percent;
1619}
1620
[email protected]b172aee2012-04-10 17:05:261621void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501622 if (!delegate_)
1623 return;
1624
[email protected]10f417c52011-12-28 21:04:231625 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501626 if (!active_entry)
1627 return;
1628
[email protected]36fc0392011-12-25 03:59:511629 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121630}
1631
[email protected]b172aee2012-04-10 17:05:261632void WebContentsImpl::ViewFrameSource(const GURL& url,
1633 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271634 if (!delegate_)
1635 return;
1636
1637 delegate_->ViewSourceForFrame(this, url, content_state);
1638}
1639
[email protected]b172aee2012-04-10 17:05:261640int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271641 return minimum_zoom_percent_;
1642}
1643
[email protected]b172aee2012-04-10 17:05:261644int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271645 return maximum_zoom_percent_;
1646}
1647
[email protected]b172aee2012-04-10 17:05:261648gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231649 return preferred_size_;
1650}
1651
[email protected]b172aee2012-04-10 17:05:261652int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271653 return content_restrictions_;
1654}
1655
[email protected]b172aee2012-04-10 17:05:261656WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501657 WebUIControllerFactory* factory =
1658 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1659 if (!factory)
1660 return WebUI::kNoWebUI;
1661 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271662}
1663
[email protected]b172aee2012-04-10 17:05:261664content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271665 // When there is a pending navigation entry, we want to use the pending WebUI
1666 // that goes along with it to control the basic flags. For example, we want to
1667 // show the pending URL in the URL bar, so we want the display_url flag to
1668 // be from the pending entry.
1669 //
1670 // The confusion comes because there are multiple possibilities for the
1671 // initial load in a tab as a side effect of the way the RenderViewHostManager
1672 // works.
1673 //
1674 // - For the very first tab the load looks "normal". The new tab Web UI is
1675 // the pending one, and we want it to apply here.
1676 //
1677 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1678 // get switched to the one previously associated with the new tab pages.
1679 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1680 // have a committed Web UI in this case.
1681 //
1682 // This condition handles all of these cases:
1683 //
1684 // - First load in first tab: no committed nav entry + pending nav entry +
1685 // pending dom ui:
1686 // -> Use pending Web UI if any.
1687 //
1688 // - First load in second tab: no committed nav entry + pending nav entry +
1689 // no pending Web UI:
1690 // -> Use the committed Web UI if any.
1691 //
1692 // - Second navigation in any tab: committed nav entry + pending nav entry:
1693 // -> Use pending Web UI if any.
1694 //
1695 // - Normal state with no load: committed nav entry + no pending nav entry:
1696 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251697 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271698 (controller_.GetLastCommittedEntry() ||
1699 render_manager_.pending_web_ui()))
1700 return render_manager_.pending_web_ui();
1701 return render_manager_.web_ui();
1702}
1703
[email protected]b172aee2012-04-10 17:05:261704bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271705 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581706 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271707}
1708
[email protected]b172aee2012-04-10 17:05:261709bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441710 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501711}
1712
[email protected]b172aee2012-04-10 17:05:261713void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321714 SkColor color) {
[email protected]da8543762012-03-20 08:52:201715 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1716 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1717}
1718
[email protected]b172aee2012-04-10 17:05:261719void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201720 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1721 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1722 if (delegate_)
1723 delegate_->DidEndColorChooser();
1724 color_chooser_ = NULL;
1725}
1726
[email protected]b172aee2012-04-10 17:05:261727bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471728 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271729 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221730 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231731 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411732 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271733}
1734
[email protected]b172aee2012-04-10 17:05:261735void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271736 if (delegate_)
1737 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211738}
1739
[email protected]b172aee2012-04-10 17:05:261740void WebContentsImpl::OnRegisterIntentService(const string16& action,
1741 const string16& type,
1742 const string16& href,
1743 const string16& title,
1744 const string16& disposition) {
[email protected]6934a702011-12-20 00:04:511745 delegate_->RegisterIntentHandler(
[email protected]63c239322011-10-31 23:56:301746 this, action, type, href, title, disposition);
1747}
1748
[email protected]b172aee2012-04-10 17:05:261749void WebContentsImpl::OnWebIntentDispatch(
1750 const webkit_glue::WebIntentData& intent,
1751 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001752 WebIntentsDispatcherImpl* intents_dispatcher =
1753 new WebIntentsDispatcherImpl(this, intent, intent_id);
1754 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301755}
1756
[email protected]54047eb52012-05-08 21:45:571757void WebContentsImpl::DidStartProvisionalLoadForFrame(
1758 content::RenderViewHost* render_view_host,
1759 int64 frame_id,
1760 bool is_main_frame,
1761 const GURL& opener_url,
1762 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281763 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181764 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451765 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571766 RenderViewHostImpl* render_view_host_impl =
1767 static_cast<RenderViewHostImpl*>(render_view_host);
1768 content::RenderProcessHost* render_process_host =
1769 render_view_host->GetProcess();
1770 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581771 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571772 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451773 false,
[email protected]9f76c1e2012-03-05 15:15:581774 &validated_url);
[email protected]54047eb52012-05-08 21:45:571775 render_view_host_impl->FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451776 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571777 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451778 true,
1779 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181780
[email protected]0d60f0192011-04-14 12:40:101781 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251782 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101783 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571784 validated_url, is_error_page, render_view_host));
[email protected]0d60f0192011-04-14 12:40:101785
[email protected]724159a2010-12-30 01:11:181786 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591787 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251788 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451789 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]ef16c3e2012-05-16 22:13:461790 validated_opener_url,
1791 render_view_host));
[email protected]724159a2010-12-30 01:11:181792 }
1793}
1794
[email protected]54047eb52012-05-08 21:45:571795void WebContentsImpl::DidRedirectProvisionalLoad(
1796 content::RenderViewHost* render_view_host,
1797 int32 page_id,
1798 const GURL& opener_url,
1799 const GURL& source_url,
1800 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491801 // TODO(creis): Remove this method and have the pre-rendering code listen to
1802 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1803 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451804 GURL validated_source_url(source_url);
1805 GURL validated_target_url(target_url);
1806 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571807 RenderViewHostImpl* render_view_host_impl =
1808 static_cast<RenderViewHostImpl*>(render_view_host);
1809 content::RenderProcessHost* render_process_host =
1810 render_view_host->GetProcess();
1811 render_view_host_impl->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]54047eb52012-05-08 21:45:571816 render_view_host_impl->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]54047eb52012-05-08 21:45:571821 render_view_host_impl->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 RenderViewHostImpl* render_view_host_impl =
1855 static_cast<RenderViewHostImpl*>(render_view_host);
1856 content::RenderProcessHost* render_process_host =
1857 render_view_host->GetProcess();
1858 render_view_host_impl->FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581859 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571860 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451861 false,
[email protected]9f76c1e2012-03-05 15:15:581862 &validated_url);
[email protected]724159a2010-12-30 01:11:181863
[email protected]d7b175e2011-10-11 15:31:581864 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181865 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1866 // This means that the interstitial won't be torn down properly, which is
1867 // bad. But if we have an interstitial, go back to another tab type, and
1868 // then load the same interstitial again, we could end up getting the first
1869 // interstitial's "failed" message (as a result of the cancel) when we're on
1870 // the second one.
1871 //
1872 // We can't tell this apart, so we think we're tearing down the current page
1873 // which will cause a crash later one. There is also some code in
1874 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1875 // out because of this problem.
1876 //
1877 // http://code.google.com/p/chromium/issues/detail?id=2855
1878 // Because this will not tear down the interstitial properly, if "back" is
1879 // back to another tab type, the interstitial will still be somewhat alive
1880 // in the previous tab type. If you navigate somewhere that activates the
1881 // tab with the interstitial again, you'll see a flash before the new load
1882 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271883 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181884 LOG(WARNING) << "Discarding message during interstitial.";
1885 return;
1886 }
1887
[email protected]02102f82011-06-13 20:37:021888 // Discard our pending entry if the load canceled (e.g. if we decided to
1889 // download the file instead of load it). We do not verify that the URL
1890 // being canceled matches the pending entry's URL because they will not
1891 // match if a redirect occurred (in which case we do not want to leave a
1892 // stale redirect URL showing). This means that we also cancel the pending
1893 // entry if the user started a new navigation. As a result, the navigation
1894 // controller may not remember that a load is in progress, but the
1895 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251896 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161897 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181898
[email protected]54047eb52012-05-08 21:45:571899 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181900 }
1901
[email protected]d8c660432011-12-22 20:51:251902 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581903 observers_,
1904 DidFailProvisionalLoad(params.frame_id,
1905 params.is_main_frame,
1906 validated_url,
1907 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461908 params.error_description,
1909 render_view_host));
[email protected]724159a2010-12-30 01:11:181910}
1911
[email protected]b172aee2012-04-10 17:05:261912void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181913 const GURL& url,
[email protected]70435962011-08-02 20:13:281914 const std::string& security_info,
1915 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181916 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281917 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191918 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181919 cache.Increment();
1920
1921 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081922 int cert_id = 0;
1923 net::CertStatus cert_status = 0;
1924 int security_bits = -1;
1925 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511926 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1927 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301928 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]6d6cfb3a2012-05-23 22:53:181929 cert_id, cert_status, http_method,
1930 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181931
[email protected]ad50def52011-10-19 23:17:071932 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271933 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501934 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531935 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181936}
1937
[email protected]b172aee2012-04-10 17:05:261938void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381939 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181940 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201941 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181942}
1943
[email protected]b172aee2012-04-10 17:05:261944void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021945 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231946 LOG(INFO) << security_origin << " ran insecure content from "
1947 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381948 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411949 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1950 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181951 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411952 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201953 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181954}
1955
[email protected]b172aee2012-04-10 17:05:261956void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181957 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251958 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101959 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181960}
1961
[email protected]b172aee2012-04-10 17:05:261962void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5b2011-11-29 11:36:311963 int64 frame_id,
1964 const GURL& validated_url,
1965 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251966 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5b2011-11-29 11:36:311967 DidFinishLoad(frame_id, validated_url, is_main_frame));
1968}
1969
[email protected]b172aee2012-04-10 17:05:261970void WebContentsImpl::OnDidFailLoadWithError(
1971 int64 frame_id,
1972 const GURL& validated_url,
1973 bool is_main_frame,
1974 int error_code,
1975 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251976 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5b2011-11-29 11:36:311977 DidFailLoad(frame_id, validated_url, is_main_frame,
1978 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181979}
1980
[email protected]b172aee2012-04-10 17:05:261981void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271982 content_restrictions_ = restrictions;
1983 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171984}
1985
[email protected]b172aee2012-04-10 17:05:261986void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261987 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231988 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251989 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261990 if (!entry)
1991 return;
1992 // Note that we don't call NavigationController::GotToOffset() as we don't
1993 // want to create a pending navigation entry (it might end up lingering
1994 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:251995 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:581996 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:511997 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:581998 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:471999 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572000
2001 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2002 // it in now that we know. This allows us to find the entry when it commits.
2003 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232004 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332005 entry->set_site_instance(
2006 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572007 }
[email protected]216813952011-05-19 22:21:262008 }
2009}
2010
[email protected]b172aee2012-04-10 17:05:262011void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2012 int maximum_percent,
2013 bool remember) {
[email protected]216813952011-05-19 22:21:262014 minimum_zoom_percent_ = minimum_percent;
2015 maximum_zoom_percent_ = maximum_percent;
2016 temporary_zoom_settings_ = !remember;
2017}
2018
[email protected]20b433a2012-05-15 21:23:462019void WebContentsImpl::OnSaveURL(const GURL& url,
2020 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482021 download_stats::RecordDownloadSource(
2022 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262023 // Check if the URL to save matches the URL of the main frame. Since this
2024 // message originates from Pepper plugins, it may not be the case if the
2025 // plugin is an embedded element.
2026 GURL main_frame_url = GetURL();
2027 if (!main_frame_url.is_valid())
2028 return;
2029 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462030 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272031}
2032
[email protected]b172aee2012-04-10 17:05:262033void WebContentsImpl::OnEnumerateDirectory(int request_id,
2034 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:592035 ChildProcessSecurityPolicyImpl* policy =
2036 ChildProcessSecurityPolicyImpl::GetInstance();
2037 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2038 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212039}
2040
[email protected]b172aee2012-04-10 17:05:262041void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:512042 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202043}
2044
[email protected]b172aee2012-04-10 17:05:262045void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2046 const GURL& url,
2047 const string16& title) {
[email protected]b9535422012-02-09 01:47:592048 ChildProcessSecurityPolicyImpl* policy =
2049 ChildProcessSecurityPolicyImpl::GetInstance();
2050 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2051 return;
[email protected]6934a702011-12-20 00:04:512052 delegate_->RegisterProtocolHandler(this, protocol, url, title);
[email protected]7d189022011-08-25 22:54:202053}
2054
[email protected]b172aee2012-04-10 17:05:262055void WebContentsImpl::OnFindReply(int request_id,
2056 int number_of_matches,
2057 const gfx::Rect& selection_rect,
2058 int active_match_ordinal,
2059 bool final_update) {
[email protected]6934a702011-12-20 00:04:512060 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2061 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:002062 // Send a notification to the renderer that we are ready to receive more
2063 // results from the scoping effort of the Find operation. The FindInPage
2064 // scoping is asynchronous and periodically sends results back up to the
2065 // browser using IPC. In an effort to not spam the browser we have the
2066 // browser send an ACK for each FindReply message and have the renderer
2067 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582068 GetRenderViewHostImpl()->Send(
2069 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162070}
2071
[email protected]b172aee2012-04-10 17:05:262072void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442073 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2074 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452075}
2076
[email protected]b172aee2012-04-10 17:05:262077void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2078 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102079 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252080 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102081 AppCacheAccessed(manifest_url, blocked_by_policy));
2082}
2083
[email protected]b172aee2012-04-10 17:05:262084void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322085 SkColor color) {
[email protected]da8543762012-03-20 08:52:202086 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
2087}
2088
[email protected]b172aee2012-04-10 17:05:262089void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202090 if (color_chooser_ &&
2091 color_chooser_id == color_chooser_->identifier())
2092 color_chooser_->End();
2093}
2094
[email protected]b172aee2012-04-10 17:05:262095void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322096 SkColor color) {
[email protected]da8543762012-03-20 08:52:202097 if (color_chooser_ &&
2098 color_chooser_id == color_chooser_->identifier())
2099 color_chooser_->SetSelectedColor(color);
2100}
2101
[email protected]9f2a9d72012-04-16 16:02:222102void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2103 const FilePath& path,
2104 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442105 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2106 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292107}
2108
[email protected]d0759f492012-04-19 22:50:502109// This exists for render views that don't have a WebUI, but do have WebUI
2110// bindings enabled.
2111void WebContentsImpl::OnWebUISend(const GURL& source_url,
2112 const std::string& name,
2113 const base::ListValue& args) {
2114 if (delegate_)
2115 delegate_->WebUISend(this, source_url, name, args);
2116}
2117
[email protected]96d185d2009-04-24 03:28:542118// Notifies the RenderWidgetHost instance about the fact that the page is
2119// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262120void WebContentsImpl::SetIsLoading(bool is_loading,
2121 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542122 if (is_loading == is_loading_)
2123 return;
2124
2125 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212126 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542127 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562128 upload_size_ = 0;
2129 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542130 }
2131
2132 render_manager_.SetIsLoading(is_loading);
2133
2134 is_loading_ = is_loading;
2135 waiting_for_response_ = is_loading;
2136
[email protected]6ebdc9b2010-09-27 16:55:572137 if (delegate_)
2138 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462139 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542140
[email protected]432115822011-07-10 15:52:272141 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2142 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072143 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542144 if (details)
[email protected]6c2381d2011-10-19 02:52:532145 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072146 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502147 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542148 det);
2149}
2150
[email protected]b172aee2012-04-10 17:05:262151void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132152 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322153 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562154 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382155 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442156 // that opened the window, as long as both renderers have the same
2157 // privileges.
[email protected]1fd1a502011-03-30 16:55:562158 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562159 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582160 // web_ui might be NULL if the URL refers to a non-existent extension.
2161 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402162 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522163 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442164 }
2165 }
[email protected]1fd1a502011-03-30 16:55:562166 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442167 }
2168
[email protected]4e697b042011-07-08 06:44:562169 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322170 // Clear the status bubble. This is a workaround for a bug where WebKit
2171 // doesn't let us know that the cursor left an element during a
2172 // transition (this is also why the mouse cursor remains as a hand after
2173 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2174 // clear the bubble when a user navigates to a named anchor in the same
2175 // page.
[email protected]36fc0392011-12-25 03:59:512176 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322177 }
2178
[email protected]a6e82fc2010-02-24 22:28:142179 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472180 // Once the main frame is navigated, we're no longer considered to have
2181 // displayed insecure content.
2182 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172183 }
[email protected]ce5c4502009-05-06 16:46:112184
[email protected]3c9e1872010-11-18 16:17:492185 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252186 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042187 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322188}
2189
[email protected]b172aee2012-04-10 17:05:262190void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322191 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132192 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322193 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062194 // If we navigate off the page, reset JavaScript state. This does nothing
2195 // to prevent a malicious script from spamming messages, since the script
2196 // could just reload the page to stop blocking.
2197 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552198 dialog_creator_->ResetJavaScriptState(this);
2199 dialog_creator_ = NULL;
2200 }
[email protected]420ae012009-04-24 05:16:322201
[email protected]3c9e1872010-11-18 16:17:492202 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252203 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042204 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322205}
2206
[email protected]b172aee2012-04-10 17:05:262207void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462208 // If we are creating a RVH for a restored controller, then we need to make
2209 // sure the RenderView starts with a next_page_id_ larger than the number
2210 // of restored entries. This must be called before the RenderView starts
2211 // navigating (to avoid a race between the browser updating max_page_id and
2212 // the renderer updating next_page_id_). Because of this, we only call this
2213 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562214 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582215 if (max_restored_page_id >
2216 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2217 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2218 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322219}
2220
[email protected]b172aee2012-04-10 17:05:262221bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2222 const string16& title) {
[email protected]420ae012009-04-24 05:16:322223 // For file URLs without a title, use the pathname instead. In the case of a
2224 // synthesized title, we don't want the update to count toward the "one set
2225 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512226 string16 final_title;
[email protected]420ae012009-04-24 05:16:322227 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512228 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2229 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322230 explicit_set = false; // Don't count synthetic titles toward the set limit.
2231 } else {
[email protected]acafd272011-07-26 17:35:572232 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322233 explicit_set = true;
2234 }
2235
[email protected]987fc3a2011-05-26 14:18:092236 // If a page is created via window.open and never navigated,
2237 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552238 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092239 if (entry) {
[email protected]36fc0392011-12-25 03:59:512240 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092241 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322242
[email protected]36fc0392011-12-25 03:59:512243 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092244 } else {
2245 if (page_title_when_no_navigation_entry_ == final_title)
2246 return false; // Nothing changed, don't bother.
2247
2248 page_title_when_no_navigation_entry_ = final_title;
2249 }
[email protected]420ae012009-04-24 05:16:322250
[email protected]420ae012009-04-24 05:16:322251 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232252 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322253
[email protected]2bb171882012-03-07 02:09:462254 std::pair<content::NavigationEntry*, bool> details =
2255 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142256
[email protected]ad50def52011-10-19 23:17:072257 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442258 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2259 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462260 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042261
[email protected]420ae012009-04-24 05:16:322262 return true;
2263}
2264
[email protected]b172aee2012-04-10 17:05:262265void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322266 // After sending out a swap notification, we need to send a disconnect
2267 // notification so that clients that pick up a pointer to |this| can NULL the
2268 // pointer. See Bug 1230284.
2269 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072270 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202271 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2272 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072273 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322274}
2275
[email protected]b172aee2012-04-10 17:05:262276void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322277 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072278 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122279 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2280 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072281 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322282}
2283
[email protected]b172aee2012-04-10 17:05:262284void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322285 if (!notify_disconnection_)
2286 return;
2287
2288 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072289 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322290 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2291 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072292 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322293}
2294
[email protected]5a3bdf52012-05-24 15:12:572295RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2296 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322297}
2298
[email protected]8d3347f2009-07-09 22:00:212299RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262300WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212301 return &render_manager_;
2302}
2303
[email protected]b172aee2012-04-10 17:05:262304content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372305 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462306 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512307}
2308
[email protected]b172aee2012-04-10 17:05:262309WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172310 return this;
2311}
2312
[email protected]b172aee2012-04-10 17:05:262313gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172314 if (delegate_)
2315 return delegate_->GetRootWindowResizerRect();
2316 return gfx::Rect();
2317}
2318
[email protected]b172aee2012-04-10 17:05:262319void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442320 // Don't send notifications if we are just creating a swapped-out RVH for
2321 // the opener chain. These won't be used for view-source or WebUI, so it's
2322 // ok to return early.
2323 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2324 return;
2325
[email protected]ad50def52011-10-19 23:17:072326 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272327 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322328 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532329 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232330 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322331 if (!entry)
2332 return;
2333
2334 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352335 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562336 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582337 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322338
2339 if (entry->IsViewSourceMode()) {
2340 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582341 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2342 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322343 }
[email protected]0666aef2009-05-13 19:48:082344
[email protected]d487beefe2011-12-21 05:41:212345 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262346
2347 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252348 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322349}
2350
[email protected]b172aee2012-04-10 17:05:262351void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522352 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322353 // Don't notify the world, since this came from a renderer in the
2354 // background.
2355 return;
2356 }
2357
2358 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312359 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232360 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302361
2362 // Restore the focus to the tab (otherwise the focus will be on the top
2363 // window).
[email protected]484ae5912010-09-29 19:16:142364 if (was_crashed && !FocusLocationBarByDefault() &&
2365 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302366 Focus();
[email protected]484ae5912010-09-29 19:16:142367 }
[email protected]32ded2212011-11-10 18:51:432368
[email protected]d8c660432011-12-22 20:51:252369 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322370}
2371
[email protected]b172aee2012-04-10 17:05:262372void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2373 base::TerminationStatus status,
2374 int error_code) {
[email protected]151a63d2011-12-20 22:32:522375 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322376 // The pending page's RenderViewHost is gone.
2377 return;
2378 }
2379
2380 SetIsLoading(false, NULL);
2381 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232382 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312383 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322384
[email protected]d8c660432011-12-22 20:51:252385 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272386 observers_,
[email protected]be1f56ab2011-12-22 06:55:312387 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322388}
2389
[email protected]b172aee2012-04-10 17:05:262390void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482391 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252392 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062393}
2394
[email protected]b172aee2012-04-10 17:05:262395void WebContentsImpl::DidNavigate(
2396 RenderViewHost* rvh,
2397 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582398 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322399 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372400
[email protected]434f69f2012-02-06 21:56:522401 // Update the site of the SiteInstance if it doesn't have one yet, unless
2402 // this is for about:blank. In that case, the SiteInstance can still be
2403 // considered unused until a navigation to a real page.
2404 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2405 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332406 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522407 }
[email protected]420ae012009-04-24 05:16:322408
2409 // Need to update MIME type here because it's referred to in
2410 // UpdateNavigationCommands() called by RendererDidNavigate() to
2411 // determine whether or not to enable the encoding menu.
2412 // It's updated only for the main frame. For a subframe,
2413 // RenderView::UpdateURL does not set params.contents_mime_type.
2414 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2415 // TODO(jungshik): Add a test for the encoding menu to avoid
2416 // regressing it again.
[email protected]2905f742011-10-13 03:51:582417 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322418 contents_mime_type_ = params.contents_mime_type;
2419
[email protected]8286f51a2011-05-31 17:39:132420 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002421 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392422
[email protected]a9c0bfe2010-09-17 08:35:222423 // Send notification about committed provisional loads. This notification is
2424 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2425 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082426 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072427 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2428 // that is not recorded in the navigation history. For the purpose of
2429 // tracking navigation events, we treat this event as a sub frame navigation
2430 // event.
2431 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582432 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222433 // Whether or not a page transition was triggered by going backward or
2434 // forward in the history is only stored in the navigation controller's
2435 // entry list.
2436 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512437 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582438 content::PAGE_TRANSITION_FORWARD_BACK)) {
2439 transition_type = content::PageTransitionFromInt(
2440 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222441 }
[email protected]0d60f0192011-04-14 12:40:102442 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252443 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102444 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462445 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222446 }
2447
[email protected]76543b92009-08-31 17:27:452448 if (!did_navigate)
2449 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322450
2451 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2452 // for the appropriate notification (best) or you can add it to
2453 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2454 // necessary, please).
2455
2456 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002457 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322458 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512459 if (delegate_)
2460 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002461 }
[email protected]420ae012009-04-24 05:16:322462 DidNavigateAnyFramePostCommit(rvh, details, params);
2463}
2464
[email protected]b172aee2012-04-10 17:05:262465void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2466 int32 page_id,
2467 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152468 // Ensure that this state update comes from either the active RVH or one of
2469 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522470 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322471
2472 // We must be prepared to handle state updates for any page, these occur
2473 // when the user is scrolling and entering form data, as well as when we're
2474 // leaving a page, in which case our state may have already been moved to
2475 // the next page. The navigation controller will look up the appropriate
2476 // NavigationEntry and update it when it is notified via the delegate.
2477
2478 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582479 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322480 if (entry_index < 0)
2481 return;
[email protected]10f417c52011-12-28 21:04:232482 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322483
[email protected]36fc0392011-12-25 03:59:512484 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322485 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512486 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322487 controller_.NotifyEntryChanged(entry, entry_index);
2488}
2489
[email protected]b172aee2012-04-10 17:05:262490void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2491 int32 page_id,
2492 const string16& title,
2493 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322494 // If we have a title, that's a pretty good indication that we've started
2495 // getting useful data.
2496 SetNotWaitingForResponse();
2497
[email protected]73eb2602012-02-09 19:50:552498 // Try to find the navigation entry, which might not be the current one.
2499 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232500 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582501 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092502
[email protected]73eb2602012-02-09 19:50:552503 // We can handle title updates when we don't have an entry in
2504 // UpdateTitleForEntry, but only if the update is from the current RVH.
2505 if (!entry && rvh != GetRenderViewHost())
2506 return;
2507
[email protected]a49e10b2011-08-01 23:57:462508 // TODO(evan): make use of title_direction.
2509 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092510 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322511 return;
2512
2513 // Broadcast notifications when the UI should be updated.
2514 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462515 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322516}
2517
[email protected]b172aee2012-04-10 17:05:262518void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2519 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312520 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322521}
2522
[email protected]b172aee2012-04-10 17:05:262523void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512524 if (delegate_)
2525 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322526}
2527
[email protected]b172aee2012-04-10 17:05:262528void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292529 // The UI may be in an event-tracking loop, such as between the
2530 // mouse-down and mouse-up in text selection or a button click.
2531 // Defer the close until after tracking is complete, so that we
2532 // don't free objects out from under the UI.
2533 // TODO(shess): This could probably be integrated with the
2534 // IsDoingDrag() test below. Punting for now because I need more
2535 // research to understand how this impacts platforms other than Mac.
2536 // TODO(shess): This could get more fine-grained. For instance,
2537 // closing a tab in another window while selecting text in the
2538 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212539 if (GetView()->IsEventTracking()) {
2540 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292541 return;
2542 }
2543
[email protected]24a4d1062009-07-10 23:10:422544 // If we close the tab while we're in the middle of a drag, we'll crash.
2545 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212546 if (GetView()->IsDoingDrag()) {
2547 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422548 return;
2549 }
2550
[email protected]420ae012009-04-24 05:16:322551 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522552 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512553 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322554}
2555
[email protected]b172aee2012-04-10 17:05:262556void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522557 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512558 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572559}
2560
[email protected]b172aee2012-04-10 17:05:262561void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512562 if (delegate_ && delegate_->IsPopupOrPanel(this))
2563 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322564}
2565
[email protected]b172aee2012-04-10 17:05:262566void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322567 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492568
[email protected]82114f52012-03-20 22:53:412569 if (delegate_ && content_restrictions_)
2570 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492571
2572 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252573 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322574}
2575
[email protected]b172aee2012-04-10 17:05:262576void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322577 scoped_ptr<LoadNotificationDetails> details;
2578
[email protected]10f417c52011-12-28 21:04:232579 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322580 // An entry may not exist for a stop when loading an initial blank page or
2581 // if an iframe injected by script into a blank page finishes loading.
2582 if (entry) {
[email protected]420ae012009-04-24 05:16:322583 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2584
2585 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512586 entry->GetVirtualURL(),
2587 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322588 elapsed,
2589 &controller_,
2590 controller_.GetCurrentEntryIndex()));
2591 }
2592
[email protected]420ae012009-04-24 05:16:322593 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492594
2595 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252596 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322597}
2598
[email protected]b172aee2012-04-10 17:05:262599void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162600 controller_.DiscardNonCommittedEntries();
2601
2602 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462603 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162604}
2605
[email protected]b172aee2012-04-10 17:05:262606void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512607 if (delegate_)
2608 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402609}
2610
[email protected]87717d0e2012-04-26 02:58:432611void WebContentsImpl::DocumentAvailableInMainFrame(
2612 RenderViewHost* render_view_host) {
2613 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2614 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102615}
2616
[email protected]b172aee2012-04-10 17:05:262617void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082618 RenderViewHost* render_view_host,
2619 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072620 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272621 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322622 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532623 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082624}
2625
[email protected]196159d2012-05-04 17:26:542626void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2627 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262628 const content::Referrer& referrer,
2629 WindowOpenDisposition disposition,
2630 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542631 // If this came from a swapped out RenderViewHost, we only allow the request
2632 // if we are still in the same BrowsingInstance.
2633 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2634 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2635 return;
2636 }
2637
[email protected]4ad5d77d2011-12-03 02:00:482638 // Delegate to RequestTransferURL because this is just the generic
2639 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582640 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482641 GlobalRequestID());
2642}
2643
[email protected]b172aee2012-04-10 17:05:262644void WebContentsImpl::RequestTransferURL(
2645 const GURL& url,
2646 const content::Referrer& referrer,
2647 WindowOpenDisposition disposition,
2648 int64 source_frame_id,
2649 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202650 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582651 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582652 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352653 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322654 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2655 // generated suggestions).
2656 //
[email protected]e0112912011-02-02 22:54:352657 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162658 // want web sites to see a referrer of "chrome://blah" (and some
2659 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322660 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432661 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222662 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482663 false /* is_renderer_initiated */);
2664 params.transferred_global_request_id = old_request_id;
2665 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222666 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322667 } else {
[email protected]6bf6a6b52012-02-03 15:41:432668 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482669 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2670 params.transferred_global_request_id = old_request_id;
2671 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582672 }
2673 if (new_contents) {
2674 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252675 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582676 DidOpenRequestedURL(new_contents,
2677 url,
2678 referrer,
2679 disposition,
2680 transition_type,
2681 source_frame_id));
[email protected]420ae012009-04-24 05:16:322682 }
2683}
2684
[email protected]e1c3a552012-05-04 20:51:322685void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2686 // Tell the active RenderViewHost to run unload handlers and close, as long
2687 // as the request came from a RenderViewHost in the same BrowsingInstance.
2688 // In most cases, we receive this from a swapped out RenderViewHost.
2689 // It is possible to receive it from one that has just been swapped in,
2690 // in which case we might as well deliver the message anyway.
2691 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2692 GetRenderViewHost()->ClosePage();
2693}
2694
[email protected]f546640b2012-05-15 00:03:492695void WebContentsImpl::RouteMessageEvent(
2696 RenderViewHost* rvh,
2697 const ViewMsg_PostMessage_Params& params) {
2698 // Only deliver the message to the active RenderViewHost if the request
2699 // came from a RenderViewHost in the same BrowsingInstance.
2700 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2701 return;
2702
2703 ViewMsg_PostMessage_Params new_params(params);
2704
2705 // If there is a source_routing_id, translate it to the routing ID for
2706 // the equivalent swapped out RVH in the target process. If we need
2707 // to create a swapped out RVH for the source tab, we create its opener
2708 // chain as well, since those will also be accessible to the target page.
2709 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2710 // Try to look up the WebContents for the source page.
2711 WebContentsImpl* source_contents = NULL;
2712 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2713 rvh->GetProcess()->GetID(), params.source_routing_id);
2714 if (source_rvh) {
2715 source_contents = static_cast<WebContentsImpl*>(
2716 source_rvh->GetDelegate()->GetAsWebContents());
2717 }
2718
2719 if (source_contents) {
2720 new_params.source_routing_id =
2721 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2722 } else {
2723 // We couldn't find it, so don't pass a source frame.
2724 new_params.source_routing_id = MSG_ROUTING_NONE;
2725 }
2726 }
2727
2728 // In most cases, we receive this from a swapped out RenderViewHost.
2729 // It is possible to receive it from one that has just been swapped in,
2730 // in which case we might as well deliver the message anyway.
2731 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2732 GetRenderViewHost()->GetRoutingID(), new_params));
2733}
2734
[email protected]b172aee2012-04-10 17:05:262735void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342736 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412737 const string16& message,
2738 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322739 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142740 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322741 IPC::Message* reply_msg,
2742 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072743 // Suppress JavaScript dialogs when requested. Also suppress messages when
2744 // showing an interstitial as it's shown over the previous page and we don't
2745 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502746 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582747 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272748 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072749 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522750 delegate_->ShouldSuppressDialogs() ||
2751 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322752
2753 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432754 std::string accept_lang = content::GetContentClient()->browser()->
2755 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552756 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522757 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432758 this,
2759 frame_url.GetOrigin(),
2760 accept_lang,
2761 javascript_message_type,
2762 message,
[email protected]51da7e32012-01-30 19:24:522763 default_prompt,
[email protected]b172aee2012-04-10 17:05:262764 base::Bind(&WebContentsImpl::OnDialogClosed,
2765 base::Unretained(this),
2766 rvh,
2767 reply_msg),
[email protected]51da7e32012-01-30 19:24:522768 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322769 }
[email protected]3ab9cb82011-06-03 18:02:072770
2771 if (suppress_this_message) {
2772 // If we are suppressing messages, just reply as if the user immediately
2773 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342774 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072775 }
2776
2777 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322778}
2779
[email protected]b172aee2012-04-10 17:05:262780void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2781 const string16& message,
2782 bool is_reload,
2783 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582784 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512785 if (delegate_)
2786 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072787
2788 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582789 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072790 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522791 delegate_->ShouldSuppressDialogs() ||
2792 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152793 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342794 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582795 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502796 return;
2797 }
[email protected]3ab9cb82011-06-03 18:02:072798
[email protected]7ab1e7d62009-10-14 23:32:012799 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552800 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522801 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322802 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262803 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522804 reply_msg));
[email protected]420ae012009-04-24 05:16:322805}
2806
[email protected]a796f202012-05-30 14:14:252807bool WebContentsImpl::AddMessageToConsole(int32 level,
2808 const string16& message,
2809 int32 line_no,
2810 const string16& source_id) {
2811 if (!delegate_)
2812 return false;
2813 return delegate_->AddMessageToConsole(this, level, message, line_no,
2814 source_id);
2815}
2816
[email protected]b172aee2012-04-10 17:05:262817WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332818 // We want to base the page config off of the real URL, rather than the
2819 // display URL.
2820 GURL url = controller_.GetActiveEntry()
2821 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2822 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322823}
2824
[email protected]b172aee2012-04-10 17:05:262825void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272826 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252827 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222828
[email protected]ea114722012-03-12 01:11:252829 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172830 if (rdh) // NULL in unittests.
2831 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252832}
2833
[email protected]b172aee2012-04-10 17:05:262834void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442835 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252836 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442837}
2838
[email protected]b172aee2012-04-10 17:05:262839void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2840 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152841 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522842 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152843 return;
2844
[email protected]9f76c1e2012-03-05 15:15:582845 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2846
[email protected]e5fc1632011-08-08 07:51:532847 // Ignore renderer unresponsive event if debugger is attached to the tab
2848 // since the event may be a result of the renderer sitting on a breakpoint.
2849 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442850 DevToolsAgentHost* agent =
2851 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2852 if (agent &&
2853 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532854 return;
2855
[email protected]420ae012009-04-24 05:16:322856 if (is_during_unload) {
2857 // Hang occurred while firing the beforeunload/unload handler.
2858 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582859 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322860
2861 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2862 return;
2863
2864 // If the tab hangs in the beforeunload/unload handler there's really
2865 // nothing we can do to recover. Pretend the unload listeners have
2866 // all fired and close the tab. If the hang is in the beforeunload handler
2867 // then the user will not have the option of cancelling the close.
2868 Close(rvh);
2869 return;
2870 }
2871
[email protected]9f76c1e2012-03-05 15:15:582872 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472873 return;
2874
[email protected]6934a702011-12-20 00:04:512875 if (delegate_)
2876 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322877}
2878
[email protected]b172aee2012-04-10 17:05:262879void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512880 if (delegate_)
2881 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322882}
2883
[email protected]b172aee2012-04-10 17:05:262884void WebContentsImpl::LoadStateChanged(
2885 const GURL& url,
2886 const net::LoadStateWithParam& load_state,
2887 uint64 upload_position,
2888 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322889 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562890 upload_position_ = upload_position;
2891 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502892 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202893 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302894 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212895 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322896 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462897 if (IsLoading()) {
2898 NotifyNavigationStateChanged(
2899 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2900 }
[email protected]420ae012009-04-24 05:16:322901}
2902
[email protected]b172aee2012-04-10 17:05:262903void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512904 if (delegate_)
2905 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252906}
2907
[email protected]b172aee2012-04-10 17:05:262908void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322909 bool proceed,
2910 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512911 if (delegate_)
2912 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322913}
2914
[email protected]b172aee2012-04-10 17:05:262915void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542916 RenderViewHost* render_view_host) {
2917 DidStartLoading();
2918}
2919
[email protected]b172aee2012-04-10 17:05:262920void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542921 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232922 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2923 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542924}
2925
[email protected]b172aee2012-04-10 17:05:262926void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102927 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262928 gfx::Size size = view_->GetContainerSize();
2929 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2930 // here during container initialization and normal window size will be set
2931 // later. In case of tab duplication this resizing to 0x0 prevents setting
2932 // normal size later so just ignore it.
2933 if (!size.IsEmpty())
2934 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322935}
2936
[email protected]b172aee2012-04-10 17:05:262937void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542938 NotifySwapped();
2939}
2940
[email protected]14392a52012-05-02 20:28:442941int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2942 SiteInstance* instance) {
2943 if (!opener_)
2944 return MSG_ROUTING_NONE;
2945
2946 // Recursively create RenderViews for anything else in the opener chain.
2947 return opener_->CreateOpenerRenderViews(instance);
2948}
2949
2950int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2951 int opener_route_id = MSG_ROUTING_NONE;
2952
2953 // If this tab has an opener, ensure it has a RenderView in the given
2954 // SiteInstance as well.
2955 if (opener_)
2956 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2957
2958 // Create a swapped out RenderView in the given SiteInstance if none exists,
2959 // setting its opener to the given route_id. Return the new view's route_id.
2960 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2961}
2962
[email protected]b172aee2012-04-10 17:05:262963NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202964 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542965}
2966
[email protected]b172aee2012-04-10 17:05:262967WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562968 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322969}
2970
[email protected]10f417c52011-12-28 21:04:232971NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262972 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322973 return controller_.GetLastCommittedEntry();
2974}
2975
[email protected]b172aee2012-04-10 17:05:262976bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442977 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442978 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322979 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522980
[email protected]420ae012009-04-24 05:16:322981 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442982 if (rwh_view)
2983 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322984
[email protected]74ce1ad2011-12-16 21:51:462985 // Make sure we use the correct starting page_id in the new RenderView.
2986 UpdateMaxPageIDIfNecessary(render_view_host);
2987 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582988 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462989
[email protected]7900bfdb2012-05-24 19:31:242990 std::string embedder_channel_name;
2991 int embedder_container_id;
2992 GetBrowserPluginEmbedderInfo(render_view_host,
2993 &embedder_channel_name,
2994 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:582995 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:492996 render_view_host)->CreateRenderView(string16(),
2997 opener_route_id,
2998 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:242999 embedder_channel_name,
3000 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523001 return false;
[email protected]14392a52012-05-02 20:28:443002 }
[email protected]a4127722011-04-27 23:13:523003
[email protected]e60c0232011-11-11 19:56:353004#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503005 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3006 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443007 if (rwh_view) {
3008 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3009 render_widget_host->WasResized();
3010 }
[email protected]f8233cc2011-05-31 20:24:503011#endif
3012
[email protected]420ae012009-04-24 05:16:323013 return true;
3014}
3015
[email protected]b172aee2012-04-10 17:05:263016void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3017 IPC::Message* reply_msg,
3018 bool success,
3019 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543020 if (is_showing_before_unload_dialog_ && !success) {
3021 // If a beforeunload dialog is canceled, we need to stop the throbber from
3022 // spinning, since we forced it to start spinning in Navigate.
3023 DidStopLoading();
3024
[email protected]3bbacc5b2012-04-17 17:46:153025 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543026 }
3027 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583028 static_cast<RenderViewHostImpl*>(
3029 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543030}
3031
[email protected]b172aee2012-04-10 17:05:263032void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123033 encoding_ = content::GetContentClient()->browser()->
3034 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103035}
[email protected]f45d2a72010-03-08 23:28:353036
[email protected]b172aee2012-04-10 17:05:263037void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463038 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263039 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143040 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
3041 if (!dlm)
3042 return;
3043 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263044 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143045 const NavigationEntry* entry = controller_.GetActiveEntry();
3046 if (entry)
3047 post_id = entry->GetPostID();
3048 }
[email protected]29a5ffc82012-03-13 19:35:583049 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143050 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143051 scoped_ptr<DownloadUrlParameters> params(
3052 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493053 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143054 params->set_post_id(post_id);
3055 params->set_prefer_cache(true);
3056 if (post_id >= 0)
3057 params->set_method("POST");
3058 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143059}
3060
[email protected]b172aee2012-04-10 17:05:263061void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213062 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443063 // Can be NULL during tests.
3064 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213065 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363066}
[email protected]9f76c1e2012-03-05 15:15:583067
[email protected]b172aee2012-04-10 17:05:263068RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583069 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3070}
[email protected]7900bfdb2012-05-24 19:31:243071
3072void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3073 content::RenderViewHost* render_view_host,
3074 std::string* embedder_channel_name,
3075 int* embedder_container_id) {
3076 content::RenderProcessHost* embedder_render_process_host =
3077 browser_plugin_host()->embedder_render_process_host();
3078 *embedder_container_id = browser_plugin_host()->instance_id();
3079 int embedder_process_id =
3080 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3081 if (embedder_process_id != -1) {
3082 *embedder_channel_name =
3083 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3084 embedder_process_id);
3085 }
3086}