blob: c86e17043c6f2b39fed468d6dc48435a10dd1887 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]43d9d782012-03-01 15:40:0913#include "base/string_number_conversions.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]172cf712012-05-23 15:07:3917#include "content/browser/browser_plugin/browser_plugin_host.h"
[email protected]b9535422012-02-09 01:47:5918#include "content/browser/child_process_security_policy_impl.h"
[email protected]0e12d7d2011-12-01 16:21:4419#include "content/browser/debugger/devtools_manager_impl.h"
[email protected]1ea3c792012-04-17 01:25:0420#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4621#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1222#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1623#include "content/browser/download/save_package.h"
[email protected]79078df2012-02-16 01:22:3224#include "content/browser/gpu/gpu_data_manager_impl.h"
[email protected]64d69de42012-02-06 00:19:5425#include "content/browser/gpu/gpu_process_host.h"
[email protected]5c9250872012-01-30 17:24:0526#include "content/browser/host_zoom_map_impl.h"
[email protected]0d9989d2011-12-21 20:26:0027#include "content/browser/intents/web_intents_dispatcher_impl.h"
[email protected]37a72af2011-06-13 05:42:0128#include "content/browser/load_from_memory_cache_details.h"
[email protected]f3b1a082011-11-18 00:34:3029#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3230#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5031#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]ea114722012-03-12 01:11:2532#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3333#include "content/browser/site_instance_impl.h"
[email protected]f9e4dae2012-04-10 21:26:3734#include "content/browser/web_contents/interstitial_page_impl.h"
35#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]d2353452012-01-19 19:53:5636#include "content/browser/webui/web_ui_impl.h"
[email protected]ce9751942011-09-21 01:57:2437#include "content/common/intents_messages.h"
[email protected]35be7ec2012-02-12 20:42:5138#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0239#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5740#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5841#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1142#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2043#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4444#include "content/public/browser/content_browser_client.h"
[email protected]0e12d7d2011-12-01 16:21:4445#include "content/public/browser/devtools_agent_host_registry.h"
[email protected]e582fdd2011-12-20 16:48:1746#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1447#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4648#include "content/public/browser/invalidate_type.h"
[email protected]32f497b2012-01-30 20:33:1549#include "content/public/browser/javascript_dialogs.h"
[email protected]09d31d52012-03-11 22:30:2750#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0051#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3752#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1453#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3254#include "content/public/browser/resource_request_details.h"
[email protected]7f6f44c2011-12-14 13:23:3855#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4256#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2557#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1058#include "content/public/browser/web_contents_view.h"
[email protected]863f70a2012-01-27 02:05:5059#include "content/public/browser/web_ui_controller_factory.h"
[email protected]e091df82011-10-11 18:13:2160#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4861#include "content/public/common/content_constants.h"
[email protected]4573fbd2011-10-31 20:25:1862#include "content/public/common/content_restriction.h"
[email protected]64d69de42012-02-06 00:19:5463#include "content/public/common/content_switches.h"
[email protected]a1d29162011-10-14 17:14:0364#include "content/public/common/url_constants.h"
[email protected]a53209b2012-01-20 16:48:1665#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2966#include "net/base/net_util.h"
[email protected]64d69de42012-02-06 00:19:5467#include "net/base/network_change_notifier.h"
[email protected]abe2c032011-03-31 18:49:3468#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3769#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]a08412b62012-05-29 21:28:5670#include "ui/base/layout.h"
[email protected]d353541f2012-05-03 22:45:4171#include "ui/base/ui_base_switches.h"
72#include "ui/gfx/monitor.h"
73#include "ui/gfx/screen.h"
[email protected]ce9751942011-09-21 01:57:2474#include "webkit/glue/web_intent_data.h"
[email protected]3a3b75a2012-06-01 08:38:3675#include "webkit/glue/web_intent_service_data.h"
[email protected]3c733bde2010-12-21 19:56:3176#include "webkit/glue/webpreferences.h"
77
[email protected]f66df822012-05-18 16:52:1778#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:5079#include "base/mac/foundation_util.h"
[email protected]d353541f2012-05-03 22:45:4180#include "ui/surface/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:5781#endif
[email protected]3e45ba92009-02-20 21:09:0082
[email protected]420ae012009-04-24 05:16:3283// Cross-Site Navigations
84//
[email protected]b172aee2012-04-10 17:05:2685// If a WebContentsImpl is told to navigate to a different web site (as
86// determined by SiteInstance), it will replace its current RenderViewHost with
87// a new RenderViewHost dedicated to the new SiteInstance. This works as
88// follows:
[email protected]420ae012009-04-24 05:16:3289//
90// - Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:4691// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:3292// - The pending RVH is "suspended," so that no navigation messages are sent to
93// its renderer until the onbeforeunload JavaScript handler has a chance to
94// run in the current RVH.
95// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
96// that it has a pending cross-site request. ResourceDispatcherHost will
97// check for this when the response arrives.
98// - The current RVH runs its onbeforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:4699// cancel all the pending logic. Otherwise we allow the pending RVH to send
100// the navigation request to its renderer.
101// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
102// main resource load on the pending RVH. It checks CrossSiteRequestManager
103// to see that it is a cross-site request, and installs a
104// CrossSiteResourceHandler.
105// - When RDH receives a response, the BufferedResourceHandler determines
106// whether it is a download. If so, it sends a message to the new renderer
107// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26108// pending RVH remains until the next DidNavigate event for this
109// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32110// - After RDH receives a response and determines that it is safe and not a
111// download, it pauses the response to first run the old page's onunload
112// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]b172aee2012-04-10 17:05:26113// method of WebContentsImpl on the UI thread, which sends a SwapOut message
[email protected]420ae012009-04-24 05:16:32114// to the current RVH.
[email protected]992db4c2011-05-12 15:37:15115// - Once the onunload handler is finished, a SwapOut_ACK message is sent to
[email protected]420ae012009-04-24 05:16:32116// the ResourceDispatcherHost, who unpauses the response. Data is then sent
117// to the pending RVH.
118// - The pending renderer sends a FrameNavigate message that invokes the
119// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46120// pending RVH.
[email protected]992db4c2011-05-12 15:37:15121// - The previous renderer is kept swapped out in RenderViewHostManager in case
122// the user goes back. The process only stays live if another tab is using
123// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32124
[email protected]0e12d7d2011-12-01 16:21:44125using content::DevToolsAgentHost;
126using content::DevToolsAgentHostRegistry;
127using content::DevToolsManagerImpl;
[email protected]e582fdd2011-12-20 16:48:17128using content::DownloadItem;
129using content::DownloadManager;
[email protected]c5a5c0842012-05-04 20:05:14130using content::DownloadUrlParameters;
[email protected]e5d549d2011-12-28 01:29:20131using content::GlobalRequestID;
[email protected]5fe3713a2012-02-22 08:31:56132using content::HostZoomMap;
[email protected]cadaec52012-02-08 21:53:13133using content::InterstitialPage;
[email protected]09d31d52012-03-11 22:30:27134using content::LoadNotificationDetails;
[email protected]b87ee522012-05-18 15:16:54135using content::NativeWebKeyboardEvent;
[email protected]c5eed492012-01-04 17:07:50136using content::NavigationController;
[email protected]10f417c52011-12-28 21:04:23137using content::NavigationEntry;
138using content::NavigationEntryImpl;
[email protected]e5d549d2011-12-28 01:29:20139using content::OpenURLParams;
[email protected]eaabba22012-03-07 15:02:11140using content::RenderViewHost;
[email protected]b0b67cf2012-01-18 21:59:57141using content::RenderViewHostDelegate;
[email protected]5a3bdf52012-05-24 15:12:57142using content::RenderViewHostDelegateView;
[email protected]09d31d52012-03-11 22:30:27143using content::RenderViewHostImpl;
[email protected]eaabba22012-03-07 15:02:11144using content::RenderWidgetHost;
[email protected]bafe6cd2012-05-23 23:09:50145using content::RenderWidgetHostImpl;
[email protected]5626b0892012-02-20 14:46:58146using content::RenderWidgetHostView;
[email protected]c30585c2012-02-16 15:02:04147using content::RenderWidgetHostViewPort;
[email protected]ea114722012-03-12 01:11:25148using content::ResourceDispatcherHostImpl;
[email protected]c5a5c0842012-05-04 20:05:14149using content::SSLStatus;
[email protected]adbfb8df2012-02-24 01:19:43150using content::SessionStorageNamespace;
[email protected]b6583592012-01-25 19:52:33151using content::SiteInstance;
[email protected]7f6f44c2011-12-14 13:23:38152using content::UserMetricsAction;
[email protected]ea049a02011-12-25 21:37:09153using content::WebContents;
[email protected]d8c660432011-12-22 20:51:25154using content::WebContentsObserver;
[email protected]d2353452012-01-19 19:53:56155using content::WebUI;
[email protected]c63cedf22012-01-17 18:42:22156using content::WebUIController;
[email protected]863f70a2012-01-27 02:05:50157using content::WebUIControllerFactory;
[email protected]6717bf272012-05-11 23:31:25158using webkit_glue::WebPreferences;
[email protected]0e12d7d2011-12-01 16:21:44159
[email protected]420ae012009-04-24 05:16:32160namespace {
161
162// Amount of time we wait between when a key event is received and the renderer
163// is queried for its state and pushed to the NavigationEntry.
164const int kQueryStateDelay = 5000;
165
[email protected]6ebdc9b2010-09-27 16:55:57166const int kSyncWaitDelay = 40;
167
[email protected]82114f52012-03-20 22:53:41168const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05169
[email protected]420ae012009-04-24 05:16:32170#if defined(OS_WIN)
171
172BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
173 // Note: erase is required to properly paint some widgets borders. This can
174 // be seen with textfields.
175 InvalidateRect(hwnd, NULL, TRUE);
176 return TRUE;
177}
178#endif
179
[email protected]2c5569662011-03-22 20:45:02180ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]10f417c52011-12-28 21:04:23181 content::BrowserContext* browser_context, const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:50182 NavigationController::ReloadType reload_type) {
[email protected]1ccb3568d2010-02-19 10:51:16183 switch (reload_type) {
[email protected]d202a7c2012-01-04 07:53:47184 case NavigationControllerImpl::RELOAD:
[email protected]2c5569662011-03-22 20:45:02185 return ViewMsg_Navigate_Type::RELOAD;
[email protected]d202a7c2012-01-04 07:53:47186 case NavigationControllerImpl::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02187 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]d202a7c2012-01-04 07:53:47188 case NavigationControllerImpl::NO_RELOAD:
[email protected]1ccb3568d2010-02-19 10:51:16189 break; // Fall through to rest of function.
190 }
[email protected]5e369672009-11-03 23:48:30191
[email protected]59246c572012-02-10 13:32:13192 // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates
193 // between |RESTORE_WITH_POST| and |RESTORE|.
[email protected]10f417c52011-12-28 21:04:23194 if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION &&
[email protected]59246c572012-02-10 13:32:13195 browser_context->DidLastSessionExitCleanly()) {
196 if (entry.GetHasPostData())
197 return ViewMsg_Navigate_Type::RESTORE_WITH_POST;
[email protected]2c5569662011-03-22 20:45:02198 return ViewMsg_Navigate_Type::RESTORE;
[email protected]59246c572012-02-10 13:32:13199 }
[email protected]5e369672009-11-03 23:48:30200
[email protected]2c5569662011-03-22 20:45:02201 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30202}
203
[email protected]10f417c52011-12-28 21:04:23204void MakeNavigateParams(const NavigationEntryImpl& entry,
[email protected]d202a7c2012-01-04 07:53:47205 const NavigationControllerImpl& controller,
[email protected]674bc592011-12-20 23:00:42206 content::WebContentsDelegate* delegate,
[email protected]c5eed492012-01-04 17:07:50207 NavigationController::ReloadType reload_type,
[email protected]7900bfdb2012-05-24 19:31:24208 const std::string& embedder_channel_name,
209 int embedder_container_id,
[email protected]1ccb3568d2010-02-19 10:51:16210 ViewMsg_Navigate_Params* params) {
[email protected]36fc0392011-12-25 03:59:51211 params->page_id = entry.GetPageID();
[email protected]876bc832010-09-07 16:29:54212 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]a26023822011-12-29 00:23:55213 params->current_history_list_offset = controller.GetLastCommittedEntryIndex();
214 params->current_history_list_length = controller.GetEntryCount();
[email protected]36fc0392011-12-25 03:59:51215 params->url = entry.GetURL();
216 params->referrer = entry.GetReferrer();
217 params->transition = entry.GetTransitionType();
218 params->state = entry.GetContentState();
[email protected]3cc72b12010-03-18 23:03:00219 params->navigation_type =
[email protected]a26023822011-12-29 00:23:55220 GetNavigationType(controller.GetBrowserContext(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34221 params->request_time = base::Time::Now();
[email protected]6c6b02d2011-09-02 03:36:47222 params->extra_headers = entry.extra_headers();
[email protected]4ad5d77d2011-12-03 02:00:48223 params->transferred_request_child_id =
224 entry.transferred_global_request_id().child_id;
225 params->transferred_request_request_id =
226 entry.transferred_global_request_id().request_id;
[email protected]80744782012-05-04 01:47:00227 // Avoid downloading when in view-source mode.
228 params->allow_download = !entry.IsViewSourceMode();
[email protected]7900bfdb2012-05-24 19:31:24229 params->embedder_channel_name = embedder_channel_name;
230 params->embedder_container_id = embedder_container_id;
[email protected]6c6b02d2011-09-02 03:36:47231
232 if (delegate)
233 delegate->AddNavigationHeaders(params->url, &params->extra_headers);
[email protected]056de2d2009-06-26 16:41:34234}
235
[email protected]f98f5092012-05-19 00:08:14236int GetSwitchValueAsInt(
237 const CommandLine& command_line,
238 const std::string& switch_string,
239 int min_value) {
240 std::string string_value = command_line.GetSwitchValueASCII(switch_string);
241 int int_value;
242 if (base::StringToInt(string_value, &int_value))
243 return std::max(min_value, int_value);
244 else
245 return min_value;
246}
247
[email protected]420ae012009-04-24 05:16:32248} // namespace
249
[email protected]a81343d232011-12-27 07:39:20250namespace content {
251
252WebContents* WebContents::Create(
253 BrowserContext* browser_context,
254 SiteInstance* site_instance,
255 int routing_id,
[email protected]b172aee2012-04-10 17:05:26256 const WebContents* base_web_contents,
[email protected]a81343d232011-12-27 07:39:20257 SessionStorageNamespace* session_storage_namespace) {
[email protected]b172aee2012-04-10 17:05:26258 return new WebContentsImpl(
[email protected]adbfb8df2012-02-24 01:19:43259 browser_context,
260 site_instance,
261 routing_id,
[email protected]b172aee2012-04-10 17:05:26262 static_cast<const WebContentsImpl*>(base_web_contents),
[email protected]14392a52012-05-02 20:28:44263 NULL,
[email protected]adbfb8df2012-02-24 01:19:43264 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace));
[email protected]a81343d232011-12-27 07:39:20265}
[email protected]746d3052012-05-22 15:15:47266
[email protected]299d7f12012-05-23 05:31:15267WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47268 return rvh->GetDelegate()->GetAsWebContents();
269}
270
[email protected]a81343d232011-12-27 07:39:20271}
[email protected]f4f50ef2011-01-21 19:01:19272
[email protected]b172aee2012-04-10 17:05:26273// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32274
[email protected]b172aee2012-04-10 17:05:26275WebContentsImpl::WebContentsImpl(
276 content::BrowserContext* browser_context,
277 SiteInstance* site_instance,
278 int routing_id,
279 const WebContentsImpl* base_web_contents,
[email protected]14392a52012-05-02 20:28:44280 WebContentsImpl* opener,
[email protected]b172aee2012-04-10 17:05:26281 SessionStorageNamespaceImpl* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42282 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07283 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
[email protected]3d7474ff2011-07-27 17:47:37284 this, browser_context, session_storage_namespace)),
[email protected]5a3bdf52012-05-24 15:12:57285 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44286 opener_(opener),
[email protected]4ca76c02012-05-16 16:19:05287 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)),
[email protected]d5f942ba2008-09-26 19:30:34288 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23289 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
290 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34291 waiting_for_response_(false),
[email protected]9c235f042011-08-10 22:28:21292 load_state_(net::LOAD_STATE_IDLE, string16()),
[email protected]094e5b22009-09-25 04:23:56293 upload_size_(0),
294 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47295 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57296 capturing_contents_(false),
297 is_being_destroyed_(false),
298 notify_disconnection_(false),
[email protected]2e5b90c2011-08-16 21:11:55299 dialog_creator_(NULL),
[email protected]fdd61c62009-04-22 19:22:57300#if defined(OS_WIN)
301 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
302#endif
[email protected]7ab1e7d62009-10-14 23:32:01303 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56304 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]ebf40a72010-07-22 01:46:38305 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25306 minimum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01307 static_cast<int>(content::kMinimumZoomFactor * 100)),
[email protected]b75b8292010-10-01 07:28:25308 maximum_zoom_percent_(
[email protected]0f083402011-11-22 02:59:01309 static_cast<int>(content::kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00310 temporary_zoom_settings_(false),
[email protected]32ded2212011-11-10 18:51:43311 content_restrictions_(0),
[email protected]da8543762012-03-20 08:52:20312 color_chooser_(NULL) {
[email protected]3d7474ff2011-07-27 17:47:37313 render_manager_.Init(browser_context, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32314
[email protected]38b098f2012-03-14 21:11:57315 view_.reset(content::GetContentClient()->browser()->
[email protected]5a3bdf52012-05-24 15:12:57316 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
317 if (view_.get()) {
318 CHECK(render_view_host_delegate_view_);
319 } else {
[email protected]38b098f2012-03-14 21:11:57320 content::WebContentsViewDelegate* delegate =
321 content::GetContentClient()->browser()->GetWebContentsViewDelegate(
322 this);
[email protected]5a3bdf52012-05-24 15:12:57323 view_.reset(CreateWebContentsView(
324 this, delegate, &render_view_host_delegate_view_));
325 CHECK(render_view_host_delegate_view_);
[email protected]38b098f2012-03-14 21:11:57326 }
327 CHECK(view_.get());
328
[email protected]ca13a442012-04-17 14:00:12329 // We have the initial size of the view be based on the size of the view of
330 // the passed in WebContents.
[email protected]b172aee2012-04-10 17:05:26331 view_->CreateView(base_web_contents ?
332 base_web_contents->GetView()->GetContainerSize() : gfx::Size());
[email protected]483623eb2011-10-25 09:30:00333
[email protected]14392a52012-05-02 20:28:44334 // Listen for whether our opener gets destroyed.
335 if (opener_) {
336 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
337 content::Source<WebContents>(opener_));
338 }
339
[email protected]bafe6cd2012-05-23 23:09:50340 registrar_.Add(this,
341 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
342 content::NotificationService::AllBrowserContextsAndSources());
343
[email protected]483623eb2011-10-25 09:30:00344#if defined(ENABLE_JAVA_BRIDGE)
345 java_bridge_dispatcher_host_manager_.reset(
346 new JavaBridgeDispatcherHostManager(this));
347#endif
[email protected]172cf712012-05-23 15:07:39348
349 browser_plugin_host_.reset(new content::BrowserPluginHost(this));
[email protected]332af7732009-03-11 13:21:35350}
initial.commit09911bf2008-07-26 23:55:29351
[email protected]b172aee2012-04-10 17:05:26352WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32353 is_being_destroyed_ = true;
354
[email protected]3ab9cb82011-06-03 18:02:07355 // Clear out any JavaScript state.
[email protected]2e5b90c2011-08-16 21:11:55356 if (dialog_creator_)
357 dialog_creator_->ResetJavaScriptState(this);
[email protected]3ab9cb82011-06-03 18:02:07358
[email protected]da8543762012-03-20 08:52:20359 if (color_chooser_)
360 color_chooser_->End();
361
[email protected]420ae012009-04-24 05:16:32362 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32363
[email protected]ca13a442012-04-17 14:00:12364 // Notify any observer that have a reference on this WebContents.
[email protected]ad50def52011-10-19 23:17:07365 content::NotificationService::current()->Notify(
[email protected]ea049a02011-12-25 21:37:09366 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
367 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:07368 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32369
370 // TODO(brettw) this should be moved to the view.
[email protected]010882f2011-11-14 22:32:07371#if defined(OS_WIN) && !defined(USE_AURA)
[email protected]420ae012009-04-24 05:16:32372 // If we still have a window handle, destroy it. GetNativeView can return
373 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42374 if (GetNativeView()) {
[email protected]151a63d2011-12-20 22:32:52375 RenderViewHost* host = GetRenderViewHost();
[email protected]9f76c1e2012-03-05 15:15:58376 if (host && host->GetView())
377 RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy();
[email protected]50bd6452010-11-27 19:39:42378 }
[email protected]420ae012009-04-24 05:16:32379#endif
[email protected]7ab1e7d62009-10-14 23:32:01380
381 // OnCloseStarted isn't called in unit tests.
[email protected]3bbacc5b2012-04-17 17:46:15382 if (!close_start_time_.is_null()) {
[email protected]7ab1e7d62009-10-14 23:32:01383 UMA_HISTOGRAM_TIMES("Tab.Close",
[email protected]3bbacc5b2012-04-17 17:46:15384 base::TimeTicks::Now() - close_start_time_);
[email protected]7ab1e7d62009-10-14 23:32:01385 }
[email protected]b5a1d11c2011-02-17 03:09:42386
[email protected]2db9bd72012-04-13 20:20:56387 FOR_EACH_OBSERVER(WebContentsObserver,
388 observers_,
389 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08390
[email protected]6934a702011-12-20 00:04:51391 SetDelegate(NULL);
[email protected]b5a1d11c2011-02-17 03:09:42392}
393
[email protected]b172aee2012-04-10 17:05:26394WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh,
395 const GURL& url) {
[email protected]64d69de42012-02-06 00:19:54396 WebPreferences prefs;
397
398 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
399
400 prefs.developer_extras_enabled = true;
401 prefs.javascript_enabled =
402 !command_line.HasSwitch(switches::kDisableJavaScript);
403 prefs.web_security_enabled =
404 !command_line.HasSwitch(switches::kDisableWebSecurity);
405 prefs.plugins_enabled =
406 !command_line.HasSwitch(switches::kDisablePlugins);
407 prefs.java_enabled =
408 !command_line.HasSwitch(switches::kDisableJava);
409
410 prefs.uses_page_cache =
411 command_line.HasSwitch(switches::kEnableFastback);
412 prefs.remote_fonts_enabled =
413 !command_line.HasSwitch(switches::kDisableRemoteFonts);
414 prefs.xss_auditor_enabled =
415 !command_line.HasSwitch(switches::kDisableXSSAuditor);
416 prefs.application_cache_enabled =
417 !command_line.HasSwitch(switches::kDisableApplicationCache);
418
419 prefs.local_storage_enabled =
420 !command_line.HasSwitch(switches::kDisableLocalStorage);
421 prefs.databases_enabled =
422 !command_line.HasSwitch(switches::kDisableDatabases);
423 prefs.webaudio_enabled =
424 !command_line.HasSwitch(switches::kDisableWebAudio);
425
426 prefs.experimental_webgl_enabled =
427 GpuProcessHost::gpu_enabled() &&
428 !command_line.HasSwitch(switches::kDisable3DAPIs) &&
429 !command_line.HasSwitch(switches::kDisableExperimentalWebGL);
430
[email protected]e0d8c422012-06-04 22:57:19431 prefs.flash_3d_enabled = prefs.flash_stage3d_enabled =
432 GpuProcessHost::gpu_enabled();
433
[email protected]64d69de42012-02-06 00:19:54434 prefs.gl_multisampling_enabled =
435 !command_line.HasSwitch(switches::kDisableGLMultisampling);
436 prefs.privileged_webgl_extensions_enabled =
437 command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions);
438 prefs.site_specific_quirks_enabled =
439 !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks);
440 prefs.allow_file_access_from_file_urls =
441 command_line.HasSwitch(switches::kAllowFileAccessFromFiles);
442 prefs.show_composited_layer_borders =
443 command_line.HasSwitch(switches::kShowCompositedLayerBorders);
444 prefs.show_composited_layer_tree =
445 command_line.HasSwitch(switches::kShowCompositedLayerTree);
446 prefs.show_fps_counter =
447 command_line.HasSwitch(switches::kShowFPSCounter);
[email protected]8611a852012-05-23 22:11:19448 prefs.show_paint_rects =
449 command_line.HasSwitch(switches::kShowPaintRects);
[email protected]64d69de42012-02-06 00:19:54450 prefs.accelerated_compositing_enabled =
451 GpuProcessHost::gpu_enabled() &&
452 !command_line.HasSwitch(switches::kDisableAcceleratedCompositing);
[email protected]64d69de42012-02-06 00:19:54453 prefs.force_compositing_mode =
454 command_line.HasSwitch(switches::kForceCompositingMode);
455 prefs.fixed_position_compositing_enabled =
456 command_line.HasSwitch(switches::kEnableCompositingForFixedPosition);
457 prefs.accelerated_2d_canvas_enabled =
458 GpuProcessHost::gpu_enabled() &&
459 !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas);
[email protected]e1f6bdd2012-02-07 21:52:58460 prefs.deferred_2d_canvas_enabled =
[email protected]00bbad22012-05-25 13:24:17461 !command_line.HasSwitch(switches::kDisableDeferred2dCanvas);
[email protected]eb4c1402012-02-25 00:46:36462 prefs.threaded_animation_enabled =
[email protected]efcde132012-05-30 01:05:18463 !command_line.HasSwitch(switches::kDisableThreadedAnimation);
[email protected]64d69de42012-02-06 00:19:54464 prefs.accelerated_painting_enabled =
465 GpuProcessHost::gpu_enabled() &&
466 command_line.HasSwitch(switches::kEnableAcceleratedPainting);
467 prefs.accelerated_filters_enabled =
468 GpuProcessHost::gpu_enabled() &&
469 command_line.HasSwitch(switches::kEnableAcceleratedFilters);
470 prefs.accelerated_layers_enabled =
471 prefs.accelerated_animation_enabled =
472 !command_line.HasSwitch(switches::kDisableAcceleratedLayers);
[email protected]64d69de42012-02-06 00:19:54473 prefs.accelerated_plugins_enabled =
474 !command_line.HasSwitch(switches::kDisableAcceleratedPlugins);
475 prefs.accelerated_video_enabled =
476 !command_line.HasSwitch(switches::kDisableAcceleratedVideo);
477 prefs.partial_swap_enabled =
478 command_line.HasSwitch(switches::kEnablePartialSwap);
479 prefs.interactive_form_validation_enabled =
480 !command_line.HasSwitch(switches::kDisableInteractiveFormValidation);
481 prefs.fullscreen_enabled =
482 !command_line.HasSwitch(switches::kDisableFullScreen);
[email protected]37ac2a82012-03-01 05:30:16483 prefs.css_regions_enabled =
484 command_line.HasSwitch(switches::kEnableCssRegions);
[email protected]bc199582012-03-29 09:02:29485 prefs.css_shaders_enabled =
486 command_line.HasSwitch(switches::kEnableCssShaders);
[email protected]a08412b62012-05-29 21:28:56487 prefs.device_supports_touch =
488 ui::GetDisplayLayout() == ui::LAYOUT_TOUCH;
[email protected]64d69de42012-02-06 00:19:54489
490#if defined(OS_MACOSX)
491 bool default_enable_scroll_animator = true;
492#else
493 // On CrOS, the launcher always passes in the --enable flag.
494 bool default_enable_scroll_animator = false;
495#endif
496 prefs.enable_scroll_animator = default_enable_scroll_animator;
497 if (command_line.HasSwitch(switches::kEnableSmoothScrolling))
498 prefs.enable_scroll_animator = true;
499 if (command_line.HasSwitch(switches::kDisableSmoothScrolling))
500 prefs.enable_scroll_animator = false;
501
502 prefs.visual_word_movement_enabled =
503 command_line.HasSwitch(switches::kEnableVisualWordMovement);
504 prefs.per_tile_painting_enabled =
505 command_line.HasSwitch(switches::kEnablePerTilePainting);
506
507 { // Certain GPU features might have been blacklisted.
[email protected]79078df2012-02-16 01:22:32508 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance();
[email protected]64d69de42012-02-06 00:19:54509 DCHECK(gpu_data_manager);
[email protected]d56ecf922012-02-15 16:03:11510 uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType();
511 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING)
[email protected]64d69de42012-02-06 00:19:54512 prefs.accelerated_compositing_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11513 if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL)
[email protected]64d69de42012-02-06 00:19:54514 prefs.experimental_webgl_enabled = false;
[email protected]e0d8c422012-06-04 22:57:19515 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D)
516 prefs.flash_3d_enabled = false;
517 if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D)
518 prefs.flash_stage3d_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11519 if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS)
[email protected]64d69de42012-02-06 00:19:54520 prefs.accelerated_2d_canvas_enabled = false;
[email protected]d56ecf922012-02-15 16:03:11521 if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING)
[email protected]64d69de42012-02-06 00:19:54522 prefs.gl_multisampling_enabled = false;
523
524 // Accelerated video and animation are slower than regular when using a
[email protected]2ffd73d2012-03-02 17:33:45525 // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile.
[email protected]79078df2012-02-16 01:22:32526 if (gpu_data_manager->ShouldUseSoftwareRendering()) {
[email protected]64d69de42012-02-06 00:19:54527 prefs.accelerated_video_enabled = false;
528 prefs.accelerated_animation_enabled = false;
[email protected]2ffd73d2012-03-02 17:33:45529 prefs.accelerated_layers_enabled = false;
[email protected]428e8202012-05-16 00:08:09530 prefs.accelerated_plugins_enabled = false;
[email protected]64d69de42012-02-06 00:19:54531 }
532 }
533
[email protected]b9535422012-02-09 01:47:59534 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings(
[email protected]9f76c1e2012-03-05 15:15:58535 rvh->GetProcess()->GetID())) {
[email protected]64d69de42012-02-06 00:19:54536 prefs.loads_images_automatically = true;
537 prefs.javascript_enabled = true;
538 }
539
540 prefs.is_online = !net::NetworkChangeNotifier::IsOffline();
541
542 // Force accelerated compositing and 2d canvas off for chrome:, about: and
543 // chrome-devtools: pages (unless it's specifically allowed).
544 if ((url.SchemeIs(chrome::kChromeDevToolsScheme) ||
[email protected]64d69de42012-02-06 00:19:54545 url.SchemeIs(chrome::kChromeUIScheme) ||
546 (url.SchemeIs(chrome::kAboutScheme) &&
547 url.spec() != chrome::kAboutBlankURL)) &&
[email protected]b049fbd42012-02-08 02:03:25548 !command_line.HasSwitch(switches::kAllowWebUICompositing)) {
[email protected]64d69de42012-02-06 00:19:54549 prefs.accelerated_compositing_enabled = false;
550 prefs.accelerated_2d_canvas_enabled = false;
551 }
[email protected]8b3b36152012-05-01 04:55:07552#if defined(OS_MACOSX)
553 // Mac doesn't have gfx::Screen::GetMonitorNearestWindow impl.
554 // crbug.com/125690.
[email protected]82c9a8e2012-05-02 01:07:23555 prefs.default_device_scale_factor =
556 gfx::Monitor::GetDefaultDeviceScaleFactor();
[email protected]8b3b36152012-05-01 04:55:07557#else
558 if (rvh->GetView()) {
559 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
560 rvh->GetView()->GetNativeView());
561 prefs.default_device_scale_factor =
562 static_cast<int>(monitor.device_scale_factor());
563 } else {
[email protected]82c9a8e2012-05-02 01:07:23564 prefs.default_device_scale_factor =
565 gfx::Monitor::GetDefaultDeviceScaleFactor();;
[email protected]8b3b36152012-05-01 04:55:07566 }
567#endif
[email protected]43d9d782012-03-01 15:40:09568
[email protected]f98f5092012-05-19 00:08:14569 if (command_line.HasSwitch(switches::kDefaultTileWidth))
570 prefs.default_tile_width =
571 GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1);
572 if (command_line.HasSwitch(switches::kDefaultTileHeight))
573 prefs.default_tile_height =
574 GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1);
575 if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth))
576 prefs.max_untiled_layer_width =
577 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1);
578 if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight))
579 prefs.max_untiled_layer_height =
580 GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1);
581
[email protected]2486dce2012-05-23 17:18:19582 if (gfx::Screen::IsDIPEnabled()) {
583 // Only apply when using DIP coordinate system as this setting interferes
584 // with fixed layout mode.
585 prefs.apply_default_device_scale_factor_in_compositor = true;
586 }
587
[email protected]96bcdc102012-05-24 23:42:10588 prefs.fixed_position_creates_stacking_context =
589 command_line.HasSwitch(switches::kFixedPositionCreatesStackingContext);
590
[email protected]2e21fe292012-03-02 22:52:32591 content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs);
[email protected]64d69de42012-02-06 00:19:54592
593 return prefs;
594}
595
[email protected]b172aee2012-04-10 17:05:26596NavigationControllerImpl& WebContentsImpl::GetControllerImpl() {
[email protected]cdcb1dee2012-01-04 00:46:20597 return controller_;
598}
599
[email protected]b172aee2012-04-10 17:05:26600RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]765187182012-01-11 23:59:28601 return &render_manager_;
602}
603
[email protected]b172aee2012-04-10 17:05:26604bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) {
[email protected]d2353452012-01-19 19:53:56605 if (GetWebUI() &&
606 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17607 return true;
[email protected]d2353452012-01-19 19:53:56608 }
[email protected]f82d57b52011-04-27 19:13:17609
[email protected]d8c660432011-12-22 20:51:25610 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
611 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10612 while ((observer = it.GetNext()) != NULL)
613 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53614 return true;
[email protected]403415a2011-01-10 18:57:53615
[email protected]724159a2010-12-30 01:11:18616 bool handled = true;
617 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26618 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]8b5af492011-11-28 21:50:58619 IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService,
620 OnRegisterIntentService)
[email protected]ce9751942011-09-21 01:57:24621 IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch,
622 OnWebIntentDispatch)
[email protected]724159a2010-12-30 01:11:18623 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
624 OnDidLoadResourceFromMemoryCache)
625 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
626 OnDidDisplayInsecureContent)
627 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
628 OnDidRunInsecureContent)
629 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
630 OnDocumentLoadedInFrame)
631 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]9bf6ee9f2012-04-11 11:07:26632 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError,
633 OnDidFailLoadWithError)
[email protected]c8f73ab2011-01-22 00:05:17634 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
635 OnUpdateContentRestrictions)
[email protected]7d472472011-01-22 01:30:25636 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26637 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]c7dd2f62011-07-18 15:57:59638 IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL)
[email protected]3a29a6e2011-08-24 18:26:21639 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20640 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
641 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
642 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16643 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]d952a052011-09-06 18:42:45644 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
[email protected]7fc4bbb2011-09-08 21:23:10645 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20646 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
647 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
648 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
649 OnSetSelectedColorInColorChooser)
[email protected]8be45842012-04-13 19:49:29650 IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung)
[email protected]d0759f492012-04-19 22:50:50651 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]724159a2010-12-30 01:11:18652 IPC_MESSAGE_UNHANDLED(handled = false)
653 IPC_END_MESSAGE_MAP_EX()
654
655 if (!message_is_ok) {
[email protected]7f6f44c2011-12-14 13:23:38656 content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18657 GetRenderProcessHost()->ReceivedBadMessage();
658 }
659
660 return handled;
661}
662
[email protected]b172aee2012-04-10 17:05:26663void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18664 RenderViewHost* render_view_host,
[email protected]8caadeb2011-11-22 02:45:23665 const content::FileChooserParams& params) {
[email protected]6934a702011-12-20 00:04:51666 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18667}
668
[email protected]b172aee2012-04-10 17:05:26669NavigationController& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56670 return controller_;
671}
672
[email protected]b172aee2012-04-10 17:05:26673const NavigationController& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56674 return controller_;
675}
676
[email protected]b172aee2012-04-10 17:05:26677content::BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55678 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30679}
680
[email protected]b172aee2012-04-10 17:05:26681const GURL& WebContentsImpl::GetURL() const {
[email protected]be1f56ab2011-12-22 06:55:31682 // We may not have a navigation entry yet
[email protected]10f417c52011-12-28 21:04:23683 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]36fc0392011-12-25 03:59:51684 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31685}
686
687
[email protected]b172aee2012-04-10 17:05:26688const base::PropertyBag* WebContentsImpl::GetPropertyBag() const {
[email protected]be1f56ab2011-12-22 06:55:31689 return &property_bag_;
690}
691
[email protected]b172aee2012-04-10 17:05:26692base::PropertyBag* WebContentsImpl::GetPropertyBag() {
[email protected]be1f56ab2011-12-22 06:55:31693 return &property_bag_;
694}
695
[email protected]b172aee2012-04-10 17:05:26696content::WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31697 return delegate_;
698}
699
[email protected]b172aee2012-04-10 17:05:26700void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31701 // TODO(cbentzel): remove this debugging code?
702 if (delegate == delegate_)
703 return;
704 if (delegate_)
705 delegate_->Detach(this);
706 delegate_ = delegate;
707 if (delegate_)
708 delegate_->Attach(this);
709}
710
[email protected]b172aee2012-04-10 17:05:26711content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]82114f52012-03-20 22:53:41712 RenderViewHostImpl* host = render_manager_.current_host();
713 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16714}
715
[email protected]b172aee2012-04-10 17:05:26716RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]be1f56ab2011-12-22 06:55:31717 return render_manager_.current_host();
718}
719
[email protected]b172aee2012-04-10 17:05:26720RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]be1f56ab2011-12-22 06:55:31721 return render_manager_.GetRenderWidgetHostView();
722}
723
[email protected]b172aee2012-04-10 17:05:26724content::WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31725 return view_.get();
726}
727
[email protected]b172aee2012-04-10 17:05:26728content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]863f70a2012-01-27 02:05:50729 WebUIControllerFactory* factory =
730 content::GetContentClient()->browser()->GetWebUIControllerFactory();
731 if (!factory)
732 return NULL;
[email protected]d2353452012-01-19 19:53:56733 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]c63cedf22012-01-17 18:42:22734 WebUIController* controller =
[email protected]863f70a2012-01-27 02:05:50735 factory->CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22736 if (controller) {
737 web_ui->SetController(controller);
738 return web_ui;
739 }
740
741 delete web_ui;
742 return NULL;
743}
744
[email protected]b172aee2012-04-10 17:05:26745content::WebUI* WebContentsImpl::GetWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31746 return render_manager_.web_ui() ? render_manager_.web_ui()
747 : render_manager_.pending_web_ui();
748}
749
[email protected]b172aee2012-04-10 17:05:26750content::WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]be1f56ab2011-12-22 06:55:31751 return render_manager_.web_ui();
[email protected]d5f942ba2008-09-26 19:30:34752}
753
[email protected]86ef6a392012-05-11 22:03:11754void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
755 user_agent_override_ = override;
756}
757
758const std::string& WebContentsImpl::GetUserAgentOverride() const {
759 return user_agent_override_;
760}
761
[email protected]b172aee2012-04-10 17:05:26762const string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55763 // Transient entries take precedence. They are used for interstitial pages
764 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23765 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08766 std::string accept_languages =
[email protected]597a867b2011-11-18 18:31:20767 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30768 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23769 if (entry) {
[email protected]b5cca982011-05-26 04:42:08770 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23771 }
[email protected]7ade2732011-02-10 00:13:58772 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
773 render_manager_.pending_web_ui() : render_manager_.web_ui();
774 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54775 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55776 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54777 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35778 // Give the Web UI the chance to override our title.
[email protected]c63cedf22012-01-17 18:42:22779 const string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54780 if (!title.empty())
781 return title;
782 }
783 }
784
785 // We use the title for the last committed entry rather than a pending
786 // navigation entry. For example, when the user types in a URL, we want to
787 // keep the old page's title until the new load has committed and we get a new
788 // title.
[email protected]96d185d2009-04-24 03:28:54789 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23790 if (entry) {
[email protected]b5cca982011-05-26 04:42:08791 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23792 }
[email protected]987fc3a2011-05-26 14:18:09793
794 // |page_title_when_no_navigation_entry_| is finally used
795 // if no title cannot be retrieved.
796 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54797}
798
[email protected]b172aee2012-04-10 17:05:26799int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46800 return GetMaxPageIDForSiteInstance(GetSiteInstance());
801}
802
[email protected]b172aee2012-04-10 17:05:26803int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
804 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33805 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
806 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46807
[email protected]b6583592012-01-25 19:52:33808 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34809}
810
[email protected]b172aee2012-04-10 17:05:26811void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46812 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
813}
814
[email protected]b172aee2012-04-10 17:05:26815void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33816 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46817 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33818 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34819}
820
[email protected]b172aee2012-04-10 17:05:26821void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) {
822 max_page_ids_ = web_contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57823}
824
[email protected]b172aee2012-04-10 17:05:26825SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]9f76c1e2012-03-05 15:15:58826 return render_manager_.current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54827}
828
[email protected]b172aee2012-04-10 17:05:26829SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]77362eb2011-08-01 17:18:38830 RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ?
831 render_manager_.pending_render_view_host() :
832 render_manager_.current_host();
[email protected]9f76c1e2012-03-05 15:15:58833 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38834}
835
[email protected]b172aee2012-04-10 17:05:26836bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31837 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49838}
839
[email protected]b172aee2012-04-10 17:05:26840bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31841 return waiting_for_response_;
842}
843
[email protected]b172aee2012-04-10 17:05:26844const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31845 return load_state_;
846}
847
[email protected]b172aee2012-04-10 17:05:26848const string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31849 return load_state_host_;
850}
851
[email protected]b172aee2012-04-10 17:05:26852uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31853 return upload_size_;
854}
855
[email protected]b172aee2012-04-10 17:05:26856uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31857 return upload_position_;
858}
859
[email protected]b172aee2012-04-10 17:05:26860const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31861 return encoding_;
862}
863
[email protected]b172aee2012-04-10 17:05:26864bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31865 return displayed_insecure_content_;
866}
867
[email protected]b172aee2012-04-10 17:05:26868void WebContentsImpl::SetCapturingContents(bool cap) {
[email protected]be1f56ab2011-12-22 06:55:31869 capturing_contents_ = cap;
870}
871
[email protected]b172aee2012-04-10 17:05:26872bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31873 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
874 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
875 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49876}
877
[email protected]b172aee2012-04-10 17:05:26878void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
879 int error_code) {
[email protected]443b80e2010-12-14 00:42:23880 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34881 return;
882
[email protected]443b80e2010-12-14 00:42:23883 crashed_status_ = status;
884 crashed_error_code_ = error_code;
[email protected]d9083482012-01-06 00:38:46885 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34886}
887
[email protected]b172aee2012-04-10 17:05:26888base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31889 return crashed_status_;
890}
891
[email protected]b172aee2012-04-10 17:05:26892bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31893 return is_being_destroyed_;
894}
895
[email protected]b172aee2012-04-10 17:05:26896void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34897 if (delegate_)
898 delegate_->NavigationStateChanged(this, changed_flags);
899}
900
[email protected]b172aee2012-04-10 17:05:26901void WebContentsImpl::DidBecomeSelected() {
[email protected]96d185d2009-04-24 03:28:54902 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04903 RenderWidgetHostViewPort* rwhv =
904 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16905 if (rwhv) {
906 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43907#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16908 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43909#endif
910 }
[email protected]96d185d2009-04-24 03:28:54911
[email protected]5ac20162010-11-24 23:33:11912 last_selected_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38913
[email protected]d8c660432011-12-22 20:51:25914 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected());
[email protected]b9769d82012-02-10 00:23:59915
916 // The resize rect might have changed while this was inactive -- send the new
917 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58918 RenderViewHostImpl* rvh =
919 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59920 if (rvh) {
921 rvh->ResizeRectChanged(GetRootWindowResizerRect());
922 }
[email protected]96d185d2009-04-24 03:28:54923}
924
[email protected]be1f56ab2011-12-22 06:55:31925
[email protected]b172aee2012-04-10 17:05:26926base::TimeTicks WebContentsImpl::GetLastSelectedTime() const {
[email protected]be1f56ab2011-12-22 06:55:31927 return last_selected_time_;
928}
929
[email protected]b172aee2012-04-10 17:05:26930void WebContentsImpl::WasHidden() {
[email protected]be1f56ab2011-12-22 06:55:31931 if (!capturing_contents_) {
[email protected]151a63d2011-12-20 22:32:52932 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
933 // open a tab in then background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26934 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52935 // removes the |GetRenderViewHost()|; then when we actually destroy the
936 // window, OnWindowPosChanged() notices and calls HideContents() (which
937 // calls us).
[email protected]c30585c2012-02-16 15:02:04938 RenderWidgetHostViewPort* rwhv =
939 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16940 if (rwhv)
941 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54942 }
943
[email protected]375fa1b2012-05-22 22:05:37944 bool is_visible = false;
[email protected]ad50def52011-10-19 23:17:07945 content::NotificationService::current()->Notify(
[email protected]375fa1b2012-05-22 22:05:37946 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
[email protected]ea049a02011-12-25 21:37:09947 content::Source<WebContents>(this),
[email protected]375fa1b2012-05-22 22:05:37948 content::Details<bool>(&is_visible));
949}
950
951void WebContentsImpl::WasRestored() {
952 bool is_visible = true;
953 content::NotificationService::current()->Notify(
954 content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
955 content::Source<WebContents>(this),
956 content::Details<bool>(&is_visible));
[email protected]96d185d2009-04-24 03:28:54957}
958
[email protected]b172aee2012-04-10 17:05:26959void WebContentsImpl::ShowContents() {
[email protected]c30585c2012-02-16 15:02:04960 RenderWidgetHostViewPort* rwhv =
961 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]be1f56ab2011-12-22 06:55:31962 if (rwhv)
963 rwhv->DidBecomeSelected();
[email protected]375fa1b2012-05-22 22:05:37964 WasRestored();
[email protected]be1f56ab2011-12-22 06:55:31965}
966
[email protected]b172aee2012-04-10 17:05:26967void WebContentsImpl::HideContents() {
[email protected]be1f56ab2011-12-22 06:55:31968 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
969 // our superclass HideContents(), because some callers want to be very picky
970 // about the order in which these get called. In addition to making the code
971 // here practically impossible to understand, this also means we end up
[email protected]b172aee2012-04-10 17:05:26972 // calling WebContentsImpl::WasHidden() twice if callers call both versions of
973 // HideContents() on a WebContentsImpl.
[email protected]be1f56ab2011-12-22 06:55:31974 WasHidden();
975}
976
[email protected]b172aee2012-04-10 17:05:26977bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31978 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27979 return WillNotifyDisconnection() &&
980 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58981 !static_cast<RenderViewHostImpl*>(
982 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31983}
984
[email protected]b172aee2012-04-10 17:05:26985void WebContentsImpl::Stop() {
[email protected]0bfbf882011-12-22 18:19:27986 render_manager_.Stop();
[email protected]d8c660432011-12-22 20:51:25987 FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation());
[email protected]0bfbf882011-12-22 18:19:27988}
989
[email protected]b172aee2012-04-10 17:05:26990WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:44991 // We use our current SiteInstance since the cloned entry will use it anyway.
992 // We pass |this| for the |base_web_contents| to size the view correctly, and
993 // our own opener so that the cloned page can access it if it was before.
[email protected]b172aee2012-04-10 17:05:26994 WebContentsImpl* tc = new WebContentsImpl(
[email protected]14392a52012-05-02 20:28:44995 GetBrowserContext(), GetSiteInstance(),
996 MSG_ROUTING_NONE, this, opener_, NULL);
[email protected]cdcb1dee2012-01-04 00:46:20997 tc->GetControllerImpl().CopyStateFrom(controller_);
[email protected]0bfbf882011-12-22 18:19:27998 return tc;
999}
1000
[email protected]b172aee2012-04-10 17:05:261001void WebContentsImpl::AddNewContents(WebContents* new_contents,
1002 WindowOpenDisposition disposition,
1003 const gfx::Rect& initial_pos,
1004 bool user_gesture) {
[email protected]0bfbf882011-12-22 18:19:271005 if (!delegate_)
1006 return;
1007
1008 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1009 user_gesture);
1010}
1011
[email protected]b172aee2012-04-10 17:05:261012gfx::NativeView WebContentsImpl::GetContentNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271013 return view_->GetContentNativeView();
1014}
1015
[email protected]b172aee2012-04-10 17:05:261016gfx::NativeView WebContentsImpl::GetNativeView() const {
[email protected]0bfbf882011-12-22 18:19:271017 return view_->GetNativeView();
1018}
1019
[email protected]b172aee2012-04-10 17:05:261020void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const {
[email protected]0bfbf882011-12-22 18:19:271021 view_->GetContainerBounds(out);
1022}
1023
[email protected]b172aee2012-04-10 17:05:261024void WebContentsImpl::Focus() {
[email protected]0bfbf882011-12-22 18:19:271025 view_->Focus();
1026}
1027
[email protected]14392a52012-05-02 20:28:441028void WebContentsImpl::Observe(int type,
1029 const content::NotificationSource& source,
1030 const content::NotificationDetails& details) {
1031 switch (type) {
1032 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
1033 OnWebContentsDestroyed(
1034 content::Source<content::WebContents>(source).ptr());
1035 break;
[email protected]bafe6cd2012-05-23 23:09:501036 case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1037 RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr();
1038 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1039 i != pending_widget_views_.end(); ++i) {
1040 if (host->GetView() == i->second) {
1041 pending_widget_views_.erase(i);
1042 break;
1043 }
1044 }
1045 break;
1046 }
[email protected]14392a52012-05-02 20:28:441047 default:
1048 NOTREACHED();
1049 }
1050}
1051
1052void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) {
1053 // Clear the opener if it has been closed.
1054 if (web_contents == opener_) {
1055 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
1056 content::Source<WebContents>(opener_));
1057 opener_ = NULL;
1058 }
1059}
1060
[email protected]b172aee2012-04-10 17:05:261061void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311062 observers_.AddObserver(observer);
1063}
1064
[email protected]b172aee2012-04-10 17:05:261065void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311066 observers_.RemoveObserver(observer);
1067}
1068
[email protected]b172aee2012-04-10 17:05:261069void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341070 if (delegate_)
1071 delegate_->ActivateContents(this);
1072}
1073
[email protected]b172aee2012-04-10 17:05:261074void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121075 if (delegate_)
1076 delegate_->DeactivateContents(this);
1077}
1078
[email protected]b172aee2012-04-10 17:05:261079void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481080 if (delegate_)
1081 delegate_->LostCapture();
1082}
1083
[email protected]b172aee2012-04-10 17:05:261084bool WebContentsImpl::PreHandleKeyboardEvent(
1085 const NativeWebKeyboardEvent& event,
1086 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481087 return delegate_ &&
1088 delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut);
1089}
1090
[email protected]b172aee2012-04-10 17:05:261091void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481092 if (delegate_)
1093 delegate_->HandleKeyboardEvent(event);
1094}
1095
[email protected]b172aee2012-04-10 17:05:261096void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431097 if (delegate_)
1098 delegate_->HandleMouseDown();
1099}
1100
[email protected]b172aee2012-04-10 17:05:261101void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481102 if (delegate_)
1103 delegate_->HandleMouseUp();
1104}
1105
[email protected]b172aee2012-04-10 17:05:261106void WebContentsImpl::HandleMouseActivate() {
[email protected]63954792011-07-11 04:17:481107 if (delegate_)
1108 delegate_->HandleMouseActivate();
1109}
1110
[email protected]b172aee2012-04-10 17:05:261111void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]8a5e0ca2011-08-25 06:30:471112 if (delegate_)
1113 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1114}
1115
[email protected]b172aee2012-04-10 17:05:261116bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381117 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121118}
1119
[email protected]a9c81f02012-06-01 00:15:441120void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1121 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371122 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441123 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371124 } else {
1125 GotResponseToLockMouseRequest(false);
1126 }
1127}
1128
[email protected]b172aee2012-04-10 17:05:261129void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371130 if (delegate_)
1131 delegate_->LostMouseLock();
1132}
1133
[email protected]bafe6cd2012-05-23 23:09:501134void WebContentsImpl::CreateNewWindow(
1135 int route_id,
1136 const ViewHostMsg_CreateWindow_Params& params) {
1137 if (delegate_ && !delegate_->ShouldCreateWebContents(
1138 this, route_id, params.window_container_type, params.frame_name,
1139 params.target_url)) {
1140 return;
1141 }
1142
1143 // We usually create the new window in the same BrowsingInstance (group of
1144 // script-related windows), by passing in the current SiteInstance. However,
1145 // if the opener is being suppressed, we create a new SiteInstance in its own
1146 // BrowsingInstance.
1147 scoped_refptr<SiteInstance> site_instance =
1148 params.opener_suppressed ?
1149 SiteInstance::Create(GetBrowserContext()) :
1150 GetSiteInstance();
1151
1152 // Create the new web contents. This will automatically create the new
1153 // WebContentsView. In the future, we may want to create the view separately.
1154 WebContentsImpl* new_contents =
1155 new WebContentsImpl(GetBrowserContext(),
1156 site_instance,
1157 route_id,
1158 this,
1159 params.opener_suppressed ? NULL : this,
1160 NULL);
1161 new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState());
1162
1163 if (!params.opener_suppressed) {
1164 content::WebContentsView* new_view = new_contents->GetView();
1165
1166 // TODO(brettw): It seems bogus that we have to call this function on the
1167 // newly created object and give it one of its own member variables.
1168 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1169
1170 // Save the created window associated with the route so we can show it
1171 // later.
1172 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1173 pending_contents_[route_id] = new_contents;
1174 }
1175
1176 if (delegate_) {
1177 delegate_->WebContentsCreated(
1178 this, params.opener_frame_id, params.target_url, new_contents);
1179 }
1180
1181 if (params.opener_suppressed) {
1182 // When the opener is suppressed, the original renderer cannot access the
1183 // new window. As a result, we need to show and navigate the window here.
1184 gfx::Rect initial_pos;
1185 AddNewContents(
1186 new_contents, params.disposition, initial_pos, params.user_gesture);
1187
1188 content::OpenURLParams open_params(params.target_url, content::Referrer(),
1189 CURRENT_TAB,
1190 content::PAGE_TRANSITION_LINK,
1191 true /* is_renderer_initiated */);
1192 new_contents->OpenURL(open_params);
1193 }
1194}
1195
1196void WebContentsImpl::CreateNewWidget(int route_id,
1197 WebKit::WebPopupType popup_type) {
1198 CreateNewWidget(route_id, false, popup_type);
1199}
1200
1201void WebContentsImpl::CreateNewFullscreenWidget(int route_id) {
1202 CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone);
1203}
1204
1205void WebContentsImpl::CreateNewWidget(int route_id,
1206 bool is_fullscreen,
1207 WebKit::WebPopupType popup_type) {
1208 content::RenderProcessHost* process = GetRenderProcessHost();
1209 RenderWidgetHostImpl* widget_host =
1210 new RenderWidgetHostImpl(this, process, route_id);
1211 RenderWidgetHostViewPort* widget_view =
1212 RenderWidgetHostViewPort::CreateViewForWidget(widget_host);
1213 if (!is_fullscreen) {
1214 // Popups should not get activated.
1215 widget_view->SetPopupType(popup_type);
1216 }
1217 // Save the created widget associated with the route so we can show it later.
1218 pending_widget_views_[route_id] = widget_view;
1219
1220#if defined(OS_MACOSX)
1221 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1222 // to allow it to survive the trip without being hosted.
1223 base::mac::NSObjectRetain(widget_view->GetNativeView());
1224#endif
1225}
1226
1227void WebContentsImpl::ShowCreatedWindow(int route_id,
1228 WindowOpenDisposition disposition,
1229 const gfx::Rect& initial_pos,
1230 bool user_gesture) {
1231 WebContentsImpl* contents = GetCreatedWindow(route_id);
1232 if (contents)
1233 AddNewContents(contents, disposition, initial_pos, user_gesture);
1234}
1235
1236void WebContentsImpl::ShowCreatedWidget(int route_id,
1237 const gfx::Rect& initial_pos) {
1238 ShowCreatedWidget(route_id, false, initial_pos);
1239}
1240
1241void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1242 ShowCreatedWidget(route_id, true, gfx::Rect());
1243}
1244
1245void WebContentsImpl::ShowCreatedWidget(int route_id,
1246 bool is_fullscreen,
1247 const gfx::Rect& initial_pos) {
1248 if (delegate_)
1249 delegate_->RenderWidgetShowing();
1250
1251 RenderWidgetHostViewPort* widget_host_view =
1252 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1253 if (!widget_host_view)
1254 return;
1255 if (is_fullscreen) {
1256 widget_host_view->InitAsFullscreen(GetRenderWidgetHostView());
1257 } else {
1258 widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos);
1259 }
[email protected]89054502012-06-03 10:29:241260
1261 RenderWidgetHostImpl* render_widget_host_impl =
1262 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1263 render_widget_host_impl->Init();
1264 // Only allow privileged mouse lock for fullscreen render widget, which is
1265 // used to implement Pepper Flash fullscreen.
1266 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501267
1268#if defined(OS_MACOSX)
1269 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1270 // properly embedded (or purposefully ignored) we can release the retain we
1271 // took in CreateNewWidget().
1272 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1273#endif
1274}
1275
1276WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1277 PendingContents::iterator iter = pending_contents_.find(route_id);
1278
1279 // Certain systems can block the creation of new windows. If we didn't succeed
1280 // in creating one, just return NULL.
1281 if (iter == pending_contents_.end()) {
1282 return NULL;
1283 }
1284
1285 WebContentsImpl* new_contents = iter->second;
1286 pending_contents_.erase(route_id);
1287
1288 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1289 !new_contents->GetRenderViewHost()->GetView())
1290 return NULL;
1291
1292 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1293 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1294 return new_contents;
1295}
1296
1297RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1298 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1299 if (iter == pending_widget_views_.end()) {
1300 DCHECK(false);
1301 return NULL;
1302 }
1303
1304 RenderWidgetHostView* widget_host_view = iter->second;
1305 pending_widget_views_.erase(route_id);
1306
1307 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1308 if (!widget_host->GetProcess()->HasConnection()) {
1309 // The view has gone away or the renderer crashed. Nothing to do.
1310 return NULL;
1311 }
1312
1313 return widget_host_view;
1314}
1315
1316void WebContentsImpl::ShowContextMenu(
1317 const content::ContextMenuParams& params) {
1318 // Allow WebContentsDelegates to handle the context menu operation first.
1319 if (delegate_ && delegate_->HandleContextMenu(params))
1320 return;
1321
[email protected]5a3bdf52012-05-24 15:12:571322 render_view_host_delegate_view_->ShowContextMenu(params);
[email protected]bafe6cd2012-05-23 23:09:501323}
1324
[email protected]b172aee2012-04-10 17:05:261325void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]bcd2815602012-01-14 18:17:231326 preferred_size_ = pref_size;
[email protected]0548c5352011-09-07 00:33:331327 if (delegate_)
1328 delegate_->UpdatePreferredSize(this, pref_size);
1329}
1330
[email protected]b172aee2012-04-10 17:05:261331void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341332 if (delegate_)
1333 delegate_->ResizeDueToAutoResize(this, new_size);
1334}
1335
[email protected]b172aee2012-04-10 17:05:261336WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201337 if (!delegate_)
1338 return NULL;
[email protected]00c37fc2011-08-02 00:22:501339
[email protected]e5d549d2011-12-28 01:29:201340 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
1341 // Notify observers.
1342 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1343 DidOpenURL(params.url, params.referrer,
1344 params.disposition, params.transition));
1345 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341346}
1347
[email protected]b172aee2012-04-10 17:05:261348bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501349 NavigationController::ReloadType reload_type) {
[email protected]022af742011-12-28 18:37:251350 return NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231351 *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()),
[email protected]022af742011-12-28 18:37:251352 reload_type);
[email protected]876bc832010-09-07 16:29:541353}
[email protected]96d185d2009-04-24 03:28:541354
[email protected]ba45bfd2012-05-22 21:51:441355void WebContentsImpl::RenderViewForInterstitialPageCreated(
1356 content::RenderViewHost* render_view_host) {
1357 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1358 RenderViewForInterstitialPageCreated(render_view_host));
1359}
1360
[email protected]b172aee2012-04-10 17:05:261361bool WebContentsImpl::NavigateToEntry(
[email protected]10f417c52011-12-28 21:04:231362 const NavigationEntryImpl& entry,
[email protected]c5eed492012-01-04 17:07:501363 NavigationController::ReloadType reload_type) {
[email protected]19e81142011-10-03 16:19:401364 // The renderer will reject IPC messages with URLs longer than
1365 // this limit, so don't attempt to navigate with a longer URL.
[email protected]36fc0392011-12-25 03:59:511366 if (entry.GetURL().spec().size() > content::kMaxURLChars)
[email protected]19e81142011-10-03 16:19:401367 return false;
1368
[email protected]9f76c1e2012-03-05 15:15:581369 RenderViewHostImpl* dest_render_view_host =
1370 static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry));
[email protected]ffc906f2011-10-04 22:55:401371 if (!dest_render_view_host)
1372 return false; // Unable to create the desired render view host.
1373
[email protected]80a8fad2011-01-29 04:02:381374 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071375 // Double check that here.
[email protected]9f76c1e2012-03-05 15:15:581376 int enabled_bindings = dest_render_view_host->GetEnabledBindings();
[email protected]863f70a2012-01-27 02:05:501377 WebUIControllerFactory* factory =
1378 content::GetContentClient()->browser()->GetWebUIControllerFactory();
[email protected]24e18252012-04-16 21:26:271379 bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI();
[email protected]863f70a2012-01-27 02:05:501380 bool is_allowed_in_web_ui_renderer =
1381 factory &&
[email protected]24e18252012-04-16 21:26:271382 factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(),
1383 data_urls_allowed);
[email protected]1684454a2012-03-24 04:12:231384 if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) &&
1385 !is_allowed_in_web_ui_renderer) {
[email protected]24e18252012-04-16 21:26:271386 // Log the URL to help us diagnose any future failures of this CHECK.
[email protected]1684454a2012-03-24 04:12:231387 content::GetContentClient()->SetActiveURL(entry.GetURL());
1388 CHECK(0);
1389 }
[email protected]54ec6472010-04-09 19:39:581390
[email protected]96d185d2009-04-24 03:28:541391 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]0e12d7d2011-12-01 16:21:441392 DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry(
[email protected]151a63d2011-12-20 22:32:521393 GetRenderViewHost(),
[email protected]0e12d7d2011-12-01 16:21:441394 dest_render_view_host,
[email protected]36fc0392011-12-25 03:59:511395 entry.GetURL());
[email protected]96d185d2009-04-24 03:28:541396
1397 // Used for page load time metrics.
1398 current_load_start_ = base::TimeTicks::Now();
1399
1400 // Navigate in the desired RenderViewHost.
[email protected]7900bfdb2012-05-24 19:31:241401 std::string embedder_channel_name;
1402 int embedder_container_id;
1403 GetBrowserPluginEmbedderInfo(dest_render_view_host,
1404 &embedder_channel_name,
1405 &embedder_container_id);
[email protected]056de2d2009-06-26 16:41:341406 ViewMsg_Navigate_Params navigate_params;
[email protected]dd11de52011-11-03 22:54:271407 MakeNavigateParams(entry, controller_, delegate_, reload_type,
[email protected]7900bfdb2012-05-24 19:31:241408 embedder_channel_name,
1409 embedder_container_id,
[email protected]6c6b02d2011-09-02 03:36:471410 &navigate_params);
[email protected]056de2d2009-06-26 16:41:341411 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541412
[email protected]36fc0392011-12-25 03:59:511413 if (entry.GetPageID() == -1) {
[email protected]96d185d2009-04-24 03:28:541414 // HACK!! This code suppresses javascript: URLs from being added to
1415 // session history, which is what we want to do for javascript: URLs that
1416 // do not generate content. What we really need is a message from the
1417 // renderer telling us that a new page was not created. The same message
1418 // could be used for mailto: URLs and the like.
[email protected]36fc0392011-12-25 03:59:511419 if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme))
[email protected]96d185d2009-04-24 03:28:541420 return false;
1421 }
1422
[email protected]3c9e1872010-11-18 16:17:491423 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:251424 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]b375c5d2011-05-03 21:15:041425 observers_,
[email protected]36fc0392011-12-25 03:59:511426 NavigateToPendingEntry(entry.GetURL(), reload_type));
[email protected]96d185d2009-04-24 03:28:541427
[email protected]09b29342011-06-24 19:18:481428 if (delegate_)
1429 delegate_->DidNavigateToPendingEntry(this);
1430
[email protected]d5f942ba2008-09-26 19:30:341431 return true;
1432}
1433
[email protected]b172aee2012-04-10 17:05:261434void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331435 const SiteInstance* site_instance,
1436 int history_length,
1437 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411438 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1439 // navigations. Callers should ensure that this is the case.
[email protected]9e1ad4b2011-08-14 16:49:191440 if (render_manager_.pending_render_view_host()) {
1441 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141442 return;
[email protected]9e1ad4b2011-08-14 16:49:191443 }
[email protected]9f76c1e2012-03-05 15:15:581444 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191445 if (!rvh) {
1446 NOTREACHED();
1447 return;
1448 }
[email protected]9f76c1e2012-03-05 15:15:581449 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191450 NOTREACHED();
1451 return;
1452 }
[email protected]9f76c1e2012-03-05 15:15:581453 rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(),
[email protected]9e1ad4b2011-08-14 16:49:191454 history_length,
1455 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141456}
1457
[email protected]b172aee2012-04-10 17:05:261458void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271459 if (ShowingInterstitialPage()) {
[email protected]7e383692009-06-12 19:14:541460 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1461 return;
1462 }
[email protected]9f76c1e2012-03-05 15:15:581463 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541464}
1465
[email protected]b172aee2012-04-10 17:05:261466bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271467 return render_manager_.interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541468}
1469
[email protected]b172aee2012-04-10 17:05:261470InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]0bfbf882011-12-22 18:19:271471 return render_manager_.interstitial_page();
[email protected]686493142011-07-15 21:47:221472}
1473
[email protected]b172aee2012-04-10 17:05:261474bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161475 // WebKit creates Document object when MIME type is application/xhtml+xml,
1476 // so we also support this MIME type.
1477 return contents_mime_type_ == "text/html" ||
1478 contents_mime_type_ == "text/xml" ||
1479 contents_mime_type_ == "application/xhtml+xml" ||
1480 contents_mime_type_ == "text/plain" ||
1481 contents_mime_type_ == "text/css" ||
1482 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1483}
1484
[email protected]b172aee2012-04-10 17:05:261485void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591486 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161487 if (!IsSavable()) {
[email protected]731809e2012-02-15 21:56:481488 download_stats::RecordDownloadSource(
1489 download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]20b433a2012-05-15 21:23:461490 SaveURL(GetURL(), content::Referrer(), true);
[email protected]27678b2a2012-02-04 22:09:141491 return;
[email protected]c7dd2f62011-07-18 15:57:591492 }
1493
1494 Stop();
1495
1496 // Create the save package and possibly prompt the user for the name to save
1497 // the page as. The user prompt is an asynchronous operation that runs on
1498 // another thread.
1499 save_package_ = new SavePackage(this);
1500 save_package_->GetSaveInfo();
1501}
1502
1503// Used in automated testing to bypass prompting the user for file names.
1504// Instead, the names and paths are hard coded rather than running them through
1505// file name sanitation and extension / mime checking.
[email protected]b172aee2012-04-10 17:05:261506bool WebContentsImpl::SavePage(const FilePath& main_file,
1507 const FilePath& dir_path,
1508 content::SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591509 // Stop the page from navigating.
1510 Stop();
1511
1512 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]6474b112012-05-04 19:35:271513 return save_package_->Init(content::SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591514}
1515
[email protected]b172aee2012-04-10 17:05:261516void WebContentsImpl::GenerateMHTML(
[email protected]aa4f3972012-03-01 18:12:121517 const FilePath& file,
1518 const base::Callback<void(const FilePath&, int64)>& callback) {
1519 MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback);
1520}
1521
[email protected]b172aee2012-04-10 17:05:261522bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]10f417c52011-12-28 21:04:231523 NavigationEntryImpl* active_entry =
1524 NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry());
[email protected]420ae012009-04-24 05:16:321525 return (active_entry != NULL &&
1526 active_entry->site_instance() == GetSiteInstance() &&
[email protected]36fc0392011-12-25 03:59:511527 active_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321528}
1529
[email protected]b172aee2012-04-10 17:05:261530const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271531 return contents_mime_type_;
1532}
1533
[email protected]b172aee2012-04-10 17:05:261534bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271535 return notify_disconnection_;
1536}
1537
[email protected]b172aee2012-04-10 17:05:261538void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311539 SetEncoding(encoding);
[email protected]9f76c1e2012-03-05 15:15:581540 GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding(
1541 GetRenderViewHost()->GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161542}
1543
[email protected]b172aee2012-04-10 17:05:261544void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311545 encoding_.clear();
[email protected]9f76c1e2012-03-05 15:15:581546 GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault(
1547 GetRenderViewHost()->GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161548}
1549
[email protected]b172aee2012-04-10 17:05:261550content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271551 return &renderer_preferences_;
1552}
1553
[email protected]b172aee2012-04-10 17:05:261554void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) {
[email protected]0bfbf882011-12-22 18:19:271555 new_tab_start_time_ = time;
1556}
1557
[email protected]b172aee2012-04-10 17:05:261558base::TimeTicks WebContentsImpl::GetNewTabStartTime() const {
[email protected]0bfbf882011-12-22 18:19:271559 return new_tab_start_time_;
1560}
1561
[email protected]e35ccd52012-05-23 16:22:471562void WebContentsImpl::Close() {
1563 Close(GetRenderViewHost());
1564}
1565
[email protected]b172aee2012-04-10 17:05:261566void WebContentsImpl::OnCloseStarted() {
[email protected]3bbacc5b2012-04-17 17:46:151567 if (close_start_time_.is_null())
1568 close_start_time_ = base::TimeTicks::Now();
[email protected]7ab1e7d62009-10-14 23:32:011569}
1570
[email protected]b172aee2012-04-10 17:05:261571bool WebContentsImpl::ShouldAcceptDragAndDrop() const {
[email protected]46624bf2010-06-09 16:04:191572#if defined(OS_CHROMEOS)
1573 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1574 // See http://crosbug.com/2413
[email protected]6934a702011-12-20 00:04:511575 if (delegate_ && delegate_->IsPopupOrPanel(this))
[email protected]b83af492010-10-09 03:21:201576 return false;
1577 return true;
[email protected]46624bf2010-06-09 16:04:191578#else
1579 return true;
1580#endif
1581}
1582
[email protected]b172aee2012-04-10 17:05:261583void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521584 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581585 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511586 if (delegate_)
1587 delegate_->DragEnded();
[email protected]7813bd72011-02-05 02:19:341588}
1589
[email protected]e35ccd52012-05-23 16:22:471590void WebContentsImpl::UserGestureDone() {
1591 OnUserGesture();
1592}
1593
[email protected]b172aee2012-04-10 17:05:261594void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271595 closed_by_user_gesture_ = value;
1596}
1597
[email protected]b172aee2012-04-10 17:05:261598bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271599 return closed_by_user_gesture_;
1600}
1601
[email protected]b172aee2012-04-10 17:05:261602double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051603 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561604 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251605 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171606 return 0;
[email protected]b75b8292010-10-01 07:28:251607
1608 double zoom_level;
1609 if (temporary_zoom_settings_) {
1610 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581611 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251612 } else {
[email protected]2ae88d12011-10-14 09:11:191613 GURL url;
[email protected]10f417c52011-12-28 21:04:231614 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]2ae88d12011-10-14 09:11:191615 // Since zoom map is updated using rewritten URL, use rewritten URL
1616 // to get the zoom level.
[email protected]36fc0392011-12-25 03:59:511617 url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL();
[email protected]2ae88d12011-10-14 09:11:191618 zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251619 }
[email protected]d0b8d092010-10-25 04:05:171620 return zoom_level;
1621}
[email protected]b75b8292010-10-01 07:28:251622
[email protected]b172aee2012-04-10 17:05:261623int WebContentsImpl::GetZoomPercent(bool* enable_increment,
1624 bool* enable_decrement) {
[email protected]d0b8d092010-10-25 04:05:171625 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011626 // Calculate the zoom percent from the factor. Round up to the nearest whole
1627 // number.
[email protected]b75b8292010-10-01 07:28:251628 int percent = static_cast<int>(
[email protected]0f083402011-11-22 02:59:011629 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251630 *enable_decrement = percent > minimum_zoom_percent_;
1631 *enable_increment = percent < maximum_zoom_percent_;
1632 return percent;
1633}
1634
[email protected]b172aee2012-04-10 17:05:261635void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501636 if (!delegate_)
1637 return;
1638
[email protected]10f417c52011-12-28 21:04:231639 NavigationEntry* active_entry = GetController().GetActiveEntry();
[email protected]1788e772010-12-15 16:40:501640 if (!active_entry)
1641 return;
1642
[email protected]36fc0392011-12-25 03:59:511643 delegate_->ViewSourceForTab(this, active_entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121644}
1645
[email protected]b172aee2012-04-10 17:05:261646void WebContentsImpl::ViewFrameSource(const GURL& url,
1647 const std::string& content_state) {
[email protected]932b7a12011-03-09 12:50:271648 if (!delegate_)
1649 return;
1650
1651 delegate_->ViewSourceForFrame(this, url, content_state);
1652}
1653
[email protected]b172aee2012-04-10 17:05:261654int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271655 return minimum_zoom_percent_;
1656}
1657
[email protected]b172aee2012-04-10 17:05:261658int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271659 return maximum_zoom_percent_;
1660}
1661
[email protected]b172aee2012-04-10 17:05:261662gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]bcd2815602012-01-14 18:17:231663 return preferred_size_;
1664}
1665
[email protected]b172aee2012-04-10 17:05:261666int WebContentsImpl::GetContentRestrictions() const {
[email protected]0bfbf882011-12-22 18:19:271667 return content_restrictions_;
1668}
1669
[email protected]b172aee2012-04-10 17:05:261670WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() {
[email protected]863f70a2012-01-27 02:05:501671 WebUIControllerFactory* factory =
1672 content::GetContentClient()->browser()->GetWebUIControllerFactory();
1673 if (!factory)
1674 return WebUI::kNoWebUI;
1675 return factory->GetWebUIType(GetBrowserContext(), GetURL());
[email protected]0bfbf882011-12-22 18:19:271676}
1677
[email protected]b172aee2012-04-10 17:05:261678content::WebUI* WebContentsImpl::GetWebUIForCurrentState() {
[email protected]0bfbf882011-12-22 18:19:271679 // When there is a pending navigation entry, we want to use the pending WebUI
1680 // that goes along with it to control the basic flags. For example, we want to
1681 // show the pending URL in the URL bar, so we want the display_url flag to
1682 // be from the pending entry.
1683 //
1684 // The confusion comes because there are multiple possibilities for the
1685 // initial load in a tab as a side effect of the way the RenderViewHostManager
1686 // works.
1687 //
1688 // - For the very first tab the load looks "normal". The new tab Web UI is
1689 // the pending one, and we want it to apply here.
1690 //
1691 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1692 // get switched to the one previously associated with the new tab pages.
1693 // This switching will cause the manager to commit the RVH/WebUI. So we'll
1694 // have a committed Web UI in this case.
1695 //
1696 // This condition handles all of these cases:
1697 //
1698 // - First load in first tab: no committed nav entry + pending nav entry +
1699 // pending dom ui:
1700 // -> Use pending Web UI if any.
1701 //
1702 // - First load in second tab: no committed nav entry + pending nav entry +
1703 // no pending Web UI:
1704 // -> Use the committed Web UI if any.
1705 //
1706 // - Second navigation in any tab: committed nav entry + pending nav entry:
1707 // -> Use pending Web UI if any.
1708 //
1709 // - Normal state with no load: committed nav entry + no pending nav entry:
1710 // -> Use committed Web UI.
[email protected]022af742011-12-28 18:37:251711 if (controller_.GetPendingEntry() &&
[email protected]0bfbf882011-12-22 18:19:271712 (controller_.GetLastCommittedEntry() ||
1713 render_manager_.pending_web_ui()))
1714 return render_manager_.pending_web_ui();
1715 return render_manager_.web_ui();
1716}
1717
[email protected]b172aee2012-04-10 17:05:261718bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271719 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581720 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271721}
1722
[email protected]b172aee2012-04-10 17:05:261723bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441724 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501725}
1726
[email protected]b172aee2012-04-10 17:05:261727void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:321728 SkColor color) {
[email protected]da8543762012-03-20 08:52:201729 GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse(
1730 GetRenderViewHost()->GetRoutingID(), color_chooser_id, color));
1731}
1732
[email protected]b172aee2012-04-10 17:05:261733void WebContentsImpl::DidEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:201734 GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser(
1735 GetRenderViewHost()->GetRoutingID(), color_chooser_id));
1736 if (delegate_)
1737 delegate_->DidEndColorChooser();
1738 color_chooser_ = NULL;
1739}
1740
[email protected]b172aee2012-04-10 17:05:261741bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]01ec4ec2012-01-18 04:13:471742 content::WebUI* web_ui = GetWebUIForCurrentState();
[email protected]0bfbf882011-12-22 18:19:271743 if (web_ui)
[email protected]c63cedf22012-01-17 18:42:221744 return web_ui->ShouldFocusLocationBarByDefault();
[email protected]10f417c52011-12-28 21:04:231745 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]82114f52012-03-20 22:53:411746 return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL));
[email protected]0bfbf882011-12-22 18:19:271747}
1748
[email protected]b172aee2012-04-10 17:05:261749void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:271750 if (delegate_)
1751 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:211752}
1753
[email protected]3a3b75a2012-06-01 08:38:361754void WebContentsImpl::OnRegisterIntentService(
1755 const webkit_glue::WebIntentServiceData& data,
1756 bool user_gesture) {
1757 delegate_->RegisterIntentHandler(this, data, user_gesture);
[email protected]63c239322011-10-31 23:56:301758}
1759
[email protected]b172aee2012-04-10 17:05:261760void WebContentsImpl::OnWebIntentDispatch(
1761 const webkit_glue::WebIntentData& intent,
1762 int intent_id) {
[email protected]0d9989d2011-12-21 20:26:001763 WebIntentsDispatcherImpl* intents_dispatcher =
1764 new WebIntentsDispatcherImpl(this, intent, intent_id);
1765 delegate_->WebIntentDispatch(this, intents_dispatcher);
[email protected]63c239322011-10-31 23:56:301766}
1767
[email protected]54047eb52012-05-08 21:45:571768void WebContentsImpl::DidStartProvisionalLoadForFrame(
1769 content::RenderViewHost* render_view_host,
1770 int64 frame_id,
1771 bool is_main_frame,
1772 const GURL& opener_url,
1773 const GURL& url) {
[email protected]285f4bb82012-04-17 15:57:281774 bool is_error_page = (url.spec() == content::kUnreachableWebDataURL);
[email protected]724159a2010-12-30 01:11:181775 GURL validated_url(url);
[email protected]6b7cd8f2012-03-21 21:02:451776 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571777 content::RenderProcessHost* render_process_host =
1778 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161779 RenderViewHostImpl::FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581780 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571781 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451782 false,
[email protected]9f76c1e2012-03-05 15:15:581783 &validated_url);
[email protected]97d402f32012-06-01 02:55:161784 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451785 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571786 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451787 true,
1788 &validated_opener_url);
[email protected]724159a2010-12-30 01:11:181789
[email protected]0d60f0192011-04-14 12:40:101790 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:251791 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101792 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
[email protected]54047eb52012-05-08 21:45:571793 validated_url, is_error_page, render_view_host));
[email protected]0d60f0192011-04-14 12:40:101794
[email protected]724159a2010-12-30 01:11:181795 if (is_main_frame) {
[email protected]4850a7f2011-03-08 23:36:591796 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251797 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451798 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]ef16c3e2012-05-16 22:13:461799 validated_opener_url,
1800 render_view_host));
[email protected]724159a2010-12-30 01:11:181801 }
1802}
1803
[email protected]54047eb52012-05-08 21:45:571804void WebContentsImpl::DidRedirectProvisionalLoad(
1805 content::RenderViewHost* render_view_host,
1806 int32 page_id,
1807 const GURL& opener_url,
1808 const GURL& source_url,
1809 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491810 // TODO(creis): Remove this method and have the pre-rendering code listen to
1811 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1812 // instead. See http://crbug.com/78512.
[email protected]6b7cd8f2012-03-21 21:02:451813 GURL validated_source_url(source_url);
1814 GURL validated_target_url(target_url);
1815 GURL validated_opener_url(opener_url);
[email protected]54047eb52012-05-08 21:45:571816 content::RenderProcessHost* render_process_host =
1817 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161818 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451819 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571820 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451821 false,
1822 &validated_source_url);
[email protected]97d402f32012-06-01 02:55:161823 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451824 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571825 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451826 false,
1827 &validated_target_url);
[email protected]97d402f32012-06-01 02:55:161828 RenderViewHostImpl::FilterURL(
[email protected]6b7cd8f2012-03-21 21:02:451829 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571830 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451831 true,
1832 &validated_opener_url);
[email protected]10f417c52011-12-28 21:04:231833 NavigationEntry* entry;
[email protected]54047eb52012-05-08 21:45:571834 if (page_id == -1) {
[email protected]022af742011-12-28 18:37:251835 entry = controller_.GetPendingEntry();
[email protected]54047eb52012-05-08 21:45:571836 } else {
1837 entry = controller_.GetEntryWithPageID(render_view_host->GetSiteInstance(),
1838 page_id);
1839 }
[email protected]6b7cd8f2012-03-21 21:02:451840 if (!entry || entry->GetURL() != validated_source_url)
[email protected]724159a2010-12-30 01:11:181841 return;
[email protected]e7d50892011-01-19 21:47:381842
[email protected]4850a7f2011-03-08 23:36:591843 // Notify observers about the provisional change in the main frame URL.
[email protected]d8c660432011-12-22 20:51:251844 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]6b7cd8f2012-03-21 21:02:451845 ProvisionalChangeToMainFrameUrl(validated_target_url,
[email protected]ef16c3e2012-05-16 22:13:461846 validated_opener_url,
1847 render_view_host));
[email protected]724159a2010-12-30 01:11:181848}
1849
[email protected]54047eb52012-05-08 21:45:571850void WebContentsImpl::DidFailProvisionalLoadWithError(
1851 content::RenderViewHost* render_view_host,
[email protected]d7b175e2011-10-11 15:31:581852 const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) {
1853 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
1854 << ", error_code: " << params.error_code
1855 << ", error_description: " << params.error_description
1856 << ", is_main_frame: " << params.is_main_frame
1857 << ", showing_repost_interstitial: " <<
1858 params.showing_repost_interstitial
1859 << ", frame_id: " << params.frame_id;
1860 GURL validated_url(params.url);
[email protected]54047eb52012-05-08 21:45:571861 content::RenderProcessHost* render_process_host =
1862 render_view_host->GetProcess();
[email protected]97d402f32012-06-01 02:55:161863 RenderViewHostImpl::FilterURL(
[email protected]9f76c1e2012-03-05 15:15:581864 ChildProcessSecurityPolicyImpl::GetInstance(),
[email protected]54047eb52012-05-08 21:45:571865 render_process_host->GetID(),
[email protected]6b7cd8f2012-03-21 21:02:451866 false,
[email protected]9f76c1e2012-03-05 15:15:581867 &validated_url);
[email protected]724159a2010-12-30 01:11:181868
[email protected]d7b175e2011-10-11 15:31:581869 if (net::ERR_ABORTED == params.error_code) {
[email protected]724159a2010-12-30 01:11:181870 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1871 // This means that the interstitial won't be torn down properly, which is
1872 // bad. But if we have an interstitial, go back to another tab type, and
1873 // then load the same interstitial again, we could end up getting the first
1874 // interstitial's "failed" message (as a result of the cancel) when we're on
1875 // the second one.
1876 //
1877 // We can't tell this apart, so we think we're tearing down the current page
1878 // which will cause a crash later one. There is also some code in
1879 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1880 // out because of this problem.
1881 //
1882 // http://code.google.com/p/chromium/issues/detail?id=2855
1883 // Because this will not tear down the interstitial properly, if "back" is
1884 // back to another tab type, the interstitial will still be somewhat alive
1885 // in the previous tab type. If you navigate somewhere that activates the
1886 // tab with the interstitial again, you'll see a flash before the new load
1887 // commits of the interstitial page.
[email protected]0bfbf882011-12-22 18:19:271888 if (ShowingInterstitialPage()) {
[email protected]724159a2010-12-30 01:11:181889 LOG(WARNING) << "Discarding message during interstitial.";
1890 return;
1891 }
1892
[email protected]02102f82011-06-13 20:37:021893 // Discard our pending entry if the load canceled (e.g. if we decided to
1894 // download the file instead of load it). We do not verify that the URL
1895 // being canceled matches the pending entry's URL because they will not
1896 // match if a redirect occurred (in which case we do not want to leave a
1897 // stale redirect URL showing). This means that we also cancel the pending
1898 // entry if the user started a new navigation. As a result, the navigation
1899 // controller may not remember that a load is in progress, but the
1900 // navigation will still commit even if there is no pending entry.
[email protected]022af742011-12-28 18:37:251901 if (controller_.GetPendingEntry())
[email protected]c95fa8b2011-04-28 20:26:161902 DidCancelLoading();
[email protected]724159a2010-12-30 01:11:181903
[email protected]54047eb52012-05-08 21:45:571904 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
[email protected]724159a2010-12-30 01:11:181905 }
1906
[email protected]d8c660432011-12-22 20:51:251907 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]d7b175e2011-10-11 15:31:581908 observers_,
1909 DidFailProvisionalLoad(params.frame_id,
1910 params.is_main_frame,
1911 validated_url,
1912 params.error_code,
[email protected]ef16c3e2012-05-16 22:13:461913 params.error_description,
1914 render_view_host));
[email protected]724159a2010-12-30 01:11:181915}
1916
[email protected]b172aee2012-04-10 17:05:261917void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:181918 const GURL& url,
[email protected]70435962011-08-02 20:13:281919 const std::string& security_info,
1920 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:181921 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:281922 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:191923 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181924 cache.Increment();
1925
1926 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:081927 int cert_id = 0;
1928 net::CertStatus cert_status = 0;
1929 int security_bits = -1;
1930 int connection_status = 0;
[email protected]35be7ec2012-02-12 20:42:511931 content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
1932 &security_bits, &connection_status);
[email protected]f3b1a082011-11-18 00:34:301933 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(),
[email protected]6d6cfb3a2012-05-23 22:53:181934 cert_id, cert_status, http_method,
1935 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:181936
[email protected]ad50def52011-10-19 23:17:071937 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:271938 content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE,
[email protected]c5eed492012-01-04 17:07:501939 content::Source<NavigationController>(&controller_),
[email protected]6c2381d2011-10-19 02:52:531940 content::Details<LoadFromMemoryCacheDetails>(&details));
[email protected]724159a2010-12-30 01:11:181941}
1942
[email protected]b172aee2012-04-10 17:05:261943void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]7f6f44c2011-12-14 13:23:381944 content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:181945 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201946 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181947}
1948
[email protected]b172aee2012-04-10 17:05:261949void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021950 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231951 LOG(INFO) << security_origin << " ran insecure content from "
1952 << target_url.possibly_invalid_spec();
[email protected]7f6f44c2011-12-14 13:23:381953 content::RecordAction(UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:411954 if (EndsWith(security_origin, kDotGoogleDotCom, false))
1955 content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:181956 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:411957 displayed_insecure_content_ = true;
[email protected]cdcb1dee2012-01-04 00:46:201958 SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl());
[email protected]724159a2010-12-30 01:11:181959}
1960
[email protected]b172aee2012-04-10 17:05:261961void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) {
[email protected]724159a2010-12-30 01:11:181962 controller_.DocumentLoadedInFrame();
[email protected]d8c660432011-12-22 20:51:251963 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101964 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181965}
1966
[email protected]b172aee2012-04-10 17:05:261967void WebContentsImpl::OnDidFinishLoad(
[email protected]1a55c5be2011-11-29 11:36:311968 int64 frame_id,
1969 const GURL& validated_url,
1970 bool is_main_frame) {
[email protected]d8c660432011-12-22 20:51:251971 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311972 DidFinishLoad(frame_id, validated_url, is_main_frame));
1973}
1974
[email protected]b172aee2012-04-10 17:05:261975void WebContentsImpl::OnDidFailLoadWithError(
1976 int64 frame_id,
1977 const GURL& validated_url,
1978 bool is_main_frame,
1979 int error_code,
1980 const string16& error_description) {
[email protected]d8c660432011-12-22 20:51:251981 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1a55c5be2011-11-29 11:36:311982 DidFailLoad(frame_id, validated_url, is_main_frame,
1983 error_code, error_description));
[email protected]724159a2010-12-30 01:11:181984}
1985
[email protected]b172aee2012-04-10 17:05:261986void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) {
[email protected]0bfbf882011-12-22 18:19:271987 content_restrictions_ = restrictions;
1988 delegate_->ContentRestrictionsChanged(this);
[email protected]c8f73ab2011-01-22 00:05:171989}
1990
[email protected]b172aee2012-04-10 17:05:261991void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]216813952011-05-19 22:21:261992 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
[email protected]10f417c52011-12-28 21:04:231993 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry(
[email protected]022af742011-12-28 18:37:251994 controller_.GetEntryAtOffset(offset));
[email protected]216813952011-05-19 22:21:261995 if (!entry)
1996 return;
1997 // Note that we don't call NavigationController::GotToOffset() as we don't
1998 // want to create a pending navigation entry (it might end up lingering
1999 // http://crbug.com/51680).
[email protected]022af742011-12-28 18:37:252000 entry->SetTransitionType(
[email protected]2905f742011-10-13 03:51:582001 content::PageTransitionFromInt(
[email protected]36fc0392011-12-25 03:59:512002 entry->GetTransitionType() |
[email protected]2905f742011-10-13 03:51:582003 content::PAGE_TRANSITION_FORWARD_BACK));
[email protected]d202a7c2012-01-04 07:53:472004 NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD);
[email protected]a13cc362011-07-28 21:29:572005
2006 // If the entry is being restored and doesn't have a SiteInstance yet, fill
2007 // it in now that we know. This allows us to find the entry when it commits.
2008 if (!entry->site_instance() &&
[email protected]10f417c52011-12-28 21:04:232009 entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) {
[email protected]b6583592012-01-25 19:52:332010 entry->set_site_instance(
2011 static_cast<SiteInstanceImpl*>(GetPendingSiteInstance()));
[email protected]a13cc362011-07-28 21:29:572012 }
[email protected]216813952011-05-19 22:21:262013 }
2014}
2015
[email protected]b172aee2012-04-10 17:05:262016void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2017 int maximum_percent,
2018 bool remember) {
[email protected]216813952011-05-19 22:21:262019 minimum_zoom_percent_ = minimum_percent;
2020 maximum_zoom_percent_ = maximum_percent;
2021 temporary_zoom_settings_ = !remember;
2022}
2023
[email protected]20b433a2012-05-15 21:23:462024void WebContentsImpl::OnSaveURL(const GURL& url,
2025 const content::Referrer& referrer) {
[email protected]731809e2012-02-15 21:56:482026 download_stats::RecordDownloadSource(
2027 download_stats::INITIATED_BY_PEPPER_SAVE);
[email protected]e30d68d2012-02-09 00:06:262028 // Check if the URL to save matches the URL of the main frame. Since this
2029 // message originates from Pepper plugins, it may not be the case if the
2030 // plugin is an embedded element.
2031 GURL main_frame_url = GetURL();
2032 if (!main_frame_url.is_valid())
2033 return;
2034 bool is_main_frame = (url == main_frame_url);
[email protected]20b433a2012-05-15 21:23:462035 SaveURL(url, referrer, is_main_frame);
[email protected]0bfbf882011-12-22 18:19:272036}
2037
[email protected]b172aee2012-04-10 17:05:262038void WebContentsImpl::OnEnumerateDirectory(int request_id,
2039 const FilePath& path) {
[email protected]b9535422012-02-09 01:47:592040 ChildProcessSecurityPolicyImpl* policy =
2041 ChildProcessSecurityPolicyImpl::GetInstance();
2042 if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path))
2043 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212044}
2045
[email protected]b172aee2012-04-10 17:05:262046void WebContentsImpl::OnJSOutOfMemory() {
[email protected]6934a702011-12-20 00:04:512047 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202048}
2049
[email protected]b172aee2012-04-10 17:05:262050void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2051 const GURL& url,
[email protected]3a3b75a2012-06-01 08:38:362052 const string16& title,
2053 bool user_gesture) {
[email protected]b9535422012-02-09 01:47:592054 ChildProcessSecurityPolicyImpl* policy =
2055 ChildProcessSecurityPolicyImpl::GetInstance();
2056 if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol))
2057 return;
[email protected]3a3b75a2012-06-01 08:38:362058 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202059}
2060
[email protected]b172aee2012-04-10 17:05:262061void WebContentsImpl::OnFindReply(int request_id,
2062 int number_of_matches,
2063 const gfx::Rect& selection_rect,
2064 int active_match_ordinal,
2065 bool final_update) {
[email protected]6934a702011-12-20 00:04:512066 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2067 active_match_ordinal, final_update);
[email protected]4e6239c2011-09-23 00:11:002068 // Send a notification to the renderer that we are ready to receive more
2069 // results from the scoping effort of the Find operation. The FindInPage
2070 // scoping is asynchronous and periodically sends results back up to the
2071 // browser using IPC. In an effort to not spam the browser we have the
2072 // browser send an ACK for each FindReply message and have the renderer
2073 // queue up the latest status message while waiting for this ACK.
[email protected]9f76c1e2012-03-05 15:15:582074 GetRenderViewHostImpl()->Send(
2075 new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID()));
[email protected]b888919c2011-09-02 00:32:162076}
2077
[email protected]b172aee2012-04-10 17:05:262078void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]3fc07c52012-04-20 00:27:442079 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2080 PluginCrashed(plugin_path));
[email protected]d952a052011-09-06 18:42:452081}
2082
[email protected]b172aee2012-04-10 17:05:262083void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2084 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102085 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252086 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102087 AppCacheAccessed(manifest_url, blocked_by_policy));
2088}
2089
[email protected]b172aee2012-04-10 17:05:262090void WebContentsImpl::OnOpenColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322091 SkColor color) {
[email protected]da8543762012-03-20 08:52:202092 color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color);
2093}
2094
[email protected]b172aee2012-04-10 17:05:262095void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202096 if (color_chooser_ &&
2097 color_chooser_id == color_chooser_->identifier())
2098 color_chooser_->End();
2099}
2100
[email protected]b172aee2012-04-10 17:05:262101void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322102 SkColor color) {
[email protected]da8543762012-03-20 08:52:202103 if (color_chooser_ &&
2104 color_chooser_id == color_chooser_->identifier())
2105 color_chooser_->SetSelectedColor(color);
2106}
2107
[email protected]9f2a9d72012-04-16 16:02:222108void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2109 const FilePath& path,
2110 bool is_hung) {
[email protected]3fc07c52012-04-20 00:27:442111 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2112 PluginHungStatusChanged(plugin_child_id, path, is_hung));
[email protected]8be45842012-04-13 19:49:292113}
2114
[email protected]d0759f492012-04-19 22:50:502115// This exists for render views that don't have a WebUI, but do have WebUI
2116// bindings enabled.
2117void WebContentsImpl::OnWebUISend(const GURL& source_url,
2118 const std::string& name,
2119 const base::ListValue& args) {
2120 if (delegate_)
2121 delegate_->WebUISend(this, source_url, name, args);
2122}
2123
[email protected]96d185d2009-04-24 03:28:542124// Notifies the RenderWidgetHost instance about the fact that the page is
2125// loading, or done loading and calls the base implementation.
[email protected]b172aee2012-04-10 17:05:262126void WebContentsImpl::SetIsLoading(bool is_loading,
2127 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542128 if (is_loading == is_loading_)
2129 return;
2130
2131 if (!is_loading) {
[email protected]9c235f042011-08-10 22:28:212132 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16());
[email protected]96d185d2009-04-24 03:28:542133 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562134 upload_size_ = 0;
2135 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542136 }
2137
2138 render_manager_.SetIsLoading(is_loading);
2139
2140 is_loading_ = is_loading;
2141 waiting_for_response_ = is_loading;
2142
[email protected]6ebdc9b2010-09-27 16:55:572143 if (delegate_)
2144 delegate_->LoadingStateChanged(this);
[email protected]d9083482012-01-06 00:38:462145 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542146
[email protected]432115822011-07-10 15:52:272147 int type = is_loading ? content::NOTIFICATION_LOAD_START :
2148 content::NOTIFICATION_LOAD_STOP;
[email protected]ad50def52011-10-19 23:17:072149 content::NotificationDetails det = content::NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542150 if (details)
[email protected]6c2381d2011-10-19 02:52:532151 det = content::Details<LoadNotificationDetails>(details);
[email protected]ad50def52011-10-19 23:17:072152 content::NotificationService::current()->Notify(type,
[email protected]c5eed492012-01-04 17:07:502153 content::Source<NavigationController>(&controller_),
[email protected]96d185d2009-04-24 03:28:542154 det);
2155}
2156
[email protected]b172aee2012-04-10 17:05:262157void WebContentsImpl::DidNavigateMainFramePostCommit(
[email protected]8286f51a2011-05-31 17:39:132158 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322159 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:562160 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:382161 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442162 // that opened the window, as long as both renderers have the same
2163 // privileges.
[email protected]1fd1a502011-03-30 16:55:562164 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
[email protected]d2353452012-01-19 19:53:562165 WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL()));
[email protected]7ade2732011-02-10 00:13:582166 // web_ui might be NULL if the URL refers to a non-existent extension.
2167 if (web_ui) {
[email protected]d0980792011-02-13 19:41:402168 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]151a63d2011-12-20 22:32:522169 web_ui->RenderViewCreated(GetRenderViewHost());
[email protected]c2e74fe82009-09-03 17:57:442170 }
2171 }
[email protected]1fd1a502011-03-30 16:55:562172 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442173 }
2174
[email protected]4e697b042011-07-08 06:44:562175 if (details.is_navigation_to_different_page()) {
[email protected]420ae012009-04-24 05:16:322176 // Clear the status bubble. This is a workaround for a bug where WebKit
2177 // doesn't let us know that the cursor left an element during a
2178 // transition (this is also why the mouse cursor remains as a hand after
2179 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2180 // clear the bubble when a user navigates to a named anchor in the same
2181 // page.
[email protected]36fc0392011-12-25 03:59:512182 UpdateTargetURL(details.entry->GetPageID(), GURL());
[email protected]420ae012009-04-24 05:16:322183 }
2184
[email protected]a6e82fc2010-02-24 22:28:142185 if (!details.is_in_page) {
[email protected]f17a0ee2010-05-17 17:38:472186 // Once the main frame is navigated, we're no longer considered to have
2187 // displayed insecure content.
2188 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172189 }
[email protected]ce5c4502009-05-06 16:46:112190
[email protected]3c9e1872010-11-18 16:17:492191 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252192 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042193 DidNavigateMainFrame(details, params));
[email protected]420ae012009-04-24 05:16:322194}
2195
[email protected]b172aee2012-04-10 17:05:262196void WebContentsImpl::DidNavigateAnyFramePostCommit(
[email protected]420ae012009-04-24 05:16:322197 RenderViewHost* render_view_host,
[email protected]8286f51a2011-05-31 17:39:132198 const content::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322199 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]e550f5e2012-01-11 07:22:062200 // If we navigate off the page, reset JavaScript state. This does nothing
2201 // to prevent a malicious script from spamming messages, since the script
2202 // could just reload the page to stop blocking.
2203 if (dialog_creator_ && !details.is_in_page) {
[email protected]2e5b90c2011-08-16 21:11:552204 dialog_creator_->ResetJavaScriptState(this);
2205 dialog_creator_ = NULL;
2206 }
[email protected]420ae012009-04-24 05:16:322207
[email protected]3c9e1872010-11-18 16:17:492208 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252209 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a6e16aec2011-11-11 18:53:042210 DidNavigateAnyFrame(details, params));
[email protected]420ae012009-04-24 05:16:322211}
2212
[email protected]b172aee2012-04-10 17:05:262213void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462214 // If we are creating a RVH for a restored controller, then we need to make
2215 // sure the RenderView starts with a next_page_id_ larger than the number
2216 // of restored entries. This must be called before the RenderView starts
2217 // navigating (to avoid a race between the browser updating max_page_id and
2218 // the renderer updating next_page_id_). Because of this, we only call this
2219 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562220 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582221 if (max_restored_page_id >
2222 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2223 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2224 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322225}
2226
[email protected]b172aee2012-04-10 17:05:262227bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
2228 const string16& title) {
[email protected]420ae012009-04-24 05:16:322229 // For file URLs without a title, use the pathname instead. In the case of a
2230 // synthesized title, we don't want the update to count toward the "one set
2231 // per page of the title to history."
[email protected]6b2f7a82011-04-25 19:30:512232 string16 final_title;
[email protected]420ae012009-04-24 05:16:322233 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512234 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
2235 final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322236 explicit_set = false; // Don't count synthetic titles toward the set limit.
2237 } else {
[email protected]acafd272011-07-26 17:35:572238 TrimWhitespace(title, TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322239 explicit_set = true;
2240 }
2241
[email protected]987fc3a2011-05-26 14:18:092242 // If a page is created via window.open and never navigated,
2243 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552244 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092245 if (entry) {
[email protected]36fc0392011-12-25 03:59:512246 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092247 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322248
[email protected]36fc0392011-12-25 03:59:512249 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092250 } else {
2251 if (page_title_when_no_navigation_entry_ == final_title)
2252 return false; // Nothing changed, don't bother.
2253
2254 page_title_when_no_navigation_entry_ = final_title;
2255 }
[email protected]420ae012009-04-24 05:16:322256
[email protected]420ae012009-04-24 05:16:322257 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232258 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322259
[email protected]2bb171882012-03-07 02:09:462260 std::pair<content::NavigationEntry*, bool> details =
2261 std::make_pair(entry, explicit_set);
[email protected]105bb0f2011-05-24 17:12:142262
[email protected]ad50def52011-10-19 23:17:072263 content::NotificationService::current()->Notify(
[email protected]bb81f382012-01-03 22:45:442264 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2265 content::Source<WebContents>(this),
[email protected]2bb171882012-03-07 02:09:462266 content::Details<std::pair<content::NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042267
[email protected]420ae012009-04-24 05:16:322268 return true;
2269}
2270
[email protected]b172aee2012-04-10 17:05:262271void WebContentsImpl::NotifySwapped() {
[email protected]420ae012009-04-24 05:16:322272 // After sending out a swap notification, we need to send a disconnect
2273 // notification so that clients that pick up a pointer to |this| can NULL the
2274 // pointer. See Bug 1230284.
2275 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072276 content::NotificationService::current()->Notify(
[email protected]4ca15302012-01-03 05:53:202277 content::NOTIFICATION_WEB_CONTENTS_SWAPPED,
2278 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072279 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322280}
2281
[email protected]b172aee2012-04-10 17:05:262282void WebContentsImpl::NotifyConnected() {
[email protected]420ae012009-04-24 05:16:322283 notify_disconnection_ = true;
[email protected]ad50def52011-10-19 23:17:072284 content::NotificationService::current()->Notify(
[email protected]ef9572e2012-01-04 22:14:122285 content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
2286 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072287 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322288}
2289
[email protected]b172aee2012-04-10 17:05:262290void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322291 if (!notify_disconnection_)
2292 return;
2293
2294 notify_disconnection_ = false;
[email protected]ad50def52011-10-19 23:17:072295 content::NotificationService::current()->Notify(
[email protected]fbc5e5f92012-01-02 06:08:322296 content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2297 content::Source<WebContents>(this),
[email protected]ad50def52011-10-19 23:17:072298 content::NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322299}
2300
[email protected]5a3bdf52012-05-24 15:12:572301RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2302 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322303}
2304
[email protected]8d3347f2009-07-09 22:00:212305RenderViewHostDelegate::RendererManagement*
[email protected]b172aee2012-04-10 17:05:262306WebContentsImpl::GetRendererManagementDelegate() {
[email protected]8d3347f2009-07-09 22:00:212307 return &render_manager_;
2308}
2309
[email protected]b172aee2012-04-10 17:05:262310content::RendererPreferences WebContentsImpl::GetRendererPrefs(
[email protected]3d7474ff2011-07-27 17:47:372311 content::BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462312 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512313}
2314
[email protected]b172aee2012-04-10 17:05:262315WebContents* WebContentsImpl::GetAsWebContents() {
[email protected]768c5472011-12-26 19:06:172316 return this;
2317}
2318
[email protected]b172aee2012-04-10 17:05:262319gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172320 if (delegate_)
2321 return delegate_->GetRootWindowResizerRect();
2322 return gfx::Rect();
2323}
2324
[email protected]b172aee2012-04-10 17:05:262325void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442326 // Don't send notifications if we are just creating a swapped-out RVH for
2327 // the opener chain. These won't be used for view-source or WebUI, so it's
2328 // ok to return early.
2329 if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out())
2330 return;
2331
[email protected]ad50def52011-10-19 23:17:072332 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272333 content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB,
[email protected]fbc5e5f92012-01-02 06:08:322334 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532335 content::Details<RenderViewHost>(render_view_host));
[email protected]10f417c52011-12-28 21:04:232336 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322337 if (!entry)
2338 return;
2339
2340 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352341 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:562342 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:582343 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322344
2345 if (entry->IsViewSourceMode()) {
2346 // Put the renderer in view source mode.
[email protected]9f76c1e2012-03-05 15:15:582347 static_cast<RenderViewHostImpl*>(render_view_host)->Send(
2348 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322349 }
[email protected]0666aef2009-05-13 19:48:082350
[email protected]d487beefe2011-12-21 05:41:212351 GetView()->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262352
2353 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252354 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:322355}
2356
[email protected]b172aee2012-04-10 17:05:262357void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522358 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322359 // Don't notify the world, since this came from a renderer in the
2360 // background.
2361 return;
2362 }
2363
2364 NotifyConnected();
[email protected]be1f56ab2011-12-22 06:55:312365 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232366 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302367
2368 // Restore the focus to the tab (otherwise the focus will be on the top
2369 // window).
[email protected]484ae5912010-09-29 19:16:142370 if (was_crashed && !FocusLocationBarByDefault() &&
2371 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302372 Focus();
[email protected]484ae5912010-09-29 19:16:142373 }
[email protected]32ded2212011-11-10 18:51:432374
[email protected]d8c660432011-12-22 20:51:252375 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322376}
2377
[email protected]b172aee2012-04-10 17:05:262378void WebContentsImpl::RenderViewGone(RenderViewHost* rvh,
2379 base::TerminationStatus status,
2380 int error_code) {
[email protected]151a63d2011-12-20 22:32:522381 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322382 // The pending page's RenderViewHost is gone.
2383 return;
2384 }
2385
2386 SetIsLoading(false, NULL);
2387 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232388 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312389 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322390
[email protected]d8c660432011-12-22 20:51:252391 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272392 observers_,
[email protected]be1f56ab2011-12-22 06:55:312393 RenderViewGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322394}
2395
[email protected]b172aee2012-04-10 17:05:262396void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:482397 render_manager_.RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252398 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062399}
2400
[email protected]b172aee2012-04-10 17:05:262401void WebContentsImpl::DidNavigate(
2402 RenderViewHost* rvh,
2403 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]2905f742011-10-13 03:51:582404 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322405 render_manager_.DidNavigateMainFrame(rvh);
[email protected]8030f012009-09-25 18:09:372406
[email protected]434f69f2012-02-06 21:56:522407 // Update the site of the SiteInstance if it doesn't have one yet, unless
2408 // this is for about:blank. In that case, the SiteInstance can still be
2409 // considered unused until a navigation to a real page.
2410 if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() &&
2411 params.url != GURL(chrome::kAboutBlankURL)) {
[email protected]b6583592012-01-25 19:52:332412 static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url);
[email protected]434f69f2012-02-06 21:56:522413 }
[email protected]420ae012009-04-24 05:16:322414
2415 // Need to update MIME type here because it's referred to in
2416 // UpdateNavigationCommands() called by RendererDidNavigate() to
2417 // determine whether or not to enable the encoding menu.
2418 // It's updated only for the main frame. For a subframe,
2419 // RenderView::UpdateURL does not set params.contents_mime_type.
2420 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2421 // TODO(jungshik): Add a test for the encoding menu to avoid
2422 // regressing it again.
[email protected]2905f742011-10-13 03:51:582423 if (content::PageTransitionIsMainFrame(params.transition))
[email protected]420ae012009-04-24 05:16:322424 contents_mime_type_ = params.contents_mime_type;
2425
[email protected]8286f51a2011-05-31 17:39:132426 content::LoadCommittedDetails details;
[email protected]93f230e02011-06-01 14:40:002427 bool did_navigate = controller_.RendererDidNavigate(params, &details);
[email protected]3e90d4a2009-07-03 17:38:392428
[email protected]a9c0bfe2010-09-17 08:35:222429 // Send notification about committed provisional loads. This notification is
2430 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2431 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
[email protected]610cbb82011-10-18 16:35:082432 if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072433 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2434 // that is not recorded in the navigation history. For the purpose of
2435 // tracking navigation events, we treat this event as a sub frame navigation
2436 // event.
2437 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]2905f742011-10-13 03:51:582438 content::PageTransition transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:222439 // Whether or not a page transition was triggered by going backward or
2440 // forward in the history is only stored in the navigation controller's
2441 // entry list.
2442 if (did_navigate &&
[email protected]36fc0392011-12-25 03:59:512443 (controller_.GetActiveEntry()->GetTransitionType() &
[email protected]2905f742011-10-13 03:51:582444 content::PAGE_TRANSITION_FORWARD_BACK)) {
2445 transition_type = content::PageTransitionFromInt(
2446 params.transition | content::PAGE_TRANSITION_FORWARD_BACK);
[email protected]a9c0bfe2010-09-17 08:35:222447 }
[email protected]0d60f0192011-04-14 12:40:102448 // Notify observers about the commit of the provisional load.
[email protected]d8c660432011-12-22 20:51:252449 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:102450 DidCommitProvisionalLoadForFrame(params.frame_id,
[email protected]ef16c3e2012-05-16 22:13:462451 is_main_frame, params.url, transition_type, rvh));
[email protected]a9c0bfe2010-09-17 08:35:222452 }
2453
[email protected]76543b92009-08-31 17:27:452454 if (!did_navigate)
2455 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322456
2457 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2458 // for the appropriate notification (best) or you can add it to
2459 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2460 // necessary, please).
2461
2462 // Run post-commit tasks.
[email protected]93f230e02011-06-01 14:40:002463 if (details.is_main_frame) {
[email protected]420ae012009-04-24 05:16:322464 DidNavigateMainFramePostCommit(details, params);
[email protected]6934a702011-12-20 00:04:512465 if (delegate_)
2466 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]93f230e02011-06-01 14:40:002467 }
[email protected]420ae012009-04-24 05:16:322468 DidNavigateAnyFramePostCommit(rvh, details, params);
2469}
2470
[email protected]b172aee2012-04-10 17:05:262471void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2472 int32 page_id,
2473 const std::string& state) {
[email protected]992db4c2011-05-12 15:37:152474 // Ensure that this state update comes from either the active RVH or one of
2475 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]151a63d2011-12-20 22:32:522476 DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh));
[email protected]420ae012009-04-24 05:16:322477
2478 // We must be prepared to handle state updates for any page, these occur
2479 // when the user is scrolling and entering form data, as well as when we're
2480 // leaving a page, in which case our state may have already been moved to
2481 // the next page. The navigation controller will look up the appropriate
2482 // NavigationEntry and update it when it is notified via the delegate.
2483
2484 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582485 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322486 if (entry_index < 0)
2487 return;
[email protected]10f417c52011-12-28 21:04:232488 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322489
[email protected]36fc0392011-12-25 03:59:512490 if (state == entry->GetContentState())
[email protected]420ae012009-04-24 05:16:322491 return; // Nothing to update.
[email protected]36fc0392011-12-25 03:59:512492 entry->SetContentState(state);
[email protected]420ae012009-04-24 05:16:322493 controller_.NotifyEntryChanged(entry, entry_index);
2494}
2495
[email protected]b172aee2012-04-10 17:05:262496void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2497 int32 page_id,
2498 const string16& title,
2499 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322500 // If we have a title, that's a pretty good indication that we've started
2501 // getting useful data.
2502 SetNotWaitingForResponse();
2503
[email protected]73eb2602012-02-09 19:50:552504 // Try to find the navigation entry, which might not be the current one.
2505 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232506 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582507 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092508
[email protected]73eb2602012-02-09 19:50:552509 // We can handle title updates when we don't have an entry in
2510 // UpdateTitleForEntry, but only if the update is from the current RVH.
2511 if (!entry && rvh != GetRenderViewHost())
2512 return;
2513
[email protected]a49e10b2011-08-01 23:57:462514 // TODO(evan): make use of title_direction.
2515 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092516 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322517 return;
2518
2519 // Broadcast notifications when the UI should be updated.
2520 if (entry == controller_.GetEntryAtOffset(0))
[email protected]d9083482012-01-06 00:38:462521 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322522}
2523
[email protected]b172aee2012-04-10 17:05:262524void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2525 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312526 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322527}
2528
[email protected]b172aee2012-04-10 17:05:262529void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512530 if (delegate_)
2531 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322532}
2533
[email protected]b172aee2012-04-10 17:05:262534void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292535 // The UI may be in an event-tracking loop, such as between the
2536 // mouse-down and mouse-up in text selection or a button click.
2537 // Defer the close until after tracking is complete, so that we
2538 // don't free objects out from under the UI.
2539 // TODO(shess): This could probably be integrated with the
2540 // IsDoingDrag() test below. Punting for now because I need more
2541 // research to understand how this impacts platforms other than Mac.
2542 // TODO(shess): This could get more fine-grained. For instance,
2543 // closing a tab in another window while selecting text in the
2544 // current window's Omnibox should be just fine.
[email protected]d487beefe2011-12-21 05:41:212545 if (GetView()->IsEventTracking()) {
2546 GetView()->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292547 return;
2548 }
2549
[email protected]24a4d1062009-07-10 23:10:422550 // If we close the tab while we're in the middle of a drag, we'll crash.
2551 // Instead, cancel the drag and close it as soon as the drag ends.
[email protected]d487beefe2011-12-21 05:41:212552 if (GetView()->IsDoingDrag()) {
2553 GetView()->CancelDragAndCloseTab();
[email protected]24a4d1062009-07-10 23:10:422554 return;
2555 }
2556
[email protected]420ae012009-04-24 05:16:322557 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522558 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512559 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322560}
2561
[email protected]b172aee2012-04-10 17:05:262562void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522563 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512564 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:572565}
2566
[email protected]b172aee2012-04-10 17:05:262567void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:512568 if (delegate_ && delegate_->IsPopupOrPanel(this))
2569 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:322570}
2571
[email protected]b172aee2012-04-10 17:05:262572void WebContentsImpl::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322573 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492574
[email protected]82114f52012-03-20 22:53:412575 if (delegate_ && content_restrictions_)
2576 OnUpdateContentRestrictions(0);
[email protected]3c9e1872010-11-18 16:17:492577
2578 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252579 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322580}
2581
[email protected]b172aee2012-04-10 17:05:262582void WebContentsImpl::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322583 scoped_ptr<LoadNotificationDetails> details;
2584
[email protected]10f417c52011-12-28 21:04:232585 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]420ae012009-04-24 05:16:322586 // An entry may not exist for a stop when loading an initial blank page or
2587 // if an iframe injected by script into a blank page finishes loading.
2588 if (entry) {
[email protected]420ae012009-04-24 05:16:322589 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2590
2591 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:512592 entry->GetVirtualURL(),
2593 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:322594 elapsed,
2595 &controller_,
2596 controller_.GetCurrentEntryIndex()));
2597 }
2598
[email protected]420ae012009-04-24 05:16:322599 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492600
2601 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252602 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322603}
2604
[email protected]b172aee2012-04-10 17:05:262605void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:162606 controller_.DiscardNonCommittedEntries();
2607
2608 // Update the URL display.
[email protected]d9083482012-01-06 00:38:462609 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:162610}
2611
[email protected]b172aee2012-04-10 17:05:262612void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:512613 if (delegate_)
2614 delegate_->LoadProgressChanged(progress);
[email protected]1a3c3cb2010-12-16 21:03:402615}
2616
[email protected]87717d0e2012-04-26 02:58:432617void WebContentsImpl::DocumentAvailableInMainFrame(
2618 RenderViewHost* render_view_host) {
2619 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2620 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:102621}
2622
[email protected]b172aee2012-04-10 17:05:262623void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:082624 RenderViewHost* render_view_host,
2625 int32 page_id) {
[email protected]ad50def52011-10-19 23:17:072626 content::NotificationService::current()->Notify(
[email protected]432115822011-07-10 15:52:272627 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
[email protected]fbc5e5f92012-01-02 06:08:322628 content::Source<WebContents>(this),
[email protected]6c2381d2011-10-19 02:52:532629 content::Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:082630}
2631
[email protected]196159d2012-05-04 17:26:542632void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh,
2633 const GURL& url,
[email protected]b172aee2012-04-10 17:05:262634 const content::Referrer& referrer,
2635 WindowOpenDisposition disposition,
2636 int64 source_frame_id) {
[email protected]196159d2012-05-04 17:26:542637 // If this came from a swapped out RenderViewHost, we only allow the request
2638 // if we are still in the same BrowsingInstance.
2639 if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() &&
2640 !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) {
2641 return;
2642 }
2643
[email protected]4ad5d77d2011-12-03 02:00:482644 // Delegate to RequestTransferURL because this is just the generic
2645 // case where |old_request_id| is empty.
[email protected]bce1f1c2011-12-05 15:11:582646 RequestTransferURL(url, referrer, disposition, source_frame_id,
[email protected]4ad5d77d2011-12-03 02:00:482647 GlobalRequestID());
2648}
2649
[email protected]b172aee2012-04-10 17:05:262650void WebContentsImpl::RequestTransferURL(
2651 const GURL& url,
2652 const content::Referrer& referrer,
2653 WindowOpenDisposition disposition,
2654 int64 source_frame_id,
2655 const GlobalRequestID& old_request_id) {
[email protected]e5d549d2011-12-28 01:29:202656 WebContents* new_contents = NULL;
[email protected]2905f742011-10-13 03:51:582657 content::PageTransition transition_type = content::PAGE_TRANSITION_LINK;
[email protected]7ade2732011-02-10 00:13:582658 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352659 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322660 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2661 // generated suggestions).
2662 //
[email protected]e0112912011-02-02 22:54:352663 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162664 // want web sites to see a referrer of "chrome://blah" (and some
2665 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322666 // send to the site), so we send no referrer.
[email protected]6bf6a6b52012-02-03 15:41:432667 OpenURLParams params(url, content::Referrer(), source_frame_id, disposition,
[email protected]c63cedf22012-01-17 18:42:222668 render_manager_.web_ui()->GetLinkTransitionType(),
[email protected]4ad5d77d2011-12-03 02:00:482669 false /* is_renderer_initiated */);
2670 params.transferred_global_request_id = old_request_id;
2671 new_contents = OpenURL(params);
[email protected]c63cedf22012-01-17 18:42:222672 transition_type = render_manager_.web_ui()->GetLinkTransitionType();
[email protected]420ae012009-04-24 05:16:322673 } else {
[email protected]6bf6a6b52012-02-03 15:41:432674 OpenURLParams params(url, referrer, source_frame_id, disposition,
[email protected]4ad5d77d2011-12-03 02:00:482675 content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */);
2676 params.transferred_global_request_id = old_request_id;
2677 new_contents = OpenURL(params);
[email protected]ae5184d62011-10-06 19:25:582678 }
2679 if (new_contents) {
2680 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252681 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]ae5184d62011-10-06 19:25:582682 DidOpenRequestedURL(new_contents,
2683 url,
2684 referrer,
2685 disposition,
2686 transition_type,
2687 source_frame_id));
[email protected]420ae012009-04-24 05:16:322688 }
2689}
2690
[email protected]e1c3a552012-05-04 20:51:322691void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
2692 // Tell the active RenderViewHost to run unload handlers and close, as long
2693 // as the request came from a RenderViewHost in the same BrowsingInstance.
2694 // In most cases, we receive this from a swapped out RenderViewHost.
2695 // It is possible to receive it from one that has just been swapped in,
2696 // in which case we might as well deliver the message anyway.
2697 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2698 GetRenderViewHost()->ClosePage();
2699}
2700
[email protected]f546640b2012-05-15 00:03:492701void WebContentsImpl::RouteMessageEvent(
2702 RenderViewHost* rvh,
2703 const ViewMsg_PostMessage_Params& params) {
2704 // Only deliver the message to the active RenderViewHost if the request
2705 // came from a RenderViewHost in the same BrowsingInstance.
2706 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
2707 return;
2708
2709 ViewMsg_PostMessage_Params new_params(params);
2710
2711 // If there is a source_routing_id, translate it to the routing ID for
2712 // the equivalent swapped out RVH in the target process. If we need
2713 // to create a swapped out RVH for the source tab, we create its opener
2714 // chain as well, since those will also be accessible to the target page.
2715 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
2716 // Try to look up the WebContents for the source page.
2717 WebContentsImpl* source_contents = NULL;
2718 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
2719 rvh->GetProcess()->GetID(), params.source_routing_id);
2720 if (source_rvh) {
2721 source_contents = static_cast<WebContentsImpl*>(
2722 source_rvh->GetDelegate()->GetAsWebContents());
2723 }
2724
2725 if (source_contents) {
2726 new_params.source_routing_id =
2727 source_contents->CreateOpenerRenderViews(GetSiteInstance());
2728 } else {
2729 // We couldn't find it, so don't pass a source frame.
2730 new_params.source_routing_id = MSG_ROUTING_NONE;
2731 }
2732 }
2733
2734 // In most cases, we receive this from a swapped out RenderViewHost.
2735 // It is possible to receive it from one that has just been swapped in,
2736 // in which case we might as well deliver the message anyway.
2737 GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent(
2738 GetRenderViewHost()->GetRoutingID(), new_params));
2739}
2740
[email protected]b172aee2012-04-10 17:05:262741void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:342742 RenderViewHost* rvh,
[email protected]4f5ce842011-05-27 19:34:412743 const string16& message,
2744 const string16& default_prompt,
[email protected]420ae012009-04-24 05:16:322745 const GURL& frame_url,
[email protected]be2510c02012-05-28 14:52:142746 content::JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:322747 IPC::Message* reply_msg,
2748 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:072749 // Suppress JavaScript dialogs when requested. Also suppress messages when
2750 // showing an interstitial as it's shown over the previous page and we don't
2751 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502752 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582753 static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() ||
[email protected]0bfbf882011-12-22 18:19:272754 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:072755 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522756 delegate_->ShouldSuppressDialogs() ||
2757 !delegate_->GetJavaScriptDialogCreator();
[email protected]420ae012009-04-24 05:16:322758
2759 if (!suppress_this_message) {
[email protected]55df9092012-02-29 22:56:432760 std::string accept_lang = content::GetContentClient()->browser()->
2761 GetAcceptLangs(GetBrowserContext());
[email protected]2e5b90c2011-08-16 21:11:552762 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522763 dialog_creator_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:432764 this,
2765 frame_url.GetOrigin(),
2766 accept_lang,
2767 javascript_message_type,
2768 message,
[email protected]51da7e32012-01-30 19:24:522769 default_prompt,
[email protected]b172aee2012-04-10 17:05:262770 base::Bind(&WebContentsImpl::OnDialogClosed,
2771 base::Unretained(this),
2772 rvh,
2773 reply_msg),
[email protected]51da7e32012-01-30 19:24:522774 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:322775 }
[email protected]3ab9cb82011-06-03 18:02:072776
2777 if (suppress_this_message) {
2778 // If we are suppressing messages, just reply as if the user immediately
2779 // pressed "Cancel".
[email protected]fedec012012-01-28 03:09:342780 OnDialogClosed(rvh, reply_msg, false, string16());
[email protected]3ab9cb82011-06-03 18:02:072781 }
2782
2783 *did_suppress_message = suppress_this_message;
[email protected]420ae012009-04-24 05:16:322784}
2785
[email protected]b172aee2012-04-10 17:05:262786void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
2787 const string16& message,
2788 bool is_reload,
2789 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:582790 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:512791 if (delegate_)
2792 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:072793
2794 bool suppress_this_message =
[email protected]9f76c1e2012-03-05 15:15:582795 rvhi->is_swapped_out() ||
[email protected]3ab9cb82011-06-03 18:02:072796 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:522797 delegate_->ShouldSuppressDialogs() ||
2798 !delegate_->GetJavaScriptDialogCreator();
[email protected]992db4c2011-05-12 15:37:152799 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:342800 // The reply must be sent to the RVH that sent the request.
[email protected]9f76c1e2012-03-05 15:15:582801 rvhi->JavaScriptDialogClosed(reply_msg, true, string16());
[email protected]8f55e802010-12-06 18:11:502802 return;
2803 }
[email protected]3ab9cb82011-06-03 18:02:072804
[email protected]7ab1e7d62009-10-14 23:32:012805 is_showing_before_unload_dialog_ = true;
[email protected]2e5b90c2011-08-16 21:11:552806 dialog_creator_ = delegate_->GetJavaScriptDialogCreator();
[email protected]51da7e32012-01-30 19:24:522807 dialog_creator_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:322808 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:262809 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:522810 reply_msg));
[email protected]420ae012009-04-24 05:16:322811}
2812
[email protected]a796f202012-05-30 14:14:252813bool WebContentsImpl::AddMessageToConsole(int32 level,
2814 const string16& message,
2815 int32 line_no,
2816 const string16& source_id) {
2817 if (!delegate_)
2818 return false;
2819 return delegate_->AddMessageToConsole(this, level, message, line_no,
2820 source_id);
2821}
2822
[email protected]b172aee2012-04-10 17:05:262823WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]f9133932012-03-16 16:37:332824 // We want to base the page config off of the real URL, rather than the
2825 // display URL.
2826 GURL url = controller_.GetActiveEntry()
2827 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
2828 return GetWebkitPrefs(GetRenderViewHost(), url);
[email protected]420ae012009-04-24 05:16:322829}
2830
[email protected]b172aee2012-04-10 17:05:262831void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:272832 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252833 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:222834
[email protected]ea114722012-03-12 01:11:252835 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:172836 if (rdh) // NULL in unittests.
2837 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:252838}
2839
[email protected]b172aee2012-04-10 17:05:262840void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:442841 // Notify observers.
[email protected]d8c660432011-12-22 20:51:252842 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:442843}
2844
[email protected]b172aee2012-04-10 17:05:262845void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
2846 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:152847 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:522848 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:152849 return;
2850
[email protected]9f76c1e2012-03-05 15:15:582851 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
2852
[email protected]e5fc1632011-08-08 07:51:532853 // Ignore renderer unresponsive event if debugger is attached to the tab
2854 // since the event may be a result of the renderer sitting on a breakpoint.
2855 // See http://crbug.com/65458
[email protected]0e12d7d2011-12-01 16:21:442856 DevToolsAgentHost* agent =
2857 content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh);
2858 if (agent &&
2859 DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent))
[email protected]e5fc1632011-08-08 07:51:532860 return;
2861
[email protected]420ae012009-04-24 05:16:322862 if (is_during_unload) {
2863 // Hang occurred while firing the beforeunload/unload handler.
2864 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:582865 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322866
2867 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2868 return;
2869
2870 // If the tab hangs in the beforeunload/unload handler there's really
2871 // nothing we can do to recover. Pretend the unload listeners have
2872 // all fired and close the tab. If the hang is in the beforeunload handler
2873 // then the user will not have the option of cancelling the close.
2874 Close(rvh);
2875 return;
2876 }
2877
[email protected]9f76c1e2012-03-05 15:15:582878 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:472879 return;
2880
[email protected]6934a702011-12-20 00:04:512881 if (delegate_)
2882 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:322883}
2884
[email protected]b172aee2012-04-10 17:05:262885void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:512886 if (delegate_)
2887 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:322888}
2889
[email protected]b172aee2012-04-10 17:05:262890void WebContentsImpl::LoadStateChanged(
2891 const GURL& url,
2892 const net::LoadStateWithParam& load_state,
2893 uint64 upload_position,
2894 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322895 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562896 upload_position_ = upload_position;
2897 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:502898 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]597a867b2011-11-18 18:31:202899 content::GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:302900 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:212901 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:322902 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:462903 if (IsLoading()) {
2904 NotifyNavigationStateChanged(
2905 content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB);
2906 }
[email protected]420ae012009-04-24 05:16:322907}
2908
[email protected]b172aee2012-04-10 17:05:262909void WebContentsImpl::WorkerCrashed() {
[email protected]6934a702011-12-20 00:04:512910 if (delegate_)
2911 delegate_->WorkerCrashed(this);
[email protected]7d472472011-01-22 01:30:252912}
2913
[email protected]b172aee2012-04-10 17:05:262914void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]420ae012009-04-24 05:16:322915 bool proceed,
2916 bool* proceed_to_fire_unload) {
[email protected]6934a702011-12-20 00:04:512917 if (delegate_)
2918 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]420ae012009-04-24 05:16:322919}
2920
[email protected]b172aee2012-04-10 17:05:262921void WebContentsImpl::DidStartLoadingFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542922 RenderViewHost* render_view_host) {
2923 DidStartLoading();
2924}
2925
[email protected]b172aee2012-04-10 17:05:262926void WebContentsImpl::RenderViewGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:542927 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232928 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2929 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542930}
2931
[email protected]b172aee2012-04-10 17:05:262932void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:102933 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262934 gfx::Size size = view_->GetContainerSize();
2935 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2936 // here during container initialization and normal window size will be set
2937 // later. In case of tab duplication this resizing to 0x0 prevents setting
2938 // normal size later so just ignore it.
2939 if (!size.IsEmpty())
2940 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322941}
2942
[email protected]b172aee2012-04-10 17:05:262943void WebContentsImpl::NotifySwappedFromRenderManager() {
[email protected]3a3d47472010-07-15 21:03:542944 NotifySwapped();
2945}
2946
[email protected]14392a52012-05-02 20:28:442947int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
2948 SiteInstance* instance) {
2949 if (!opener_)
2950 return MSG_ROUTING_NONE;
2951
2952 // Recursively create RenderViews for anything else in the opener chain.
2953 return opener_->CreateOpenerRenderViews(instance);
2954}
2955
2956int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
2957 int opener_route_id = MSG_ROUTING_NONE;
2958
2959 // If this tab has an opener, ensure it has a RenderView in the given
2960 // SiteInstance as well.
2961 if (opener_)
2962 opener_route_id = opener_->CreateOpenerRenderViews(instance);
2963
2964 // Create a swapped out RenderView in the given SiteInstance if none exists,
2965 // setting its opener to the given route_id. Return the new view's route_id.
2966 return render_manager_.CreateRenderView(instance, opener_route_id, true);
2967}
2968
[email protected]b172aee2012-04-10 17:05:262969NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]cdcb1dee2012-01-04 00:46:202970 return GetControllerImpl();
[email protected]3a3d47472010-07-15 21:03:542971}
2972
[email protected]b172aee2012-04-10 17:05:262973WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:562974 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:322975}
2976
[email protected]10f417c52011-12-28 21:04:232977NavigationEntry*
[email protected]b172aee2012-04-10 17:05:262978 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:322979 return controller_.GetLastCommittedEntry();
2980}
2981
[email protected]b172aee2012-04-10 17:05:262982bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]14392a52012-05-02 20:28:442983 RenderViewHost* render_view_host, int opener_route_id) {
[email protected]245f7d52011-11-28 15:36:442984 // Can be NULL during tests.
[email protected]420ae012009-04-24 05:16:322985 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522986
[email protected]420ae012009-04-24 05:16:322987 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:442988 if (rwh_view)
2989 rwh_view->SetSize(view_->GetContainerSize());
[email protected]420ae012009-04-24 05:16:322990
[email protected]74ce1ad2011-12-16 21:51:462991 // Make sure we use the correct starting page_id in the new RenderView.
2992 UpdateMaxPageIDIfNecessary(render_view_host);
2993 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:582994 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:462995
[email protected]7900bfdb2012-05-24 19:31:242996 std::string embedder_channel_name;
2997 int embedder_container_id;
2998 GetBrowserPluginEmbedderInfo(render_view_host,
2999 &embedder_channel_name,
3000 &embedder_container_id);
[email protected]9f76c1e2012-03-05 15:15:583001 if (!static_cast<RenderViewHostImpl*>(
[email protected]51dbd1c2012-05-16 00:36:493002 render_view_host)->CreateRenderView(string16(),
3003 opener_route_id,
3004 max_page_id,
[email protected]7900bfdb2012-05-24 19:31:243005 embedder_channel_name,
3006 embedder_container_id)) {
[email protected]a4127722011-04-27 23:13:523007 return false;
[email protected]14392a52012-05-02 20:28:443008 }
[email protected]a4127722011-04-27 23:13:523009
[email protected]e60c0232011-11-11 19:56:353010#if defined(OS_LINUX) || defined(OS_OPENBSD)
[email protected]f8233cc2011-05-31 20:24:503011 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3012 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443013 if (rwh_view) {
3014 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3015 render_widget_host->WasResized();
3016 }
[email protected]f8233cc2011-05-31 20:24:503017#endif
3018
[email protected]420ae012009-04-24 05:16:323019 return true;
3020}
3021
[email protected]b172aee2012-04-10 17:05:263022void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3023 IPC::Message* reply_msg,
3024 bool success,
3025 const string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543026 if (is_showing_before_unload_dialog_ && !success) {
3027 // If a beforeunload dialog is canceled, we need to stop the throbber from
3028 // spinning, since we forced it to start spinning in Navigate.
3029 DidStopLoading();
3030
[email protected]3bbacc5b2012-04-17 17:46:153031 close_start_time_ = base::TimeTicks();
[email protected]beb440c2009-11-06 04:08:543032 }
3033 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583034 static_cast<RenderViewHostImpl*>(
3035 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543036}
3037
[email protected]b172aee2012-04-10 17:05:263038void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]763ec4ca2011-04-29 15:48:123039 encoding_ = content::GetContentClient()->browser()->
3040 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103041}
[email protected]f45d2a72010-03-08 23:28:353042
[email protected]b172aee2012-04-10 17:05:263043void WebContentsImpl::SaveURL(const GURL& url,
[email protected]20b433a2012-05-15 21:23:463044 const content::Referrer& referrer,
[email protected]b172aee2012-04-10 17:05:263045 bool is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143046 DownloadManager* dlm = GetBrowserContext()->GetDownloadManager();
3047 if (!dlm)
3048 return;
3049 int64 post_id = -1;
[email protected]e30d68d2012-02-09 00:06:263050 if (is_main_frame) {
[email protected]27678b2a2012-02-04 22:09:143051 const NavigationEntry* entry = controller_.GetActiveEntry();
3052 if (entry)
3053 post_id = entry->GetPostID();
3054 }
[email protected]29a5ffc82012-03-13 19:35:583055 content::DownloadSaveInfo save_info;
[email protected]27678b2a2012-02-04 22:09:143056 save_info.prompt_for_save_location = true;
[email protected]c5a5c0842012-05-04 20:05:143057 scoped_ptr<DownloadUrlParameters> params(
3058 DownloadUrlParameters::FromWebContents(this, url, save_info));
[email protected]f859eba2012-05-30 17:22:493059 params->set_referrer(referrer);
[email protected]c5a5c0842012-05-04 20:05:143060 params->set_post_id(post_id);
3061 params->set_prefer_cache(true);
3062 if (post_id >= 0)
3063 params->set_method("POST");
3064 dlm->DownloadUrl(params.Pass());
[email protected]27678b2a2012-02-04 22:09:143065}
3066
[email protected]b172aee2012-04-10 17:05:263067void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]d487beefe2011-12-21 05:41:213068 RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443069 // Can be NULL during tests.
3070 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213071 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363072}
[email protected]9f76c1e2012-03-05 15:15:583073
[email protected]b172aee2012-04-10 17:05:263074RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583075 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3076}
[email protected]7900bfdb2012-05-24 19:31:243077
3078void WebContentsImpl::GetBrowserPluginEmbedderInfo(
3079 content::RenderViewHost* render_view_host,
3080 std::string* embedder_channel_name,
3081 int* embedder_container_id) {
3082 content::RenderProcessHost* embedder_render_process_host =
3083 browser_plugin_host()->embedder_render_process_host();
3084 *embedder_container_id = browser_plugin_host()->instance_id();
3085 int embedder_process_id =
3086 embedder_render_process_host ? embedder_render_process_host->GetID() : -1;
3087 if (embedder_process_id != -1) {
3088 *embedder_channel_name =
3089 StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(),
3090 embedder_process_id);
3091 }
3092}