blob: f154585b299daa0eb03641e17ba460ee0c16b5bf [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]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/browser_plugin/browser_plugin_embedder.h"
22#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5923#include "content/browser/child_process_security_policy_impl.h"
[email protected]49413ca52014-03-05 14:13:4324#include "content/browser/devtools/render_view_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4125#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0426#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4627#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1228#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1629#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1630#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4031#include "content/browser/frame_host/interstitial_page_impl.h"
32#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0133#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1834#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1635#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]f28ef9a32014-05-12 16:36:1036#include "content/browser/geolocation/geolocation_dispatcher_host.h"
[email protected]5c9250872012-01-30 17:24:0537#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4438#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5339#include "content/browser/message_port_message_filter.h"
40#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0641#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3042#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5043#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3244#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5045#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4846#include "content/browser/renderer_host/render_widget_host_view_base.h"
[email protected]b6583592012-01-25 19:52:3347#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1148#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5849#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0350#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5651#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1452#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4253#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4454#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0255#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1756#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5157#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0258#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3659#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1160#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2861#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4462#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3663#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1764#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1465#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4666#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1567#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0068#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2769#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0070#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3771#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1472#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3273#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3474#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3875#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4276#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2577#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2178#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4879#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5480#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4981#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2082#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0383#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5784#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1685#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2986#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5387#include "net/http/http_cache.h"
88#include "net/http/http_transaction_factory.h"
89#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3490#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5691#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0192#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4193#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5294#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1895#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3196
[email protected]583418cc2013-01-17 14:01:1097#if defined(OS_ANDROID)
98#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:4599#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18100#include "content/browser/web_contents/web_contents_android.h"
[email protected]74ebfb12013-06-07 20:48:00101#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10102#endif
103
[email protected]f66df822012-05-18 16:52:17104#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50105#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27106#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57107#endif
[email protected]3e45ba92009-02-20 21:09:00108
[email protected]420ae012009-04-24 05:16:32109// Cross-Site Navigations
110//
[email protected]b172aee2012-04-10 17:05:26111// If a WebContentsImpl is told to navigate to a different web site (as
112// determined by SiteInstance), it will replace its current RenderViewHost with
113// a new RenderViewHost dedicated to the new SiteInstance. This works as
114// follows:
[email protected]420ae012009-04-24 05:16:32115//
[email protected]fc6c1872013-10-03 01:22:35116// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46117// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32118// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35119// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32120// run in the current RVH.
121// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35122// that it has a pending cross-site request. We will check this on the IO
123// thread when deciding how to handle the response.
124// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46125// cancel all the pending logic. Otherwise we allow the pending RVH to send
126// the navigation request to its renderer.
127// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35128// main resource load on the pending RVH. It creates a
129// CrossSiteResourceHandler to check whether a process swap is needed when
130// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46131// - When RDH receives a response, the BufferedResourceHandler determines
132// whether it is a download. If so, it sends a message to the new renderer
133// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26134// pending RVH remains until the next DidNavigate event for this
135// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32136// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35137// download, the CrossSiteResourceHandler checks whether a process swap is
138// needed (either because CrossSiteRequestManager has state for it or because
139// a transfer was needed for a redirect).
140// - If so, CrossSiteResourceHandler pauses the response to first run the old
141// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36142// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
143// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35144// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
145// to a new process is needed, based on the stored pending_nav_params_. (This
146// is independent of whether we started out with a cross-process navigation.)
147// - If not, it just tells the ResourceDispatcherHost to resume the response
148// to its current RenderViewHost.
149// - If so, it cancels the current pending RenderViewHost and sets up a new
150// navigation using RequestTransferURL. When the transferred request
151// arrives in the ResourceDispatcherHost, we transfer the response and
152// resume it.
[email protected]420ae012009-04-24 05:16:32153// - The pending renderer sends a FrameNavigate message that invokes the
154// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46155// pending RVH.
[email protected]b0936d22013-11-28 06:47:36156// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15157// the user goes back. The process only stays live if another tab is using
158// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32159
[email protected]8ff00d72012-10-23 19:12:21160namespace content {
[email protected]420ae012009-04-24 05:16:32161namespace {
162
[email protected]960b0372014-05-19 18:01:00163const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
164
165// This matches what Blink's ProgressTracker has traditionally used for a
166// minimum progress value.
167const double kMinimumLoadingProgress = 0.1;
168
[email protected]82114f52012-03-20 22:53:41169const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05170
[email protected]155c7f22013-12-09 17:07:18171#if defined(OS_ANDROID)
172const char kWebContentsAndroidKey[] = "web_contents_android";
173#endif // OS_ANDROID
174
[email protected]e4abd3b42013-11-12 18:28:47175base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46176g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
177
[email protected]988ed7132014-03-31 16:25:58178static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39179 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29180 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30181 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02182 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58183 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02184 ++g_next_image_download_id,
185 url,
186 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30187 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02188 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39189}
190
[email protected]8bfc8272013-09-09 20:10:53191void NotifyCacheOnIO(
192 scoped_refptr<net::URLRequestContextGetter> request_context,
193 const GURL& url,
194 const std::string& http_method) {
195 request_context->GetURLRequestContext()->http_transaction_factory()->
196 GetCache()->OnExternalCacheHit(url, http_method);
197}
198
[email protected]9b159a52013-10-03 17:24:55199// Helper function for retrieving all the sites in a frame tree.
200bool CollectSites(BrowserContext* context,
201 std::set<GURL>* sites,
202 FrameTreeNode* node) {
203 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
204 return true;
205}
206
[email protected]a86c0e962013-12-17 17:10:39207bool ForEachFrameInternal(
208 const base::Callback<void(RenderFrameHost*)>& on_frame,
209 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41210 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39211 return true;
212}
213
[email protected]c06c58c2014-03-12 20:31:59214bool ForEachPendingFrameInternal(
215 const base::Callback<void(RenderFrameHost*)>& on_frame,
216 FrameTreeNode* node) {
217 RenderFrameHost* pending_frame_host =
218 node->render_manager()->pending_frame_host();
219 if (pending_frame_host)
220 on_frame.Run(pending_frame_host);
221 return true;
222}
223
[email protected]a86c0e962013-12-17 17:10:39224void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
225 IPC::Message* message_copy = new IPC::Message(*message);
226 message_copy->set_routing_id(rfh->GetRoutingID());
227 rfh->Send(message_copy);
228}
229
[email protected]c06c58c2014-03-12 20:31:59230void RunRenderFrameDeleted(
231 ObserverList<WebContentsObserver>* observer_list,
232 RenderFrameHost* render_frame_host) {
233 FOR_EACH_OBSERVER(WebContentsObserver,
234 *observer_list,
235 RenderFrameDeleted(render_frame_host));
236}
237
[email protected]420ae012009-04-24 05:16:32238} // namespace
239
[email protected]54944cde2012-12-09 09:24:59240WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15241 return WebContentsImpl::CreateWithOpener(
242 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19243}
244
245WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59246 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30247 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59248 WebContentsImpl* new_contents = new WebContentsImpl(
249 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30250
251 for (SessionStorageNamespaceMap::const_iterator it =
252 session_storage_namespace_map.begin();
253 it != session_storage_namespace_map.end();
254 ++it) {
255 new_contents->GetController()
256 .SetSessionStorageNamespace(it->first, it->second.get());
257 }
258
[email protected]54944cde2012-12-09 09:24:59259 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19260 return new_contents;
[email protected]a81343d232011-12-27 07:39:20261}
[email protected]746d3052012-05-22 15:15:47262
[email protected]e4abd3b42013-11-12 18:28:47263void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46264 g_created_callbacks.Get().push_back(callback);
265}
266
[email protected]e4abd3b42013-11-12 18:28:47267void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46268 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
269 if (g_created_callbacks.Get().at(i).Equals(callback)) {
270 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
271 return;
272 }
273 }
274}
275
[email protected]299d7f12012-05-23 05:31:15276WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47277 return rvh->GetDelegate()->GetAsWebContents();
278}
279
[email protected]a86c0e962013-12-17 17:10:39280WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
281 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
282 if (!rfh_impl)
283 return NULL;
284 return rfh_impl->delegate()->GetAsWebContents();
285}
286
[email protected]7fff43e2013-05-21 20:21:10287// WebContentsImpl::DestructionObserver ----------------------------------------
288
289class WebContentsImpl::DestructionObserver : public WebContentsObserver {
290 public:
291 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
292 : WebContentsObserver(watched_contents),
293 owner_(owner) {
294 }
295
296 // WebContentsObserver:
[email protected]12a46832014-05-09 13:35:58297 virtual void WebContentsDestroyed() OVERRIDE {
298 owner_->OnWebContentsDestroyed(
299 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10300 }
301
302 private:
303 WebContentsImpl* owner_;
304
305 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
306};
307
[email protected]8ed16472014-04-11 19:02:48308WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
309 int render_frame_id,
310 ColorChooser* chooser,
311 int identifier)
312 : render_process_id(render_process_id),
313 render_frame_id(render_frame_id),
314 chooser(chooser),
315 identifier(identifier) {
316}
317
318WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
319}
320
[email protected]b172aee2012-04-10 17:05:26321// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32322
[email protected]b172aee2012-04-10 17:05:26323WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21324 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19325 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42326 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22327 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57328 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44329 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49330 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08331#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41332 accessible_parent_(NULL),
333#endif
[email protected]6ea6bdf2013-12-06 13:35:01334 frame_tree_(new NavigatorImpl(&controller_, this),
335 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34336 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03337 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23338 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
339 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34340 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26341 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00342 loading_total_progress_(0.0),
343 loading_weak_factory_(this),
344 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56345 upload_size_(0),
346 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47347 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10348 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55349 capturer_count_(0),
350 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57351 is_being_destroyed_(false),
352 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15353 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01354 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02355 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38356 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21357 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
358 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00359 temporary_zoom_settings_(false),
[email protected]bab38af2014-03-30 17:37:29360 totalPinchGestureAmount_(0),
361 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44362 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42363 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]87de04b02014-04-08 22:14:49364 is_subframe_(false),
365 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46366 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
367 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55368 frame_tree_.SetFrameRemoveListener(
369 base::Bind(&WebContentsImpl::OnFrameRemoved,
370 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35371}
initial.commit09911bf2008-07-26 23:55:29372
[email protected]b172aee2012-04-10 17:05:26373WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32374 is_being_destroyed_ = true;
375
[email protected]21b41c7e892014-02-28 01:52:24376 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
377 // shutdown and be deleted as well.
378 frame_tree_.ForEach(
379 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
380
[email protected]d9030b82013-07-19 08:26:06381 ClearAllPowerSaveBlockers();
382
[email protected]b24b68a2012-09-24 21:57:26383 for (std::set<RenderWidgetHostImpl*>::iterator iter =
384 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
385 (*iter)->DetachDelegate();
386 }
387 created_widgets_.clear();
388
[email protected]3ab9cb82011-06-03 18:02:07389 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15390 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11391 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07392
[email protected]8ed16472014-04-11 19:02:48393 if (color_chooser_info_.get())
394 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20395
[email protected]420ae012009-04-24 05:16:32396 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32397
[email protected]ca13a442012-04-17 14:00:12398 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21399 NotificationService::current()->Notify(
400 NOTIFICATION_WEB_CONTENTS_DESTROYED,
401 Source<WebContents>(this),
402 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32403
[email protected]c06c58c2014-03-12 20:31:59404 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
405 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
406 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
407 run_render_frame_deleted_callback));
408
[email protected]fa944cb82013-11-15 17:51:21409 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27410 if (pending_rvh) {
411 FOR_EACH_OBSERVER(WebContentsObserver,
412 observers_,
413 RenderViewDeleted(pending_rvh));
414 }
415
[email protected]c06c58c2014-03-12 20:31:59416 ForEachFrame(run_render_frame_deleted_callback);
417
[email protected]f273ee52013-10-18 16:05:27418 FOR_EACH_OBSERVER(WebContentsObserver,
419 observers_,
[email protected]fa944cb82013-11-15 17:51:21420 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27421
[email protected]2db9bd72012-04-13 20:20:56422 FOR_EACH_OBSERVER(WebContentsObserver,
423 observers_,
[email protected]12a46832014-05-09 13:35:58424 WebContentsDestroyed());
425
426 FOR_EACH_OBSERVER(WebContentsObserver,
427 observers_,
428 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08429
[email protected]6934a702011-12-20 00:04:51430 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10431
432 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
433 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42434}
435
[email protected]d1198fd2012-08-13 22:50:19436WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59437 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19438 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03439 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59440 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06441 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19442
[email protected]83100cd2014-05-10 11:50:06443 if (params.guest_instance_id) {
[email protected]50d326e2014-05-20 17:59:06444 scoped_ptr<base::DictionaryValue> extra_params;
445 if (params.guest_extra_params)
446 extra_params.reset(params.guest_extra_params->DeepCopy());
[email protected]83100cd2014-05-10 11:50:06447 // This makes |new_contents| act as a guest.
448 // For more info, see comment above class BrowserPluginGuest.
449 BrowserPluginGuest::Create(params.guest_instance_id,
450 params.site_instance,
451 new_contents,
[email protected]50d326e2014-05-20 17:59:06452 extra_params.Pass(),
453 opener ? opener->GetBrowserPluginGuest() : NULL);
[email protected]83100cd2014-05-10 11:50:06454 // We are instantiating a WebContents for browser plugin. Set its subframe
455 // bit to true.
456 new_contents->is_subframe_ = true;
457 }
[email protected]54944cde2012-12-09 09:24:59458 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19459 return new_contents;
460}
461
[email protected]b0936d22013-11-28 06:47:36462RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21463 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28464}
465
[email protected]7bb761892012-07-20 09:32:47466bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
467 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44468 return OnMessageReceived(render_view_host, NULL, message);
469}
470
471bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
472 RenderFrameHost* render_frame_host,
473 const IPC::Message& message) {
474 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56475 if (GetWebUI() &&
476 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17477 return true;
[email protected]d2353452012-01-19 19:53:56478 }
[email protected]f82d57b52011-04-27 19:13:17479
[email protected]d8c660432011-12-22 20:51:25480 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
481 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33482 if (render_frame_host) {
483 while ((observer = it.GetNext()) != NULL)
484 if (observer->OnMessageReceived(message, render_frame_host))
485 return true;
486 } else {
487 while ((observer = it.GetNext()) != NULL)
488 if (observer->OnMessageReceived(message))
489 return true;
490 }
[email protected]403415a2011-01-10 18:57:53491
[email protected]1d62cf72014-02-07 21:31:57492 // Message handlers should be aware of which
493 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
494 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43495 if (render_frame_host) {
496 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
497 render_frame_host->GetRenderViewHost(), message))
498 return true;
[email protected]1d62cf72014-02-07 21:31:57499 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43500 } else {
501 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
502 render_view_host, message))
503 return true;
[email protected]1d62cf72014-02-07 21:31:57504 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43505 }
[email protected]1d62cf72014-02-07 21:31:57506
[email protected]724159a2010-12-30 01:11:18507 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33508 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]f114fa42013-12-06 17:06:44509 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
510 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40511 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
512 OnDomOperationResponse)
[email protected]8ed16472014-04-11 19:02:48513 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
514 OnDocumentLoadedInFrame)
515 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00516 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
517 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
518 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
519 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48520 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
521 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
522 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
523 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19524 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
525 OnMediaPlayingNotification)
526 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
527 OnMediaPausedNotification)
[email protected]724159a2010-12-30 01:11:18528 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
529 OnDidLoadResourceFromMemoryCache)
530 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
531 OnDidDisplayInsecureContent)
532 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
533 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25534 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26535 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21536 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20537 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
538 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16539 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10540 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50541 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50542 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
543 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55544 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
545 OnBrowserPluginMessage(message))
546 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
547 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02548 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
549 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]9f268072013-11-07 00:02:15550 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
551 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07552 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
553 OnShowValidationMessage)
554 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
555 OnHideValidationMessage)
556 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
557 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48558#if defined(OS_ANDROID)
559 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
560 OnFindMatchRectsReply)
561 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
562 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48563#endif
[email protected]724159a2010-12-30 01:11:18564 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33565 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44566 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57567 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18568
[email protected]724159a2010-12-30 01:11:18569 return handled;
570}
571
[email protected]b172aee2012-04-10 17:05:26572void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18573 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21574 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43575 if (delegate_)
576 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18577}
578
[email protected]d1198fd2012-08-13 22:50:19579NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56580 return controller_;
581}
582
[email protected]d1198fd2012-08-13 22:50:19583const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56584 return controller_;
585}
586
[email protected]8ff00d72012-10-23 19:12:21587BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55588 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30589}
590
[email protected]b172aee2012-04-10 17:05:26591const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24592 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32593 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51594 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31595}
596
[email protected]a093ce02013-07-22 20:53:14597const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24598 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32599 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24600 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
601}
602
603const GURL& WebContentsImpl::GetLastCommittedURL() const {
604 // We may not have a navigation entry yet.
605 NavigationEntry* entry = controller_.GetLastCommittedEntry();
606 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
607}
608
[email protected]8ff00d72012-10-23 19:12:21609WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31610 return delegate_;
611}
612
[email protected]8ff00d72012-10-23 19:12:21613void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31614 // TODO(cbentzel): remove this debugging code?
615 if (delegate == delegate_)
616 return;
617 if (delegate_)
618 delegate_->Detach(this);
619 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08620 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31621 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08622 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00623 if (view_)
624 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08625 }
[email protected]be1f56ab2011-12-22 06:55:31626}
627
[email protected]8ff00d72012-10-23 19:12:21628RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21629 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41630 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16631}
632
[email protected]60eca4eb2013-12-06 00:02:16633RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41634 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16635}
636
[email protected]9c9343b2014-03-08 02:56:07637RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
638 if (!frame_tree_.GetFocusedFrame())
639 return NULL;
640 return frame_tree_.GetFocusedFrame()->current_frame_host();
641}
642
[email protected]a86c0e962013-12-17 17:10:39643void WebContentsImpl::ForEachFrame(
644 const base::Callback<void(RenderFrameHost*)>& on_frame) {
645 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
646}
647
648void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
649 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
650 delete message;
651}
652
[email protected]b172aee2012-04-10 17:05:26653RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21654 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31655}
656
[email protected]6b618e62012-08-16 12:59:18657int WebContentsImpl::GetRoutingID() const {
658 if (!GetRenderViewHost())
659 return MSG_ROUTING_NONE;
660
661 return GetRenderViewHost()->GetRoutingID();
662}
663
[email protected]44470a22013-01-24 01:21:54664int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
665 return fullscreen_widget_routing_id_;
666}
667
[email protected]b172aee2012-04-10 17:05:26668RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21669 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31670}
671
[email protected]4aebbca2013-09-17 22:26:49672RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
673 const {
674 RenderWidgetHost* const widget_host =
675 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
676 GetFullscreenWidgetRoutingID());
677 return widget_host ? widget_host->GetView() : NULL;
678}
679
[email protected]8ff00d72012-10-23 19:12:21680WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31681 return view_.get();
682}
683
[email protected]8ff00d72012-10-23 19:12:21684WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56685 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03686 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
687 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22688 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58689 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22690 web_ui->SetController(controller);
691 return web_ui;
692 }
693
694 delete web_ui;
695 return NULL;
696}
697
[email protected]8ff00d72012-10-23 19:12:21698WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21699 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
700 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31701}
702
[email protected]8ff00d72012-10-23 19:12:21703WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21704 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34705}
706
[email protected]86ef6a392012-05-11 22:03:11707void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22708 if (GetUserAgentOverride() == override)
709 return;
710
711 renderer_preferences_.user_agent_override = override;
712
713 // Send the new override string to the renderer.
714 RenderViewHost* host = GetRenderViewHost();
715 if (host)
716 host->SyncRendererPrefs();
717
718 // Reload the page if a load is currently in progress to avoid having
719 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27720 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22721 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
722 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53723
724 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
725 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11726}
727
728const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22729 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11730}
731
[email protected]2ceee8f2014-01-14 18:02:08732#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41733void WebContentsImpl::SetParentNativeViewAccessible(
734gfx::NativeViewAccessible accessible_parent) {
735 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45736 if (GetRenderViewHost())
737 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41738}
739#endif
740
[email protected]fcf75d42013-12-03 20:11:26741const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55742 // Transient entries take precedence. They are used for interstitial pages
743 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23744 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08745 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21746 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30747 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23748 if (entry) {
[email protected]b5cca982011-05-26 04:42:08749 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23750 }
[email protected]fa944cb82013-11-15 17:51:21751 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
752 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58753 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54754 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32755 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54756 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35757 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26758 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54759 if (!title.empty())
760 return title;
761 }
762 }
763
764 // We use the title for the last committed entry rather than a pending
765 // navigation entry. For example, when the user types in a URL, we want to
766 // keep the old page's title until the new load has committed and we get a new
767 // title.
[email protected]96d185d2009-04-24 03:28:54768 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32769
[email protected]9eeafc012013-11-25 23:49:47770 // We make an exception for initial navigations.
771 if (controller_.IsInitialNavigation()) {
772 // We only want to use the title from the visible entry in one of two cases:
773 // 1. There's already a committed entry for an initial navigation, in which
774 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
775 // 2. The pending entry has been explicitly assigned a title to display.
776 //
777 // If there's no last committed entry and no assigned title, we should fall
778 // back to |page_title_when_no_navigation_entry_| rather than showing the
779 // URL.
780 if (entry ||
781 (controller_.GetVisibleEntry() &&
782 !controller_.GetVisibleEntry()->GetTitle().empty())) {
783 entry = controller_.GetVisibleEntry();
784 }
785 }
[email protected]59167c22013-06-03 18:07:32786
[email protected]45d0ef7f2011-01-05 13:46:23787 if (entry) {
[email protected]b5cca982011-05-26 04:42:08788 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23789 }
[email protected]987fc3a2011-05-26 14:18:09790
791 // |page_title_when_no_navigation_entry_| is finally used
792 // if no title cannot be retrieved.
793 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54794}
795
[email protected]b172aee2012-04-10 17:05:26796int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46797 return GetMaxPageIDForSiteInstance(GetSiteInstance());
798}
799
[email protected]b172aee2012-04-10 17:05:26800int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
801 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33802 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
803 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46804
[email protected]b6583592012-01-25 19:52:33805 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34806}
807
[email protected]b172aee2012-04-10 17:05:26808void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46809 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
810}
811
[email protected]b172aee2012-04-10 17:05:26812void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33813 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46814 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33815 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34816}
817
[email protected]ec6c05f2013-10-23 18:41:57818void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
819 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
820 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57821}
822
[email protected]b172aee2012-04-10 17:05:26823SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21824 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54825}
826
[email protected]b172aee2012-04-10 17:05:26827SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21828 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
829 GetRenderManager()->pending_render_view_host() :
830 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58831 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38832}
833
[email protected]b172aee2012-04-10 17:05:26834bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31835 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49836}
837
[email protected]6dfed692014-05-22 04:18:03838bool WebContentsImpl::IsLoadingToDifferentDocument() const {
839 return is_loading_ && is_load_to_different_document_;
840}
841
[email protected]b172aee2012-04-10 17:05:26842bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03843 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31844}
845
[email protected]b172aee2012-04-10 17:05:26846const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31847 return load_state_;
848}
849
[email protected]fcf75d42013-12-03 20:11:26850const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31851 return load_state_host_;
852}
853
[email protected]b172aee2012-04-10 17:05:26854uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31855 return upload_size_;
856}
857
[email protected]b172aee2012-04-10 17:05:26858uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31859 return upload_position_;
860}
861
[email protected]1ae93fb2013-06-14 03:38:56862std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56863 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39864 frame_tree_.ForEach(base::Bind(&CollectSites,
865 base::Unretained(GetBrowserContext()),
866 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56867 return sites;
868}
869
[email protected]b172aee2012-04-10 17:05:26870const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54871 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31872}
873
[email protected]b172aee2012-04-10 17:05:26874bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31875 return displayed_insecure_content_;
876}
877
[email protected]222f5822014-02-05 23:40:49878void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25879 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55880 ++capturer_count_;
881 DVLOG(1) << "There are now " << capturer_count_
882 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49883
884 // Note: This provides a hint to upstream code to size the views optimally
885 // for quality (e.g., to avoid scaling).
886 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
887 preferred_size_for_capture_ = capture_size;
888 OnPreferredSizeChanged(preferred_size_);
889 }
[email protected]54597982013-02-06 01:59:55890}
891
892void WebContentsImpl::DecrementCapturerCount() {
893 --capturer_count_;
894 DVLOG(1) << "There are now " << capturer_count_
895 << " capturing(s) of WebContentsImpl@" << this;
896 DCHECK_LE(0, capturer_count_);
897
[email protected]5a652232013-02-12 06:15:25898 if (is_being_destroyed_)
899 return;
900
[email protected]222f5822014-02-05 23:40:49901 if (capturer_count_ == 0) {
902 const gfx::Size old_size = preferred_size_for_capture_;
903 preferred_size_for_capture_ = gfx::Size();
904 OnPreferredSizeChanged(old_size);
905 }
906
[email protected]1ac10dca2013-08-20 20:47:04907 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55908 DVLOG(1) << "Executing delayed WasHidden().";
909 WasHidden();
910 }
[email protected]be1f56ab2011-12-22 06:55:31911}
912
[email protected]f2bd40812013-07-20 04:30:44913int WebContentsImpl::GetCapturerCount() const {
914 return capturer_count_;
915}
916
[email protected]b172aee2012-04-10 17:05:26917bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31918 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
919 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
920 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49921}
922
[email protected]b172aee2012-04-10 17:05:26923void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
924 int error_code) {
[email protected]443b80e2010-12-14 00:42:23925 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34926 return;
927
[email protected]443b80e2010-12-14 00:42:23928 crashed_status_ = status;
929 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21930 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34931}
932
[email protected]b172aee2012-04-10 17:05:26933base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31934 return crashed_status_;
935}
936
[email protected]b172aee2012-04-10 17:05:26937bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31938 return is_being_destroyed_;
939}
940
[email protected]b172aee2012-04-10 17:05:26941void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34942 if (delegate_)
943 delegate_->NavigationStateChanged(this, changed_flags);
944}
945
[email protected]9a890452014-02-13 22:21:02946base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
947 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33948}
949
[email protected]9e2e4632012-07-27 16:38:41950void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54951 controller_.SetActive(true);
[email protected]cfd80b02014-05-01 17:46:48952 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]8cb5d5b2010-02-09 11:36:16953 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29954 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43955#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16956 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43957#endif
958 }
[email protected]96d185d2009-04-24 03:28:54959
[email protected]9a890452014-02-13 22:21:02960 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38961
[email protected]b9769d82012-02-10 00:23:59962 // The resize rect might have changed while this was inactive -- send the new
963 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58964 RenderViewHostImpl* rvh =
965 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59966 if (rvh) {
967 rvh->ResizeRectChanged(GetRootWindowResizerRect());
968 }
[email protected]96d185d2009-04-24 03:28:54969
[email protected]c0d9d5672013-10-09 07:38:03970 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
971
[email protected]54597982013-02-06 01:59:55972 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31973}
974
[email protected]b172aee2012-04-10 17:05:26975void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55976 // If there are entities capturing screenshots or video (e.g., mirroring),
977 // don't activate the "disable rendering" optimization.
978 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52979 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55980 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26981 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52982 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33983 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52984 // calls us).
[email protected]cfd80b02014-05-01 17:46:48985 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]8cb5d5b2010-02-09 11:36:16986 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29987 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54988 }
989
[email protected]c0d9d5672013-10-09 07:38:03990 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
991
[email protected]54597982013-02-06 01:59:55992 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37993}
994
[email protected]b172aee2012-04-10 17:05:26995bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31996 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27997 return WillNotifyDisconnection() &&
998 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58999 !static_cast<RenderViewHostImpl*>(
1000 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311001}
1002
[email protected]1c3f80bd2014-04-08 23:02:061003void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1004 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1005 for_cross_site_transition);
1006}
1007
[email protected]b172aee2012-04-10 17:05:261008void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211009 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401010 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271011}
1012
[email protected]b172aee2012-04-10 17:05:261013WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441014 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451015 // We pass our own opener so that the cloned page can access it if it was
1016 // before.
[email protected]54944cde2012-12-09 09:24:591017 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451018 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591019 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191020 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221021 FOR_EACH_OBSERVER(WebContentsObserver,
1022 observers_,
1023 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271024 return tc;
1025}
1026
[email protected]14392a52012-05-02 20:28:441027void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211028 const NotificationSource& source,
1029 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441030 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211031 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1032 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501033 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1034 i != pending_widget_views_.end(); ++i) {
1035 if (host->GetView() == i->second) {
1036 pending_widget_views_.erase(i);
1037 break;
1038 }
1039 }
1040 break;
1041 }
[email protected]14392a52012-05-02 20:28:441042 default:
1043 NOTREACHED();
1044 }
1045}
1046
[email protected]ec6c05f2013-10-23 18:41:571047WebContents* WebContentsImpl::GetWebContents() {
1048 return this;
1049}
1050
[email protected]54944cde2012-12-09 09:24:591051void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211052 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361053 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211054 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431055 should_normally_be_visible_ = !params.initially_hidden;
1056
[email protected]fa944cb82013-11-15 17:51:211057 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041058 params.browser_context, params.site_instance, params.routing_id,
1059 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191060
[email protected]fc2b46b2014-05-03 16:33:451061 WebContentsViewDelegate* delegate =
1062 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1063
1064 if (browser_plugin_guest_) {
1065 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1066 this, delegate, &render_view_host_delegate_view_));
1067
1068 WebContentsViewGuest* rv = new WebContentsViewGuest(
1069 this, browser_plugin_guest_.get(), platform_view.Pass(),
1070 render_view_host_delegate_view_);
1071 render_view_host_delegate_view_ = rv;
1072 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191073 } else {
[email protected]fc2b46b2014-05-03 16:33:451074 // Regular WebContentsView.
1075 view_.reset(CreateWebContentsView(
1076 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191077 }
[email protected]fc2b46b2014-05-03 16:33:451078 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191079 CHECK(view_.get());
1080
[email protected]ed245db2012-12-18 08:00:451081 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591082 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191083
1084 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101085 if (opener_)
1086 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191087
1088 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211089 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1090 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101091
1092 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
1093
[email protected]c7654a232013-06-12 21:04:441094#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101095 date_time_chooser_.reset(new DateTimeChooserAndroid());
1096#endif
[email protected]d1198fd2012-08-13 22:50:191097}
1098
[email protected]7fff43e2013-05-21 20:21:101099void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1100 RemoveDestructionObserver(web_contents);
1101
[email protected]14392a52012-05-02 20:28:441102 // Clear the opener if it has been closed.
1103 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441104 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511105 return;
[email protected]14392a52012-05-02 20:28:441106 }
[email protected]ceee8cd2013-03-08 04:59:511107 // Clear a pending contents that has been closed before being shown.
1108 for (PendingContents::iterator iter = pending_contents_.begin();
1109 iter != pending_contents_.end();
1110 ++iter) {
1111 if (iter->second != web_contents)
1112 continue;
1113 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511114 return;
1115 }
1116 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441117}
1118
[email protected]7fff43e2013-05-21 20:21:101119void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1120 if (!ContainsKey(destruction_observers_, web_contents)) {
1121 destruction_observers_[web_contents] =
1122 new DestructionObserver(this, web_contents);
1123 }
1124}
1125
1126void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1127 DestructionObservers::iterator iter =
1128 destruction_observers_.find(web_contents);
1129 if (iter != destruction_observers_.end()) {
1130 delete destruction_observers_[web_contents];
1131 destruction_observers_.erase(iter);
1132 }
1133}
1134
[email protected]b172aee2012-04-10 17:05:261135void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311136 observers_.AddObserver(observer);
1137}
1138
[email protected]b172aee2012-04-10 17:05:261139void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311140 observers_.RemoveObserver(observer);
1141}
1142
[email protected]b172aee2012-04-10 17:05:261143void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341144 if (delegate_)
1145 delegate_->ActivateContents(this);
1146}
1147
[email protected]b172aee2012-04-10 17:05:261148void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121149 if (delegate_)
1150 delegate_->DeactivateContents(this);
1151}
1152
[email protected]b172aee2012-04-10 17:05:261153void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481154 if (delegate_)
1155 delegate_->LostCapture();
1156}
1157
[email protected]b24b68a2012-09-24 21:57:261158void WebContentsImpl::RenderWidgetDeleted(
1159 RenderWidgetHostImpl* render_widget_host) {
1160 if (is_being_destroyed_) {
1161 // |created_widgets_| might have been destroyed.
1162 return;
1163 }
1164
1165 std::set<RenderWidgetHostImpl*>::iterator iter =
1166 created_widgets_.find(render_widget_host);
1167 if (iter != created_widgets_.end())
1168 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541169
1170 if (render_widget_host &&
1171 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491172 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1173 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541174 FOR_EACH_OBSERVER(WebContentsObserver,
1175 observers_,
1176 DidDestroyFullscreenWidget(
1177 fullscreen_widget_routing_id_));
1178 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1179 }
[email protected]b24b68a2012-09-24 21:57:261180}
1181
[email protected]b172aee2012-04-10 17:05:261182bool WebContentsImpl::PreHandleKeyboardEvent(
1183 const NativeWebKeyboardEvent& event,
1184 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481185 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131186 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481187}
1188
[email protected]b172aee2012-04-10 17:05:261189void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481190 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131191 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481192}
1193
[email protected]d92026ef2014-03-03 21:04:131194bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461195 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191196#if !defined(OS_MACOSX)
1197 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1198 // isn't done for two reasons:
1199 // -the OS already has a gesture to do this through pinch-zoom
1200 // -if a user starts an inertial scroll, let's go, and presses control
1201 // (i.e. control+tab) then the OS's buffered scroll events will come in
1202 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521203 if (delegate_ &&
1204 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551205 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1206 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1207 // gestures, which are regrettably easy to trigger accidentally.
1208 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521209 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1210 return true;
1211 }
[email protected]bccc4472013-04-18 16:37:191212#endif
[email protected]fb3f066e2013-02-12 19:12:521213 return false;
1214}
1215
[email protected]04bce562014-01-30 05:34:541216bool WebContentsImpl::PreHandleGestureEvent(
1217 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031218 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541219}
1220
[email protected]bab38af2014-03-30 17:37:291221bool WebContentsImpl::HandleGestureEvent(
1222 const blink::WebGestureEvent& event) {
1223 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1224 // Use them to implement browser zoom, as for HandleWheelEvent above.
1225 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1226 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1227 // The scale difference necessary to trigger a zoom action. Derived from
1228 // experimentation to find a value that feels reasonable.
1229 const float kZoomStepValue = 0.6f;
1230
1231 // Find the (absolute) thresholds on either side of the current zoom factor,
1232 // then convert those to actual numbers to trigger a zoom in or out.
1233 // This logic deliberately makes the range around the starting zoom value
1234 // for the gesture twice as large as the other ranges (i.e., the notches are
1235 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1236 // so that it's easier to get back to your starting point than it is to
1237 // overshoot.
1238 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1239 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1240 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1241 : -backStep;
1242 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1243 : backStep;
1244
[email protected]fb546cb2014-04-28 14:09:371245 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291246 if (totalPinchGestureAmount_ > zoomInThreshold) {
1247 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461248 if (delegate_)
1249 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291250 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1251 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461252 if (delegate_)
1253 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291254 }
1255 return true;
1256 }
1257
1258 return false;
1259}
1260
[email protected]2ceee8f2014-01-14 18:02:081261#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411262gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1263 return accessible_parent_;
1264}
1265#endif
1266
[email protected]b172aee2012-04-10 17:05:261267void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431268 if (delegate_)
1269 delegate_->HandleMouseDown();
1270}
1271
[email protected]b172aee2012-04-10 17:05:261272void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481273 if (delegate_)
1274 delegate_->HandleMouseUp();
1275}
1276
[email protected]590a634e2012-07-19 16:38:231277void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481278 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231279 delegate_->HandlePointerActivate();
1280}
1281
1282void WebContentsImpl::HandleGestureBegin() {
1283 if (delegate_)
1284 delegate_->HandleGestureBegin();
1285}
1286
1287void WebContentsImpl::HandleGestureEnd() {
1288 if (delegate_)
1289 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481290}
1291
[email protected]b172aee2012-04-10 17:05:261292void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491293 // This method is being called to enter or leave renderer-initiated fullscreen
1294 // mode. Either way, make sure any existing fullscreen widget is shut down
1295 // first.
1296 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1297 if (widget_view)
1298 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1299
[email protected]8a5e0ca2011-08-25 06:30:471300 if (delegate_)
1301 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371302
1303 FOR_EACH_OBSERVER(WebContentsObserver,
1304 observers_,
1305 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471306}
1307
[email protected]b172aee2012-04-10 17:05:261308bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381309 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121310}
1311
[email protected]a9c81f02012-06-01 00:15:441312void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1313 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371314 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441315 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371316 } else {
1317 GotResponseToLockMouseRequest(false);
1318 }
1319}
1320
[email protected]b172aee2012-04-10 17:05:261321void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371322 if (delegate_)
1323 delegate_->LostMouseLock();
1324}
1325
[email protected]bafe6cd2012-05-23 23:09:501326void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201327 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501328 int route_id,
[email protected]227692c52013-05-31 22:43:041329 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131330 const ViewHostMsg_CreateWindow_Params& params,
1331 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501332 // We usually create the new window in the same BrowsingInstance (group of
1333 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551334 // if the opener is being suppressed (in a non-guest), we create a new
1335 // SiteInstance in its own BrowsingInstance.
1336 bool is_guest = GetRenderProcessHost()->IsGuest();
1337
[email protected]04cbd3d2013-12-04 04:58:201338 // If the opener is to be suppressed, the new window can be in any process.
1339 // Since routing ids are process specific, we must not have one passed in
1340 // as argument here.
1341 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1342
[email protected]bafe6cd2012-05-23 23:09:501343 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551344 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571345 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501346 GetSiteInstance();
1347
[email protected]04cbd3d2013-12-04 04:58:201348 // A message to create a new window can only come from the active process for
1349 // this WebContentsImpl instance. If any other process sends the request,
1350 // it is invalid and the process must be terminated.
1351 if (GetRenderProcessHost()->GetID() != render_process_id) {
1352 base::ProcessHandle process_handle =
1353 RenderProcessHost::FromID(render_process_id)->GetHandle();
1354 if (process_handle != base::kNullProcessHandle) {
1355 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391356 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201357 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1358 }
1359 return;
1360 }
1361
[email protected]d1198fd2012-08-13 22:50:191362 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341363 //
1364 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301365 const std::string& partition_id =
1366 GetContentClient()->browser()->
1367 GetStoragePartitionIdForSite(GetBrowserContext(),
1368 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461369 StoragePartition* partition = BrowserContext::GetStoragePartition(
1370 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411371 DOMStorageContextWrapper* dom_storage_context =
1372 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191373 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1374 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1375 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371376
1377 if (delegate_ &&
1378 !delegate_->ShouldCreateWebContents(this,
1379 route_id,
1380 params.window_container_type,
1381 params.frame_name,
1382 params.target_url,
1383 partition_id,
1384 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011385 if (route_id != MSG_ROUTING_NONE &&
1386 !RenderViewHost::FromID(render_process_id, route_id)) {
1387 // If the embedder didn't create a WebContents for this route, we need to
1388 // delete the RenderView that had already been created.
1389 Send(new ViewMsg_Close(route_id));
1390 }
[email protected]dd6730412013-08-14 15:03:371391 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1392 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1393 main_frame_route_id);
1394 return;
1395 }
1396
1397 // Create the new web contents. This will automatically create the new
1398 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461399 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591400 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041401 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061402 create_params.opener = this;
1403 create_params.opener_suppressed = params.opener_suppressed;
1404 if (params.disposition == NEW_BACKGROUND_TAB)
1405 create_params.initially_hidden = true;
1406
[email protected]c4538072013-03-18 02:17:551407 if (!is_guest) {
1408 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451409 create_params.initial_size = GetContainerBounds().size();
[email protected]c4538072013-03-18 02:17:551410 } else {
[email protected]50d326e2014-05-20 17:59:061411 create_params.guest_instance_id =
[email protected]139355f2014-05-11 14:21:281412 GetBrowserContext()->GetGuestManager()->GetNextInstanceID();
[email protected]c4538072013-03-18 02:17:551413 }
[email protected]50d326e2014-05-20 17:59:061414 WebContentsImpl* new_contents = static_cast<WebContentsImpl*>(
1415 WebContents::Create(create_params));
1416 new_contents->GetController().SetSessionStorageNamespace(
1417 partition_id,
1418 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261419 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191420
[email protected]c4538072013-03-18 02:17:551421 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341422 // will be shown immediately).
1423 if (!params.opener_suppressed) {
1424 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451425 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501426
[email protected]d70bea92013-04-05 04:23:341427 // TODO(brettw): It seems bogus that we have to call this function on the
1428 // newly created object and give it one of its own member variables.
1429 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1430 }
[email protected]bafe6cd2012-05-23 23:09:501431 // Save the created window associated with the route so we can show it
1432 // later.
1433 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1434 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101435 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501436 }
1437
1438 if (delegate_) {
1439 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071440 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131441 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501442 }
1443
1444 if (params.opener_suppressed) {
1445 // When the opener is suppressed, the original renderer cannot access the
1446 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001447 bool was_blocked = false;
1448 if (delegate_) {
1449 gfx::Rect initial_pos;
1450 delegate_->AddNewContents(
1451 this, new_contents, params.disposition, initial_pos,
1452 params.user_gesture, &was_blocked);
1453 }
1454 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211455 OpenURLParams open_params(params.target_url,
1456 Referrer(),
1457 CURRENT_TAB,
1458 PAGE_TRANSITION_LINK,
1459 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301460 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001461 new_contents->OpenURL(open_params);
1462 }
[email protected]bafe6cd2012-05-23 23:09:501463 }
1464}
1465
[email protected]a8504022013-12-04 20:23:511466void WebContentsImpl::CreateNewWidget(int render_process_id,
1467 int route_id,
[email protected]180ef242013-11-07 06:50:461468 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511469 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501470}
1471
[email protected]a8504022013-12-04 20:23:511472void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1473 int route_id) {
1474 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501475}
1476
[email protected]a8504022013-12-04 20:23:511477void WebContentsImpl::CreateNewWidget(int render_process_id,
1478 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501479 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461480 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211481 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511482 // A message to create a new widget can only come from the active process for
1483 // this WebContentsImpl instance. If any other process sends the request,
1484 // it is invalid and the process must be terminated.
1485 if (process->GetID() != render_process_id) {
1486 base::ProcessHandle process_handle =
1487 RenderProcessHost::FromID(render_process_id)->GetHandle();
1488 if (process_handle != base::kNullProcessHandle) {
1489 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391490 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511491 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1492 }
1493 return;
1494 }
1495
[email protected]bafe6cd2012-05-23 23:09:501496 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041497 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261498 created_widgets_.insert(widget_host);
1499
[email protected]cfd80b02014-05-01 17:46:481500 RenderWidgetHostViewBase* widget_view =
1501 static_cast<RenderWidgetHostViewBase*>(
1502 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191503 if (!widget_view)
1504 return;
[email protected]bafe6cd2012-05-23 23:09:501505 if (!is_fullscreen) {
1506 // Popups should not get activated.
1507 widget_view->SetPopupType(popup_type);
1508 }
1509 // Save the created widget associated with the route so we can show it later.
1510 pending_widget_views_[route_id] = widget_view;
1511
1512#if defined(OS_MACOSX)
1513 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1514 // to allow it to survive the trip without being hosted.
1515 base::mac::NSObjectRetain(widget_view->GetNativeView());
1516#endif
1517}
1518
1519void WebContentsImpl::ShowCreatedWindow(int route_id,
1520 WindowOpenDisposition disposition,
1521 const gfx::Rect& initial_pos,
1522 bool user_gesture) {
1523 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001524 if (contents) {
1525 WebContentsDelegate* delegate = GetDelegate();
1526 if (delegate) {
1527 delegate->AddNewContents(
1528 this, contents, disposition, initial_pos, user_gesture, NULL);
1529 }
1530 }
[email protected]bafe6cd2012-05-23 23:09:501531}
1532
1533void WebContentsImpl::ShowCreatedWidget(int route_id,
1534 const gfx::Rect& initial_pos) {
1535 ShowCreatedWidget(route_id, false, initial_pos);
1536}
1537
1538void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1539 ShowCreatedWidget(route_id, true, gfx::Rect());
1540}
1541
1542void WebContentsImpl::ShowCreatedWidget(int route_id,
1543 bool is_fullscreen,
1544 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481545 RenderWidgetHostViewBase* widget_host_view =
1546 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501547 if (!widget_host_view)
1548 return;
[email protected]cfd80b02014-05-01 17:46:481549
1550 RenderWidgetHostView* view = NULL;
1551 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1552 if (guest && guest->embedder_web_contents()) {
1553 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1554 } else {
1555 view = GetRenderWidgetHostView();
1556 }
1557
[email protected]4aebbca2013-09-17 22:26:491558 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311559 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1560 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491561 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1562 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1563 delegate_->ToggleFullscreenModeForTab(this, true);
1564 } else {
[email protected]cfd80b02014-05-01 17:46:481565 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491566 }
[email protected]4aebbca2013-09-17 22:26:491567 FOR_EACH_OBSERVER(WebContentsObserver,
1568 observers_,
1569 DidShowFullscreenWidget(route_id));
1570 if (!widget_host_view->HasFocus())
1571 widget_host_view->Focus();
1572 } else {
[email protected]cfd80b02014-05-01 17:46:481573 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491574 }
[email protected]89054502012-06-03 10:29:241575
1576 RenderWidgetHostImpl* render_widget_host_impl =
1577 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1578 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311579 // Only allow privileged mouse lock for fullscreen render widget, which is
1580 // used to implement Pepper Flash fullscreen.
1581 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501582
1583#if defined(OS_MACOSX)
1584 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1585 // properly embedded (or purposefully ignored) we can release the retain we
1586 // took in CreateNewWidget().
1587 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1588#endif
1589}
1590
1591WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1592 PendingContents::iterator iter = pending_contents_.find(route_id);
1593
1594 // Certain systems can block the creation of new windows. If we didn't succeed
1595 // in creating one, just return NULL.
1596 if (iter == pending_contents_.end()) {
1597 return NULL;
1598 }
1599
1600 WebContentsImpl* new_contents = iter->second;
1601 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101602 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501603
[email protected]d70bea92013-04-05 04:23:341604 // Don't initialize the guest WebContents immediately.
1605 if (new_contents->GetRenderProcessHost()->IsGuest())
1606 return new_contents;
1607
[email protected]bafe6cd2012-05-23 23:09:501608 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1609 !new_contents->GetRenderViewHost()->GetView())
1610 return NULL;
1611
1612 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1613 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1614 return new_contents;
1615}
1616
1617RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1618 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1619 if (iter == pending_widget_views_.end()) {
1620 DCHECK(false);
1621 return NULL;
1622 }
1623
1624 RenderWidgetHostView* widget_host_view = iter->second;
1625 pending_widget_views_.erase(route_id);
1626
1627 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1628 if (!widget_host->GetProcess()->HasConnection()) {
1629 // The view has gone away or the renderer crashed. Nothing to do.
1630 return NULL;
1631 }
1632
1633 return widget_host_view;
1634}
1635
[email protected]f13b4202012-06-12 23:53:231636void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091637 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211638 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371639 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231640 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371641 } else {
1642 callback.Run(MediaStreamDevices(),
1643 MEDIA_DEVICE_INVALID_STATE,
1644 scoped_ptr<MediaStreamUI>());
1645 }
[email protected]f13b4202012-06-12 23:53:231646}
1647
[email protected]cc9200432013-07-23 23:02:401648SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1649 SiteInstance* instance) {
1650 return controller_.GetSessionStorageNamespace(instance);
1651}
1652
[email protected]9b159a52013-10-03 17:24:551653FrameTree* WebContentsImpl::GetFrameTree() {
1654 return &frame_tree_;
1655}
1656
[email protected]31a71eaf2014-03-13 01:47:361657void WebContentsImpl::AccessibilityEventReceived(
1658 const std::vector<AXEventNotificationDetails>& details) {
1659 FOR_EACH_OBSERVER(
1660 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1661}
1662
[email protected]edc3af82013-12-12 21:24:071663void WebContentsImpl::OnShowValidationMessage(
1664 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291665 const base::string16& main_text,
1666 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071667 if (delegate_)
1668 delegate_->ShowValidationMessage(
1669 this, anchor_in_root_view, main_text, sub_text);
1670}
1671
1672void WebContentsImpl::OnHideValidationMessage() {
1673 if (delegate_)
1674 delegate_->HideValidationMessage(this);
1675}
1676
1677void WebContentsImpl::OnMoveValidationMessage(
1678 const gfx::Rect& anchor_in_root_view) {
1679 if (delegate_)
1680 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1681}
1682
[email protected]32deec62013-05-15 23:55:041683void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1684 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441685 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041686}
1687
[email protected]b172aee2012-04-10 17:05:261688void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491689 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231690 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491691 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331692}
1693
[email protected]b172aee2012-04-10 17:05:261694void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341695 if (delegate_)
1696 delegate_->ResizeDueToAutoResize(this, new_size);
1697}
1698
[email protected]b172aee2012-04-10 17:05:261699WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201700 if (!delegate_)
1701 return NULL;
[email protected]00c37fc2011-08-02 00:22:501702
[email protected]e5d549d2011-12-28 01:29:201703 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201704 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341705}
1706
[email protected]6b618e62012-08-16 12:59:181707bool WebContentsImpl::Send(IPC::Message* message) {
1708 if (!GetRenderViewHost()) {
1709 delete message;
1710 return false;
1711 }
1712
1713 return GetRenderViewHost()->Send(message);
1714}
1715
[email protected]b172aee2012-04-10 17:05:261716bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501717 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261718 FrameTreeNode* node = frame_tree_.root();
1719
1720 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1721 // specified in the pending entry.
1722 NavigationEntryImpl* pending_entry =
1723 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1724 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1725 pending_entry->frame_tree_node_id() != -1) {
1726 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1727 }
1728
1729 return node->navigator()->NavigateToPendingEntry(
1730 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541731}
[email protected]96d185d2009-04-24 03:28:541732
[email protected]a86c0e962013-12-17 17:10:391733void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1734 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441735 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391736 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441737}
1738
[email protected]20ca0382013-02-28 19:50:071739void WebContentsImpl::AttachInterstitialPage(
1740 InterstitialPageImpl* interstitial_page) {
1741 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211742 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291743
1744 // Cancel any visible dialogs so that they don't interfere with the
1745 // interstitial.
1746 if (dialog_manager_)
1747 dialog_manager_->CancelActiveAndPendingDialogs(this);
1748
[email protected]20ca0382013-02-28 19:50:071749 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1750 DidAttachInterstitialPage());
1751}
1752
1753void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571754 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211755 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071756 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1757 DidDetachInterstitialPage());
1758}
1759
[email protected]b172aee2012-04-10 17:05:261760void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331761 const SiteInstance* site_instance,
1762 int history_length,
1763 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411764 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1765 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211766 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191767 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141768 return;
[email protected]9e1ad4b2011-08-14 16:49:191769 }
[email protected]9f76c1e2012-03-05 15:15:581770 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191771 if (!rvh) {
1772 NOTREACHED();
1773 return;
1774 }
[email protected]9f76c1e2012-03-05 15:15:581775 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191776 NOTREACHED();
1777 return;
1778 }
[email protected]6b618e62012-08-16 12:59:181779 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1780 history_length,
1781 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141782}
1783
[email protected]4fed3702014-04-01 09:08:001784void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171785 RenderFrameHost* focused_frame = GetFocusedFrame();
1786 if (!focused_frame)
1787 return;
1788
[email protected]959be4c2014-04-08 15:01:331789 focused_frame->Send(new FrameMsg_Reload(
1790 focused_frame->GetRoutingID(), ignore_cache));
1791}
1792
1793void WebContentsImpl::Undo() {
1794 RenderFrameHost* focused_frame = GetFocusedFrame();
1795 if (!focused_frame)
1796 return;
1797
1798 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1799 RecordAction(base::UserMetricsAction("Undo"));
1800}
1801
1802void WebContentsImpl::Redo() {
1803 RenderFrameHost* focused_frame = GetFocusedFrame();
1804 if (!focused_frame)
1805 return;
1806 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1807 RecordAction(base::UserMetricsAction("Redo"));
1808}
1809
1810void WebContentsImpl::Cut() {
1811 RenderFrameHost* focused_frame = GetFocusedFrame();
1812 if (!focused_frame)
1813 return;
1814
1815 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1816 RecordAction(base::UserMetricsAction("Cut"));
1817}
1818
1819void WebContentsImpl::Copy() {
1820 RenderFrameHost* focused_frame = GetFocusedFrame();
1821 if (!focused_frame)
1822 return;
1823
1824 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1825 RecordAction(base::UserMetricsAction("Copy"));
1826}
1827
1828void WebContentsImpl::CopyToFindPboard() {
1829#if defined(OS_MACOSX)
1830 RenderFrameHost* focused_frame = GetFocusedFrame();
1831 if (!focused_frame)
1832 return;
1833
1834 // Windows/Linux don't have the concept of a find pasteboard.
1835 focused_frame->Send(
1836 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1837 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1838#endif
1839}
1840
1841void WebContentsImpl::Paste() {
1842 RenderFrameHost* focused_frame = GetFocusedFrame();
1843 if (!focused_frame)
1844 return;
1845
1846 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1847 RecordAction(base::UserMetricsAction("Paste"));
1848}
1849
1850void WebContentsImpl::PasteAndMatchStyle() {
1851 RenderFrameHost* focused_frame = GetFocusedFrame();
1852 if (!focused_frame)
1853 return;
1854
1855 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1856 focused_frame->GetRoutingID()));
1857 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1858}
1859
1860void WebContentsImpl::Delete() {
1861 RenderFrameHost* focused_frame = GetFocusedFrame();
1862 if (!focused_frame)
1863 return;
1864
1865 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1866 RecordAction(base::UserMetricsAction("DeleteSelection"));
1867}
1868
1869void WebContentsImpl::SelectAll() {
1870 RenderFrameHost* focused_frame = GetFocusedFrame();
1871 if (!focused_frame)
1872 return;
1873
1874 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1875 RecordAction(base::UserMetricsAction("SelectAll"));
1876}
1877
1878void WebContentsImpl::Unselect() {
1879 RenderFrameHost* focused_frame = GetFocusedFrame();
1880 if (!focused_frame)
1881 return;
1882
1883 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1884 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171885}
1886
1887void WebContentsImpl::Replace(const base::string16& word) {
1888 RenderFrameHost* focused_frame = GetFocusedFrame();
1889 if (!focused_frame)
1890 return;
1891
[email protected]959be4c2014-04-08 15:01:331892 focused_frame->Send(new InputMsg_Replace(
1893 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171894}
1895
1896void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1897 RenderFrameHost* focused_frame = GetFocusedFrame();
1898 if (!focused_frame)
1899 return;
1900
[email protected]959be4c2014-04-08 15:01:331901 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1902 focused_frame->GetRoutingID(), word));
1903}
1904
1905void WebContentsImpl::NotifyContextMenuClosed(
1906 const CustomContextMenuContext& context) {
1907 RenderFrameHost* focused_frame = GetFocusedFrame();
1908 if (!focused_frame)
1909 return;
1910
1911 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1912 focused_frame->GetRoutingID(), context));
1913}
1914
1915void WebContentsImpl::ExecuteCustomContextMenuCommand(
1916 int action, const CustomContextMenuContext& context) {
1917 RenderFrameHost* focused_frame = GetFocusedFrame();
1918 if (!focused_frame)
1919 return;
1920
1921 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1922 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001923}
1924
[email protected]fc2b46b2014-05-03 16:33:451925gfx::NativeView WebContentsImpl::GetNativeView() {
1926 return view_->GetNativeView();
1927}
1928
1929gfx::NativeView WebContentsImpl::GetContentNativeView() {
1930 return view_->GetContentNativeView();
1931}
1932
1933gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1934 return view_->GetTopLevelNativeWindow();
1935}
1936
1937gfx::Rect WebContentsImpl::GetViewBounds() {
1938 return view_->GetViewBounds();
1939}
1940
1941gfx::Rect WebContentsImpl::GetContainerBounds() {
1942 gfx::Rect rv;
1943 view_->GetContainerBounds(&rv);
1944 return rv;
1945}
1946
1947DropData* WebContentsImpl::GetDropData() {
1948 return view_->GetDropData();
1949}
1950
1951void WebContentsImpl::Focus() {
1952 view_->Focus();
1953}
1954
1955void WebContentsImpl::SetInitialFocus() {
1956 view_->SetInitialFocus();
1957}
1958
1959void WebContentsImpl::StoreFocus() {
1960 view_->StoreFocus();
1961}
1962
1963void WebContentsImpl::RestoreFocus() {
1964 view_->RestoreFocus();
1965}
1966
[email protected]b172aee2012-04-10 17:05:261967void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271968 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211969 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541970 return;
1971 }
[email protected]9f76c1e2012-03-05 15:15:581972 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541973}
1974
[email protected]b172aee2012-04-10 17:05:261975bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211976 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541977}
1978
[email protected]b172aee2012-04-10 17:05:261979InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211980 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221981}
1982
[email protected]b172aee2012-04-10 17:05:261983bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161984 // WebKit creates Document object when MIME type is application/xhtml+xml,
1985 // so we also support this MIME type.
1986 return contents_mime_type_ == "text/html" ||
1987 contents_mime_type_ == "text/xml" ||
1988 contents_mime_type_ == "application/xhtml+xml" ||
1989 contents_mime_type_ == "text/plain" ||
1990 contents_mime_type_ == "text/css" ||
1991 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1992}
1993
[email protected]b172aee2012-04-10 17:05:261994void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591995 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161996 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551997 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011998 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141999 return;
[email protected]c7dd2f62011-07-18 15:57:592000 }
2001
2002 Stop();
2003
2004 // Create the save package and possibly prompt the user for the name to save
2005 // the page as. The user prompt is an asynchronous operation that runs on
2006 // another thread.
2007 save_package_ = new SavePackage(this);
2008 save_package_->GetSaveInfo();
2009}
2010
2011// Used in automated testing to bypass prompting the user for file names.
2012// Instead, the names and paths are hard coded rather than running them through
2013// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342014bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2015 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212016 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592017 // Stop the page from navigating.
2018 Stop();
2019
2020 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212021 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592022}
2023
[email protected]3c71576ce2013-07-23 02:00:012024void WebContentsImpl::SaveFrame(const GURL& url,
2025 const Referrer& referrer) {
2026 if (!GetURL().is_valid())
2027 return;
2028 bool is_main_frame = (url == GetURL());
2029
2030 DownloadManager* dlm =
2031 BrowserContext::GetDownloadManager(GetBrowserContext());
2032 if (!dlm)
2033 return;
2034 int64 post_id = -1;
2035 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272036 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012037 if (entry)
2038 post_id = entry->GetPostID();
2039 }
2040 scoped_ptr<DownloadUrlParameters> params(
2041 DownloadUrlParameters::FromWebContents(this, url));
2042 params->set_referrer(referrer);
2043 params->set_post_id(post_id);
2044 params->set_prefer_cache(true);
2045 if (post_id >= 0)
2046 params->set_method("POST");
2047 params->set_prompt(true);
2048 dlm->DownloadUrl(params.Pass());
2049}
2050
[email protected]b172aee2012-04-10 17:05:262051void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342052 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482053 const base::Callback<void(int64)>& callback) {
2054 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122055}
2056
[email protected]6286a372013-10-09 04:03:272057// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262058bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272059 NavigationEntryImpl* visible_entry =
2060 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2061 return (visible_entry != NULL &&
2062 visible_entry->site_instance() == GetSiteInstance() &&
2063 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322064}
2065
[email protected]b172aee2012-04-10 17:05:262066const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272067 return contents_mime_type_;
2068}
2069
[email protected]b172aee2012-04-10 17:05:262070bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272071 return notify_disconnection_;
2072}
2073
[email protected]b172aee2012-04-10 17:05:262074void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312075 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182076 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162077}
2078
[email protected]b172aee2012-04-10 17:05:262079void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542080 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182081 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162082}
2083
[email protected]8ff00d72012-10-23 19:12:212084RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272085 return &renderer_preferences_;
2086}
2087
[email protected]e35ccd52012-05-23 16:22:472088void WebContentsImpl::Close() {
2089 Close(GetRenderViewHost());
2090}
2091
[email protected]cf200a562013-05-03 16:24:292092void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462093 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292094 if (browser_plugin_embedder_.get())
2095 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2096 screen_x, screen_y, operation);
2097 if (GetRenderViewHost())
2098 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2099 screen_x, screen_y, operation);
2100}
2101
[email protected]d60f3702013-12-26 16:30:242102void WebContentsImpl::DidGetResourceResponseStart(
2103 const ResourceRequestDetails& details) {
2104 controller_.ssl_manager()->DidStartResourceResponse(details);
2105
2106 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2107 DidGetResourceResponseStart(details));
2108
2109 // TODO(avi): Remove. http://crbug.com/170921
2110 NotificationService::current()->Notify(
2111 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2112 Source<WebContents>(this),
2113 Details<const ResourceRequestDetails>(&details));
2114}
2115
2116void WebContentsImpl::DidGetRedirectForResourceRequest(
2117 RenderViewHost* render_view_host,
2118 const ResourceRedirectDetails& details) {
2119 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2120
2121 FOR_EACH_OBSERVER(
2122 WebContentsObserver,
2123 observers_,
2124 DidGetRedirectForResourceRequest(render_view_host, details));
2125
2126 // TODO(avi): Remove. http://crbug.com/170921
2127 NotificationService::current()->Notify(
2128 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2129 Source<WebContents>(this),
2130 Details<const ResourceRedirectDetails>(&details));
2131}
2132
[email protected]b172aee2012-04-10 17:05:262133void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522134 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582135 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512136 if (delegate_)
2137 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292138 if (browser_plugin_embedder_.get())
2139 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342140}
2141
[email protected]e35ccd52012-05-23 16:22:472142void WebContentsImpl::UserGestureDone() {
2143 OnUserGesture();
2144}
2145
[email protected]b172aee2012-04-10 17:05:262146void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272147 closed_by_user_gesture_ = value;
2148}
2149
[email protected]b172aee2012-04-10 17:05:262150bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272151 return closed_by_user_gesture_;
2152}
2153
[email protected]b172aee2012-04-10 17:05:262154double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052155 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562156 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252157 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172158 return 0;
[email protected]b75b8292010-10-01 07:28:252159
2160 double zoom_level;
2161 if (temporary_zoom_settings_) {
2162 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582163 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252164 } else {
[email protected]2ae88d12011-10-14 09:11:192165 GURL url;
[email protected]6286a372013-10-09 04:03:272166 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192167 // Since zoom map is updated using rewritten URL, use rewritten URL
2168 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272169 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022170 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2171 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252172 }
[email protected]d0b8d092010-10-25 04:05:172173 return zoom_level;
2174}
[email protected]b75b8292010-10-01 07:28:252175
[email protected]b172aee2012-04-10 17:05:262176int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592177 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172178 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012179 // Calculate the zoom percent from the factor. Round up to the nearest whole
2180 // number.
[email protected]b75b8292010-10-01 07:28:252181 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492182 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252183 *enable_decrement = percent > minimum_zoom_percent_;
2184 *enable_increment = percent < maximum_zoom_percent_;
2185 return percent;
2186}
2187
[email protected]b172aee2012-04-10 17:05:262188void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502189 if (!delegate_)
2190 return;
2191
[email protected]6286a372013-10-09 04:03:272192 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2193 if (!entry)
[email protected]1788e772010-12-15 16:40:502194 return;
2195
[email protected]6286a372013-10-09 04:03:272196 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122197}
2198
[email protected]b172aee2012-04-10 17:05:262199void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042200 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272201 if (!delegate_)
2202 return;
2203
[email protected]691aa2f2013-05-28 22:52:042204 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272205}
2206
[email protected]b172aee2012-04-10 17:05:262207int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272208 return minimum_zoom_percent_;
2209}
2210
[email protected]b172aee2012-04-10 17:05:262211int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272212 return maximum_zoom_percent_;
2213}
2214
[email protected]b172aee2012-04-10 17:05:262215gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492216 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232217}
2218
[email protected]b172aee2012-04-10 17:05:262219bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052220 if (GetBrowserPluginGuest())
2221 return GetBrowserPluginGuest()->LockMouse(allowed);
2222
[email protected]0bfbf882011-12-22 18:19:272223 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582224 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272225}
2226
[email protected]b172aee2012-04-10 17:05:262227bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442228 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502229}
2230
[email protected]cb805452013-05-22 15:16:212231void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482232 if (!color_chooser_info_.get())
2233 return;
2234 RenderFrameHost* rfh = RenderFrameHost::FromID(
2235 color_chooser_info_->render_process_id,
2236 color_chooser_info_->render_frame_id);
2237 if (!rfh)
2238 return;
2239
2240 rfh->Send(new FrameMsg_DidChooseColorResponse(
2241 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202242}
2243
[email protected]cb805452013-05-22 15:16:212244void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482245 if (!color_chooser_info_.get())
2246 return;
2247 RenderFrameHost* rfh = RenderFrameHost::FromID(
2248 color_chooser_info_->render_process_id,
2249 color_chooser_info_->render_frame_id);
2250 if (!rfh)
2251 return;
2252
2253 rfh->Send(new FrameMsg_DidEndColorChooser(
2254 rfh->GetRoutingID(), color_chooser_info_->identifier));
2255 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202256}
2257
[email protected]41225fe2013-03-29 05:32:022258int WebContentsImpl::DownloadImage(const GURL& url,
2259 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302260 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022261 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582262 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022263 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392264 return id;
2265}
2266
[email protected]5dcaf8e2013-12-28 01:31:422267bool WebContentsImpl::IsSubframe() const {
2268 return is_subframe_;
2269}
2270
[email protected]9649d492014-01-10 07:15:522271void WebContentsImpl::SetZoomLevel(double level) {
2272 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2273 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2274 if (embedder)
2275 embedder->SetZoomLevel(level);
2276}
2277
[email protected]36ec24f2014-01-09 00:32:082278void WebContentsImpl::Find(int request_id,
2279 const base::string16& search_text,
2280 const blink::WebFindOptions& options) {
2281 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2282}
2283
2284void WebContentsImpl::StopFinding(StopFindAction action) {
2285 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2286}
2287
[email protected]4fe53add2014-04-08 19:53:362288void WebContentsImpl::InsertCSS(const std::string& css) {
2289 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2290 GetMainFrame()->GetRoutingID(), css));
2291}
2292
[email protected]b172aee2012-04-10 17:05:262293bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272294 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202295 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332296 return true;
2297 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272298}
2299
[email protected]b172aee2012-04-10 17:05:262300void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272301 if (delegate_)
2302 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212303}
2304
[email protected]52913802013-12-10 05:52:182305void WebContentsImpl::DidStartProvisionalLoad(
2306 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072307 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182308 const GURL& validated_url,
2309 bool is_error_page,
2310 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262311 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]d974a0a2013-01-10 01:43:572312
[email protected]0d60f0192011-04-14 12:40:102313 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272314 int render_frame_id = render_frame_host->GetRoutingID();
2315 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252316 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072317 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272318 render_frame_id, parent_routing_id, is_main_frame,
2319 validated_url, is_error_page, is_iframe_srcdoc,
2320 render_view_host));
[email protected]400992b2012-06-14 00:03:542321
2322 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182323 FOR_EACH_OBSERVER(
2324 WebContentsObserver,
2325 observers_,
2326 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582327 render_frame_host));
[email protected]400992b2012-06-14 00:03:542328 }
2329}
2330
[email protected]3109fbb72014-01-06 23:57:152331void WebContentsImpl::DidFailProvisionalLoadWithError(
2332 RenderFrameHostImpl* render_frame_host,
2333 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2334 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272335 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262336 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272337 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152338 FOR_EACH_OBSERVER(
2339 WebContentsObserver,
2340 observers_,
[email protected]161eabd2014-03-19 19:47:272341 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152342 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262343 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152344 validated_url,
2345 params.error_code,
2346 params.error_description,
[email protected]161eabd2014-03-19 19:47:272347 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152348}
2349
[email protected]b80624c2014-02-09 02:46:552350void WebContentsImpl::DidFailLoadWithError(
2351 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552352 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552353 int error_code,
2354 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272355 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262356 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272357 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552358 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272359 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262360 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552361}
2362
[email protected]52913802013-12-10 05:52:182363void WebContentsImpl::NotifyChangedNavigationState(
2364 InvalidateTypes changed_flags) {
2365 NotifyNavigationStateChanged(changed_flags);
2366}
2367
[email protected]3691e5cf2014-01-22 10:16:202368void WebContentsImpl::AboutToNavigateRenderFrame(
2369 RenderFrameHostImpl* render_frame_host) {
2370 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272371 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202372 FOR_EACH_OBSERVER(
2373 WebContentsObserver,
2374 observers_,
[email protected]161eabd2014-03-19 19:47:272375 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202376}
2377
2378void WebContentsImpl::DidStartNavigationToPendingEntry(
2379 RenderFrameHostImpl* render_frame_host,
2380 const GURL& url,
2381 NavigationController::ReloadType reload_type) {
2382 // Notify observers about navigation.
2383 FOR_EACH_OBSERVER(
2384 WebContentsObserver,
2385 observers_,
2386 DidStartNavigationToPendingEntry(url, reload_type));
2387}
2388
[email protected]8cb834e2014-03-06 14:23:232389void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2390 const OpenURLParams& params) {
2391 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182392 WebContents* new_contents = OpenURL(params);
2393
2394 if (new_contents) {
2395 // Notify observers.
2396 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2397 DidOpenRequestedURL(new_contents,
2398 params.url,
2399 params.referrer,
2400 params.disposition,
2401 params.transition,
[email protected]8cb834e2014-03-06 14:23:232402 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182403 }
2404}
2405
[email protected]aa62afd2014-04-22 19:22:462406bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2407 if (!delegate_)
2408 return false;
2409 return delegate_->ShouldPreserveAbortedURLs(this);
2410}
2411
[email protected]400992b2012-06-14 00:03:542412void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582413 RenderFrameHostImpl* render_frame_host,
2414 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542415 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582416 FOR_EACH_OBSERVER(
2417 WebContentsObserver,
2418 observers_,
2419 ProvisionalChangeToMainFrameUrl(validated_target_url,
2420 render_frame_host));
[email protected]724159a2010-12-30 01:11:182421}
2422
[email protected]37567b432014-02-12 01:12:222423void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432424 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222425 const base::string16& frame_unique_name,
2426 bool is_main_frame,
2427 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432428 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432429 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272430 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222431 // Notify observers about the commit of the provisional load.
2432 FOR_EACH_OBSERVER(
2433 WebContentsObserver,
2434 observers_,
[email protected]27dd82fd2014-03-03 22:11:432435 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222436 frame_unique_name,
2437 is_main_frame,
2438 url,
2439 transition_type,
2440 render_view_host));
2441}
2442
[email protected]0d0f4c492014-04-02 06:42:572443void WebContentsImpl::DidNavigateMainFramePreCommit(
2444 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2445 // Ensure fullscreen mode is exited before committing the navigation to a
2446 // different page. The next page will not start out assuming it is in
2447 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192448 if (controller_.IsURLInPageNavigation(params.url,
2449 params.was_within_same_page,
2450 NAVIGATION_TYPE_UNKNOWN)) {
2451 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572452 return;
2453 }
2454 if (IsFullscreenForCurrentTab())
2455 GetRenderViewHost()->ExitFullscreen();
2456 DCHECK(!IsFullscreenForCurrentTab());
2457}
2458
[email protected]37567b432014-02-12 01:12:222459void WebContentsImpl::DidNavigateMainFramePostCommit(
2460 const LoadCommittedDetails& details,
2461 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2462 if (details.is_navigation_to_different_page()) {
2463 // Clear the status bubble. This is a workaround for a bug where WebKit
2464 // doesn't let us know that the cursor left an element during a
2465 // transition (this is also why the mouse cursor remains as a hand after
2466 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2467 // clear the bubble when a user navigates to a named anchor in the same
2468 // page.
2469 UpdateTargetURL(details.entry->GetPageID(), GURL());
2470 }
2471
2472 if (!details.is_in_page) {
2473 // Once the main frame is navigated, we're no longer considered to have
2474 // displayed insecure content.
2475 displayed_insecure_content_ = false;
2476 SSLManager::NotifySSLInternalStateChanged(
2477 GetController().GetBrowserContext());
2478 }
2479
2480 // Notify observers about navigation.
2481 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2482 DidNavigateMainFrame(details, params));
2483
2484 if (delegate_) {
2485 delegate_->DidNavigateMainFramePostCommit(this);
2486 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2487 }
2488}
2489
2490void WebContentsImpl::DidNavigateAnyFramePostCommit(
2491 RenderFrameHostImpl* render_frame_host,
2492 const LoadCommittedDetails& details,
2493 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102494 // Now that something has committed, we don't need to track whether the
2495 // initial page has been accessed.
2496 has_accessed_initial_document_ = false;
2497
[email protected]37567b432014-02-12 01:12:222498 // If we navigate off the page, close all JavaScript dialogs.
2499 if (dialog_manager_ && !details.is_in_page)
2500 dialog_manager_->CancelActiveAndPendingDialogs(this);
2501
2502 // Notify observers about navigation.
2503 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2504 DidNavigateAnyFrame(details, params));
2505}
2506
2507void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2508 contents_mime_type_ = mime_type;
2509}
2510
2511bool WebContentsImpl::CanOverscrollContent() {
2512 if (delegate_)
2513 return delegate_->CanOverscrollContent();
2514
2515 return false;
2516}
2517
[email protected]b172aee2012-04-10 17:05:262518void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182519 const GURL& url,
[email protected]70435962011-08-02 20:13:282520 const std::string& security_info,
2521 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182522 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282523 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192524 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182525 cache.Increment();
2526
2527 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082528 int cert_id = 0;
2529 net::CertStatus cert_status = 0;
2530 int security_bits = -1;
2531 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122532 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212533 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122534 &security_bits, &connection_status,
2535 &signed_certificate_timestamp_ids);
2536 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212537 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002538 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2539 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182540
[email protected]b0f724c2013-09-05 04:21:132541 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2542
2543 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2544 DidLoadResourceFromMemoryCache(details));
2545
[email protected]8bfc8272013-09-09 20:10:532546 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2547 scoped_refptr<net::URLRequestContextGetter> request_context(
2548 resource_type == ResourceType::MEDIA ?
2549 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2550 GetRenderProcessHost()->GetID()) :
2551 GetBrowserContext()->GetRequestContextForRenderProcess(
2552 GetRenderProcessHost()->GetID()));
2553 BrowserThread::PostTask(
2554 BrowserThread::IO,
2555 FROM_HERE,
2556 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2557 }
[email protected]724159a2010-12-30 01:11:182558}
2559
[email protected]b172aee2012-04-10 17:05:262560void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392561 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182562 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192563 SSLManager::NotifySSLInternalStateChanged(
2564 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182565}
2566
[email protected]b172aee2012-04-10 17:05:262567void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022568 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582569 LOG(WARNING) << security_origin << " ran insecure content from "
2570 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392571 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412572 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392573 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182574 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412575 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192576 SSLManager::NotifySSLInternalStateChanged(
2577 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182578}
2579
[email protected]501052ff2014-02-21 22:19:072580void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572581 CHECK(render_frame_message_source_);
2582 CHECK(!render_view_message_source_);
2583 RenderFrameHostImpl* rfh =
2584 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2585
[email protected]161eabd2014-03-19 19:47:272586 int render_frame_id = rfh->GetRoutingID();
2587 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572588 FOR_EACH_OBSERVER(WebContentsObserver,
2589 observers_,
[email protected]161eabd2014-03-19 19:47:272590 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182591}
2592
[email protected]b172aee2012-04-10 17:05:262593void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262594 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372595 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122596 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2597 GetRenderProcessHost()->ReceivedBadMessage();
2598 return;
2599 }
[email protected]a1b99262013-12-27 21:56:222600
[email protected]8b3af1e2014-01-24 13:29:122601 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442602 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372603 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422604 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372605
[email protected]61ac9e242014-03-21 20:55:262606 RenderFrameHostImpl* rfh =
2607 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272608 int render_frame_id = rfh->GetRoutingID();
2609 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262610 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252611 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272612 DidFinishLoad(render_frame_id, validated_url,
2613 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312614}
2615
[email protected]960b0372014-05-19 18:01:002616void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2617 RenderFrameHostImpl* rfh =
2618 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2619 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2620
2621 // It is possible to get multiple calls to OnDidStartLoading that don't have
2622 // corresponding calls to OnDidStopLoading:
2623 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2624 // out for a cross-process navigation, and it turns into a placeholder for
2625 // one being rendered in a different process.
2626 // - Also, there might be more than one RenderFrameHost sharing the same
2627 // FrameTreeNode (and thus sharing its ID) each sending a start.
2628 // - But in the future, once clamy@ moves navigation network requests to the
2629 // browser process, there's a good chance that callbacks about starting and
2630 // stopping will all be handled by the browser. When that happens, there
2631 // should no longer be a start/stop call imbalance. TODO(avi): When this
2632 // future arrives, update this code to not allow this case.
2633 DCHECK_GE(loading_frames_in_progress_, 0);
2634 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2635 if (loading_frames_in_progress_ == 0)
2636 DidStartLoading(rfh, to_different_document);
2637 ++loading_frames_in_progress_;
2638 }
2639
2640 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2641 SendLoadProgressChanged();
2642}
2643
2644void WebContentsImpl::OnDidStopLoading() {
2645 RenderFrameHostImpl* rfh =
2646 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2647 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2648
2649 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2650 // Load stopped while we were still tracking load. Make sure we update
2651 // progress based on this frame's completion.
2652 loading_progresses_[render_frame_id] = 1.0;
2653 SendLoadProgressChanged();
2654 // Then we clean-up our states.
2655 if (loading_total_progress_ == 1.0)
2656 ResetLoadProgressState();
2657 }
2658
2659 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2660 // calls DidStopLoading() without a matching DidStartLoading().
2661 if (loading_frames_in_progress_ == 0)
2662 return;
2663 --loading_frames_in_progress_;
2664 if (loading_frames_in_progress_ == 0)
2665 DidStopLoading(rfh);
2666}
2667
2668void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2669 RenderFrameHostImpl* rfh =
2670 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2671 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2672
2673 loading_progresses_[render_frame_id] = load_progress;
2674
2675 // We notify progress change immediately for the first and last updates.
2676 // Also, since the message loop may be pretty busy when a page is loaded, it
2677 // might not execute a posted task in a timely manner so we make sure to
2678 // immediately send progress report if enough time has passed.
2679 base::TimeDelta min_delay =
2680 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2681 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2682 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2683 // If there is a pending task to send progress, it is now obsolete.
2684 loading_weak_factory_.InvalidateWeakPtrs();
2685 SendLoadProgressChanged();
2686 if (loading_total_progress_ == 1.0)
2687 ResetLoadProgressState();
2688 return;
2689 }
2690
2691 if (loading_weak_factory_.HasWeakPtrs())
2692 return;
2693
2694 base::MessageLoop::current()->PostDelayedTask(
2695 FROM_HERE,
2696 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2697 loading_weak_factory_.GetWeakPtr()),
2698 min_delay);
2699}
2700
[email protected]b172aee2012-04-10 17:05:262701void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222702 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2703 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262704}
2705
[email protected]b172aee2012-04-10 17:05:262706void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2707 int maximum_percent,
2708 bool remember) {
[email protected]216813952011-05-19 22:21:262709 minimum_zoom_percent_ = minimum_percent;
2710 maximum_zoom_percent_ = maximum_percent;
2711 temporary_zoom_settings_ = !remember;
2712}
2713
[email protected]b172aee2012-04-10 17:05:262714void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342715 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432716 if (!delegate_)
2717 return;
2718
[email protected]b9535422012-02-09 01:47:592719 ChildProcessSecurityPolicyImpl* policy =
2720 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222721 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592722 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212723}
2724
[email protected]b172aee2012-04-10 17:05:262725void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2726 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262727 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362728 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432729 if (!delegate_)
2730 return;
2731
[email protected]b9535422012-02-09 01:47:592732 ChildProcessSecurityPolicyImpl* policy =
2733 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322734 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592735 return;
[email protected]8f810632013-06-06 22:33:322736
[email protected]c125e532014-05-10 20:39:062737 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202738}
2739
[email protected]b172aee2012-04-10 17:05:262740void WebContentsImpl::OnFindReply(int request_id,
2741 int number_of_matches,
2742 const gfx::Rect& selection_rect,
2743 int active_match_ordinal,
2744 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432745 if (delegate_) {
2746 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2747 active_match_ordinal, final_update);
2748 }
[email protected]b888919c2011-09-02 00:32:162749}
2750
[email protected]59363fc92012-09-05 03:46:312751#if defined(OS_ANDROID)
2752void WebContentsImpl::OnFindMatchRectsReply(
2753 int version,
2754 const std::vector<gfx::RectF>& rects,
2755 const gfx::RectF& active_rect) {
2756 if (delegate_)
2757 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2758}
[email protected]583418cc2013-01-17 14:01:102759
[email protected]1ff427972013-02-07 21:14:072760void WebContentsImpl::OnOpenDateTimeDialog(
2761 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092762 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2763 GetRenderViewHost(),
2764 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132765 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092766 value.minimum,
2767 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172768 value.step,
2769 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102770}
2771
[email protected]59363fc92012-09-05 03:46:312772#endif
2773
[email protected]f114fa42013-12-06 17:06:442774void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2775 const base::FilePath& path,
2776 bool is_hung) {
2777 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2778
2779 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2780 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2781}
2782
2783void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422784 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442785 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422786 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452787}
2788
[email protected]cfa856d62014-02-22 07:58:402789void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2790 int automation_id) {
2791 DomOperationNotificationDetails details(json_string, automation_id);
2792 NotificationService::current()->Notify(
2793 NOTIFICATION_DOM_OPERATION_RESPONSE,
2794 Source<WebContents>(this),
2795 Details<DomOperationNotificationDetails>(&details));
2796}
2797
[email protected]b172aee2012-04-10 17:05:262798void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2799 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102800 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252801 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102802 AppCacheAccessed(manifest_url, blocked_by_policy));
2803}
2804
[email protected]8bc5ff02013-11-29 06:34:032805void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482806 int color_chooser_id,
2807 SkColor color,
2808 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462809 ColorChooser* new_color_chooser = delegate_ ?
2810 delegate_->OpenColorChooser(this, color, suggestions) :
2811 NULL;
[email protected]820957a2014-01-14 14:56:302812 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212813 return;
[email protected]8ed16472014-04-11 19:02:482814 if (color_chooser_info_.get())
2815 color_chooser_info_->chooser->End();
2816
2817 color_chooser_info_.reset(new ColorChooserInfo(
2818 render_frame_message_source_->GetProcess()->GetID(),
2819 render_frame_message_source_->GetRoutingID(),
2820 new_color_chooser,
2821 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202822}
2823
[email protected]b172aee2012-04-10 17:05:262824void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482825 if (color_chooser_info_ &&
2826 color_chooser_id == color_chooser_info_->identifier)
2827 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202828}
2829
[email protected]b172aee2012-04-10 17:05:262830void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322831 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482832 if (color_chooser_info_ &&
2833 color_chooser_id == color_chooser_info_->identifier)
2834 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202835}
2836
[email protected]d0759f492012-04-19 22:50:502837// This exists for render views that don't have a WebUI, but do have WebUI
2838// bindings enabled.
2839void WebContentsImpl::OnWebUISend(const GURL& source_url,
2840 const std::string& name,
2841 const base::ListValue& args) {
2842 if (delegate_)
2843 delegate_->WebUISend(this, source_url, name, args);
2844}
2845
[email protected]d8415ad92012-08-23 14:40:502846void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442847 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502848 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342849 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162850 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442851 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162852 return;
[email protected]d8415ad92012-08-23 14:40:502853 }
2854
[email protected]8c8fc292012-11-23 18:57:162855 if (!delegate_->RequestPpapiBrokerPermission(
2856 this, url, plugin_path,
2857 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442858 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162859 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442860 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162861 }
[email protected]d8415ad92012-08-23 14:40:502862}
2863
[email protected]ea0309c2013-08-06 19:35:442864void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502865 bool result) {
[email protected]ea0309c2013-08-06 19:35:442866 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502867}
2868
[email protected]c4538072013-03-18 02:17:552869void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372870 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082871 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552872 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392873 // For more info, see comment above classes BrowserPluginEmbedder and
2874 // BrowserPluginGuest.
2875 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142876 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082877 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372878}
2879
[email protected]41225fe2013-03-29 05:32:022880void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392881 int id,
[email protected]749fadd2013-05-15 08:37:482882 int http_status_code,
[email protected]795c28972012-12-06 06:13:392883 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302884 const std::vector<SkBitmap>& bitmaps,
2885 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132886 if (bitmaps.size() != original_bitmap_sizes.size())
2887 return;
2888
[email protected]41225fe2013-03-29 05:32:022889 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2890 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392891 // Currently WebContents notifies us of ANY downloads so that it is
2892 // possible to get here.
2893 return;
2894 }
2895 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302896 iter->second.Run(
2897 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392898 }
[email protected]41225fe2013-03-29 05:32:022899 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392900}
2901
2902void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392903 const std::vector<FaviconURL>& candidates) {
2904 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292905 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392906}
2907
[email protected]1dd0bb752014-02-01 01:16:262908void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2909 bool has_video,
2910 bool has_audio) {
2911// Chrome OS does its own detection of audio and video.
2912#if !defined(OS_CHROMEOS)
2913 scoped_ptr<PowerSaveBlocker> blocker;
2914 if (has_video) {
2915 blocker = PowerSaveBlocker::Create(
2916 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2917#if defined(OS_ANDROID)
2918 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2919 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2920#endif
2921 } else if (has_audio) {
2922 blocker = PowerSaveBlocker::Create(
2923 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2924 }
2925
2926 if (blocker) {
[email protected]96307312014-05-04 01:00:192927 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262928 blocker.release();
2929 }
2930#endif // !defined(OS_CHROMEOS)
2931}
2932
2933void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062934 // Chrome OS does its own detection of audio and video.
2935#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192936 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2937 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062938#endif // !defined(OS_CHROMEOS)
2939}
2940
[email protected]50279492014-05-05 23:24:292941void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152942 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292943 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152944}
[email protected]d9030b82013-07-19 08:26:062945
[email protected]e67ebf32013-02-13 11:07:192946void WebContentsImpl::DidChangeVisibleSSLState() {
2947 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2948 DidChangeVisibleSSLState());
2949}
2950
[email protected]17e286e2013-03-01 23:29:392951void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2952 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2953 BeforeFormRepostWarningShow());
2954}
2955
[email protected]ec6c05f2013-10-23 18:41:572956
2957void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2958 Activate();
2959 if (delegate_)
2960 delegate_->ShowRepostFormWarningDialog(this);
2961}
2962
[email protected]b4c84012014-04-28 19:51:102963bool WebContentsImpl::HasAccessedInitialDocument() {
2964 return has_accessed_initial_document_;
2965}
2966
[email protected]96d185d2009-04-24 03:28:542967// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592968// loading, or done loading.
2969void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2970 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092971 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262972 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542973 if (is_loading == is_loading_)
2974 return;
2975
2976 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262977 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2978 base::string16());
[email protected]96d185d2009-04-24 03:28:542979 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562980 upload_size_ = 0;
2981 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542982 }
2983
[email protected]fa944cb82013-11-15 17:51:212984 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542985
2986 is_loading_ = is_loading;
2987 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:032988 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:542989
[email protected]6ebdc9b2010-09-27 16:55:572990 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092991 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212992 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542993
[email protected]eab61442013-11-14 18:35:482994 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592995 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482996 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2997 "URL", url);
[email protected]91621872013-10-08 04:04:592998 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2999 DidStartLoading(render_view_host));
3000 } else {
[email protected]eab61442013-11-14 18:35:483001 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
3002 "URL", url);
[email protected]91621872013-10-08 04:04:593003 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3004 DidStopLoading(render_view_host));
3005 }
[email protected]66798902013-10-01 18:40:163006
3007 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213008 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3009 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543010 if (details)
[email protected]8ff00d72012-10-23 19:12:213011 det = Details<LoadNotificationDetails>(details);
3012 NotificationService::current()->Notify(
3013 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543014}
3015
[email protected]959be4c2014-04-08 15:01:333016void WebContentsImpl::SelectRange(const gfx::Point& start,
3017 const gfx::Point& end) {
3018 RenderFrameHost* focused_frame = GetFocusedFrame();
3019 if (!focused_frame)
3020 return;
3021
3022 focused_frame->Send(
3023 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
3024}
3025
[email protected]b172aee2012-04-10 17:05:263026void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463027 // If we are creating a RVH for a restored controller, then we need to make
3028 // sure the RenderView starts with a next_page_id_ larger than the number
3029 // of restored entries. This must be called before the RenderView starts
3030 // navigating (to avoid a race between the browser updating max_page_id and
3031 // the renderer updating next_page_id_). Because of this, we only call this
3032 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563033 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583034 if (max_restored_page_id >
3035 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3036 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3037 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323038}
3039
[email protected]b172aee2012-04-10 17:05:263040bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263041 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323042 // For file URLs without a title, use the pathname instead. In the case of a
3043 // synthesized title, we don't want the update to count toward the "one set
3044 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263045 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323046 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513047 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243048 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323049 explicit_set = false; // Don't count synthetic titles toward the set limit.
3050 } else {
[email protected]8af69c6c2014-03-03 19:05:313051 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323052 explicit_set = true;
3053 }
3054
[email protected]987fc3a2011-05-26 14:18:093055 // If a page is created via window.open and never navigated,
3056 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553057 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093058 if (entry) {
[email protected]36fc0392011-12-25 03:59:513059 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093060 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323061
[email protected]36fc0392011-12-25 03:59:513062 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093063 } else {
3064 if (page_title_when_no_navigation_entry_ == final_title)
3065 return false; // Nothing changed, don't bother.
3066
3067 page_title_when_no_navigation_entry_ = final_title;
3068 }
[email protected]420ae012009-04-24 05:16:323069
[email protected]420ae012009-04-24 05:16:323070 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233071 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323072
[email protected]66798902013-10-01 18:40:163073 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533074 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163075
3076 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213077 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463078 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213079 NotificationService::current()->Notify(
3080 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3081 Source<WebContents>(this),
3082 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043083
[email protected]420ae012009-04-24 05:16:323084 return true;
3085}
3086
[email protected]960b0372014-05-19 18:01:003087void WebContentsImpl::SendLoadProgressChanged() {
3088 loading_last_progress_update_ = base::TimeTicks::Now();
3089 double progress = 0.0;
3090 int frame_count = 0;
3091
3092 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3093 it != loading_progresses_.end();
3094 ++it) {
3095 progress += it->second;
3096 ++frame_count;
3097 }
3098 if (frame_count == 0)
3099 return;
3100 progress /= frame_count;
3101 DCHECK(progress <= 1.0);
3102
3103 if (progress <= loading_total_progress_)
3104 return;
3105 loading_total_progress_ = progress;
3106
3107 if (delegate_)
3108 delegate_->LoadProgressChanged(this, progress);
3109}
3110
3111void WebContentsImpl::ResetLoadProgressState() {
3112 loading_progresses_.clear();
3113 loading_total_progress_ = 0.0;
3114 loading_weak_factory_.InvalidateWeakPtrs();
3115 loading_last_progress_update_ = base::TimeTicks();
3116}
3117
[email protected]7b712ee22013-10-03 00:57:283118void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
3119 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323120 // After sending out a swap notification, we need to send a disconnect
3121 // notification so that clients that pick up a pointer to |this| can NULL the
3122 // pointer. See Bug 1230284.
3123 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113124 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283125 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113126
3127 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283128 std::pair<RenderViewHost*, RenderViewHost*> details =
3129 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213130 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283131 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213132 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283133 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393134
3135 // Ensure that the associated embedder gets cleared after a RenderViewHost
3136 // gets swapped, so we don't reuse the same embedder next time a
3137 // RenderViewHost is attached to this WebContents.
3138 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323139}
3140
[email protected]da7a7182013-09-06 08:11:113141// TODO(avi): Remove this entire function because this notification is already
3142// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263143void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323144 if (!notify_disconnection_)
3145 return;
3146
3147 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213148 NotificationService::current()->Notify(
3149 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3150 Source<WebContents>(this),
3151 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323152}
3153
[email protected]cbb1ef592013-06-05 19:49:463154void WebContentsImpl::NotifyNavigationEntryCommitted(
3155 const LoadCommittedDetails& load_details) {
3156 FOR_EACH_OBSERVER(
3157 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3158}
3159
[email protected]f114fa42013-12-06 17:06:443160bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3161 const IPC::Message& message) {
3162 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313163}
3164
[email protected]c31a84802014-04-03 15:55:493165const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3166 return GetLastCommittedURL();
3167}
3168
[email protected]b849847b2013-12-10 21:57:583169void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3170 // Note this is only for subframes, the notification for the main frame
3171 // happens in RenderViewCreated.
3172 FOR_EACH_OBSERVER(WebContentsObserver,
3173 observers_,
3174 RenderFrameCreated(render_frame_host));
3175}
3176
3177void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193178 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583179 FOR_EACH_OBSERVER(WebContentsObserver,
3180 observers_,
3181 RenderFrameDeleted(render_frame_host));
3182}
3183
[email protected]a09d53ce2014-01-31 00:46:423184void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303185 if (delegate_)
3186 delegate_->WorkerCrashed(this);
3187}
3188
[email protected]a09d53ce2014-01-31 00:46:423189void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3190 const ContextMenuParams& params) {
3191 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:403192 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:423193 return;
3194
3195 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
3196}
3197
[email protected]87de04b02014-04-08 22:14:493198void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013199 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493200 const base::string16& message,
3201 const base::string16& default_prompt,
3202 const GURL& frame_url,
3203 JavaScriptMessageType javascript_message_type,
3204 IPC::Message* reply_msg) {
3205 // Suppress JavaScript dialogs when requested. Also suppress messages when
3206 // showing an interstitial as it's shown over the previous page and we don't
3207 // want the hidden page's dialogs to interfere with the interstitial.
3208 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013209 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493210 IsSwappedOut() ||
3211 ShowingInterstitialPage() ||
3212 !delegate_ ||
3213 delegate_->ShouldSuppressDialogs() ||
3214 !delegate_->GetJavaScriptDialogManager();
3215
3216 if (!suppress_this_message) {
3217 std::string accept_lang = GetContentClient()->browser()->
3218 GetAcceptLangs(GetBrowserContext());
3219 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3220 dialog_manager_->RunJavaScriptDialog(
3221 this,
3222 frame_url.GetOrigin(),
3223 accept_lang,
3224 javascript_message_type,
3225 message,
3226 default_prompt,
3227 base::Bind(&WebContentsImpl::OnDialogClosed,
3228 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013229 render_frame_host->GetProcess()->GetID(),
3230 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493231 reply_msg,
3232 false),
3233 &suppress_this_message);
3234 }
3235
3236 if (suppress_this_message) {
3237 // If we are suppressing messages, just reply as if the user immediately
3238 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013239 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3240 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283241 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493242 }
3243
3244 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3245 // http://crbug.com/288961 ). The only safe thing to do here is return.
3246}
3247
3248void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013249 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493250 const base::string16& message,
3251 bool is_reload,
3252 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013253 RenderFrameHostImpl* rfhi =
3254 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493255 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013256 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493257 if (delegate_)
3258 delegate_->WillRunBeforeUnloadConfirm();
3259
3260 bool suppress_this_message =
3261 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3262 !delegate_ ||
3263 delegate_->ShouldSuppressDialogs() ||
3264 !delegate_->GetJavaScriptDialogManager();
3265 if (suppress_this_message) {
3266 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3267 return;
3268 }
3269
3270 is_showing_before_unload_dialog_ = true;
3271 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3272 dialog_manager_->RunBeforeUnloadDialog(
3273 this, message, is_reload,
3274 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013275 render_frame_host->GetProcess()->GetID(),
3276 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283277 false));
[email protected]87de04b02014-04-08 22:14:493278}
3279
[email protected]a86c0e962013-12-17 17:10:393280WebContents* WebContentsImpl::GetAsWebContents() {
3281 return this;
3282}
3283
[email protected]7912e822014-04-16 02:37:033284bool WebContentsImpl::IsNeverVisible() {
3285 if (!delegate_)
3286 return false;
3287 return delegate_->IsNeverVisible(this);
3288}
3289
[email protected]5a3bdf52012-05-24 15:12:573290RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3291 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323292}
3293
[email protected]8ff00d72012-10-23 19:12:213294RendererPreferences WebContentsImpl::GetRendererPrefs(
3295 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463296 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513297}
3298
[email protected]b172aee2012-04-10 17:05:263299gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173300 if (delegate_)
3301 return delegate_->GetRootWindowResizerRect();
3302 return gfx::Rect();
3303}
3304
[email protected]7a846df2012-09-20 19:17:393305void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273306 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393307 browser_plugin_embedder_.reset();
3308}
3309
[email protected]b172aee2012-04-10 17:05:263310void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443311 // Don't send notifications if we are just creating a swapped-out RVH for
3312 // the opener chain. These won't be used for view-source or WebUI, so it's
3313 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243314 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443315 return;
3316
[email protected]86f98a22013-03-20 14:35:003317 if (delegate_)
3318 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083319
[email protected]8ff00d72012-10-23 19:12:213320 NotificationService::current()->Notify(
3321 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3322 Source<WebContents>(this),
3323 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323324
3325 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353326 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213327 if (GetRenderManager()->pending_web_ui())
3328 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323329
[email protected]6286a372013-10-09 04:03:273330 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333331 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323332 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183333 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583334 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323335 }
[email protected]0666aef2009-05-13 19:48:083336
[email protected]60780f412013-02-25 16:34:103337 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263338
3339 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253340 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583341
3342 // We tell the observers now instead of when the main RenderFrameHostImpl is
3343 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3344 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363345 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583346 FOR_EACH_OBSERVER(
3347 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323348}
3349
[email protected]b172aee2012-04-10 17:05:263350void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523351 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323352 // Don't notify the world, since this came from a renderer in the
3353 // background.
3354 return;
3355 }
3356
[email protected]da7a7182013-09-06 08:11:113357 notify_disconnection_ = true;
3358 // TODO(avi): Remove. http://crbug.com/170921
3359 NotificationService::current()->Notify(
3360 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3361 Source<WebContents>(this),
3362 NotificationService::NoDetails());
3363
[email protected]be1f56ab2011-12-22 06:55:313364 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233365 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303366
3367 // Restore the focus to the tab (otherwise the focus will be on the top
3368 // window).
[email protected]484ae5912010-09-29 19:16:143369 if (was_crashed && !FocusLocationBarByDefault() &&
3370 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063371 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143372 }
[email protected]32ded2212011-11-10 18:51:433373
[email protected]d8c660432011-12-22 20:51:253374 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323375}
3376
[email protected]ec6a7eb2013-04-22 17:34:223377void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3378 base::TerminationStatus status,
3379 int error_code) {
[email protected]151a63d2011-12-20 22:32:523380 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323381 // The pending page's RenderViewHost is gone.
3382 return;
3383 }
3384
[email protected]2fcdcc32014-03-05 02:14:073385 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3386 // renderer may not have made a clean exit.
3387 if (IsFullscreenForCurrentTab())
3388 ToggleFullscreenMode(false);
3389
[email protected]698191dc2014-02-25 01:06:133390 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3391 if (dialog_manager_)
3392 dialog_manager_->CancelActiveAndPendingDialogs(this);
3393
[email protected]e3b10d12014-03-28 16:06:093394 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323395 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233396 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453397
[email protected]960b0372014-05-19 18:01:003398 // Reset the loading progress. TODO(avi): What does it mean to have a
3399 // "renderer crash" when there is more than one renderer process serving a
3400 // webpage? Once this function is called at a more granular frame level, we
3401 // probably will need to more granularly reset the state here.
3402 ResetLoadProgressState();
3403 loading_frames_in_progress_ = 0;
3404
[email protected]fc2b46b2014-05-03 16:33:453405#if defined(OS_ANDROID)
3406 if (GetRenderViewHostImpl()->media_player_manager())
3407 GetRenderViewHostImpl()->media_player_manager()->DestroyAllMediaPlayers();
3408#endif
[email protected]420ae012009-04-24 05:16:323409
[email protected]d8c660432011-12-22 20:51:253410 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273411 observers_,
[email protected]58d5cfe2013-07-10 02:40:523412 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323413}
3414
[email protected]b172aee2012-04-10 17:05:263415void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253416 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063417}
3418
[email protected]b172aee2012-04-10 17:05:263419void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3420 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043421 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153422 // Ensure that this state update comes from either the active RVH or one of
3423 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413424 // TODO(nasko): This should go through RenderFrameHost.
3425 // TODO(creis): We can't update state for cross-process subframes until we
3426 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3427 if (rvh != GetRenderViewHost() &&
3428 !GetRenderManager()->IsRVHOnSwappedOutList(
3429 static_cast<RenderViewHostImpl*>(rvh)))
3430 return;
[email protected]420ae012009-04-24 05:16:323431
3432 // We must be prepared to handle state updates for any page, these occur
3433 // when the user is scrolling and entering form data, as well as when we're
3434 // leaving a page, in which case our state may have already been moved to
3435 // the next page. The navigation controller will look up the appropriate
3436 // NavigationEntry and update it when it is notified via the delegate.
3437
3438 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583439 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323440 if (entry_index < 0)
3441 return;
[email protected]10f417c52011-12-28 21:04:233442 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323443
[email protected]691aa2f2013-05-28 22:52:043444 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323445 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043446 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323447 controller_.NotifyEntryChanged(entry, entry_index);
3448}
3449
[email protected]b172aee2012-04-10 17:05:263450void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513451 if (delegate_)
3452 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323453}
3454
[email protected]b172aee2012-04-10 17:05:263455void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103456#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293457 // The UI may be in an event-tracking loop, such as between the
3458 // mouse-down and mouse-up in text selection or a button click.
3459 // Defer the close until after tracking is complete, so that we
3460 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293461 // TODO(shess): This could get more fine-grained. For instance,
3462 // closing a tab in another window while selecting text in the
3463 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103464 if (view_->IsEventTracking()) {
3465 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293466 return;
3467 }
[email protected]60780f412013-02-25 16:34:103468#endif
[email protected]07707302009-11-06 00:50:293469
[email protected]420ae012009-04-24 05:16:323470 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523471 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513472 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323473}
3474
[email protected]66bbadaf2014-03-28 16:25:543475void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573476 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3477 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573478}
3479
[email protected]b172aee2012-04-10 17:05:263480void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513481 if (delegate_ && delegate_->IsPopupOrPanel(this))
3482 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323483}
3484
[email protected]e3b10d12014-03-28 16:06:093485void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3486 bool to_different_document) {
3487 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3488 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323489}
3490
[email protected]723971b2014-02-12 11:08:253491void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323492 scoped_ptr<LoadNotificationDetails> details;
3493
[email protected]9595fd82013-04-19 21:28:493494 // Use the last committed entry rather than the active one, in case a
3495 // pending entry has been created.
3496 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203497 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493498
[email protected]420ae012009-04-24 05:16:323499 // An entry may not exist for a stop when loading an initial blank page or
3500 // if an iframe injected by script into a blank page finishes loading.
3501 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203502 base::TimeDelta elapsed =
3503 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323504
3505 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513506 entry->GetVirtualURL(),
3507 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323508 elapsed,
3509 &controller_,
3510 controller_.GetCurrentEntryIndex()));
3511 }
3512
[email protected]e3b10d12014-03-28 16:06:093513 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3514 details.get());
[email protected]420ae012009-04-24 05:16:323515}
3516
[email protected]b172aee2012-04-10 17:05:263517void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163518 controller_.DiscardNonCommittedEntries();
3519
3520 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213521 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163522}
3523
[email protected]59167c22013-06-03 18:07:323524void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103525 has_accessed_initial_document_ = true;
3526
[email protected]d1371bf8e2014-04-19 03:26:243527 // We may have left a failed browser-initiated navigation in the address bar
3528 // to let the user edit it and try again. Clear it now that content might
3529 // show up underneath it.
3530 if (!IsLoading() && controller_.GetPendingEntry())
3531 controller_.DiscardPendingEntry();
3532
[email protected]59167c22013-06-03 18:07:323533 // Update the URL display.
3534 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3535}
3536
[email protected]3f19f1a2014-05-02 05:23:273537void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3538 if (opener_) {
3539 // Clear our opener so that future cross-process navigations don't have an
3540 // opener assigned.
3541 RemoveDestructionObserver(opener_);
3542 opener_ = NULL;
3543 }
3544
3545 // Notify all swapped out RenderViewHosts for this tab. This is important
3546 // in case we go back to them, or if another window in those processes tries
3547 // to access window.opener.
3548 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3549}
3550
[email protected]39f2f9252014-05-03 00:54:013551void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293552 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093553 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293554 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093555
3556 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213557 NotificationService::current()->Notify(
3558 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3559 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293560 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083561}
3562
[email protected]ef3adfc2014-05-11 00:04:543563void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3564 int32 page_id,
3565 const base::string16& title,
3566 base::i18n::TextDirection title_direction) {
3567 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3568
3569 // If we have a title, that's a pretty good indication that we've started
3570 // getting useful data.
3571 SetNotWaitingForResponse();
3572
3573 // Try to find the navigation entry, which might not be the current one.
3574 // For example, it might be from a pending RVH for the pending entry.
3575 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3576 rvh->GetSiteInstance(), page_id);
3577
3578 // We can handle title updates when we don't have an entry in
3579 // UpdateTitleForEntry, but only if the update is from the current RVH.
3580 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3581 if (!entry && rvh != GetRenderViewHost())
3582 return;
3583
3584 // TODO(evan): make use of title_direction.
3585 // http://code.google.com/p/chromium/issues/detail?id=27094
3586 if (!UpdateTitleForEntry(entry, title))
3587 return;
3588
3589 // Broadcast notifications when the UI should be updated.
3590 if (entry == controller_.GetEntryAtOffset(0))
3591 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3592}
3593
3594void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3595 const std::string& encoding) {
3596 SetEncoding(encoding);
3597}
3598
[email protected]39f2f9252014-05-03 00:54:013599void WebContentsImpl::DocumentAvailableInMainFrame(
3600 RenderViewHost* render_view_host) {
3601 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3602 DocumentAvailableInMainFrame());
3603}
[email protected]e1c3a552012-05-04 20:51:323604void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3605 // Tell the active RenderViewHost to run unload handlers and close, as long
3606 // as the request came from a RenderViewHost in the same BrowsingInstance.
3607 // In most cases, we receive this from a swapped out RenderViewHost.
3608 // It is possible to receive it from one that has just been swapped in,
3609 // in which case we might as well deliver the message anyway.
3610 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3611 GetRenderViewHost()->ClosePage();
3612}
3613
[email protected]f546640b2012-05-15 00:03:493614void WebContentsImpl::RouteMessageEvent(
3615 RenderViewHost* rvh,
3616 const ViewMsg_PostMessage_Params& params) {
3617 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363618 // came from a RenderViewHost in the same BrowsingInstance or if this
3619 // WebContents is dedicated to a browser plugin guest.
3620 // Note: This check means that an embedder could theoretically receive a
3621 // postMessage from anyone (not just its own guests). However, this is
3622 // probably not a risk for apps since other pages won't have references
3623 // to App windows.
3624 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3625 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493626 return;
3627
3628 ViewMsg_PostMessage_Params new_params(params);
3629
[email protected]0bc7f3542013-10-21 15:05:533630 if (!params.message_port_ids.empty()) {
3631 MessagePortMessageFilter* message_port_message_filter =
3632 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3633 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093634 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3635 params.message_port_ids,
3636 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533637 }
3638
[email protected]f546640b2012-05-15 00:03:493639 // If there is a source_routing_id, translate it to the routing ID for
3640 // the equivalent swapped out RVH in the target process. If we need
3641 // to create a swapped out RVH for the source tab, we create its opener
3642 // chain as well, since those will also be accessible to the target page.
3643 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3644 // Try to look up the WebContents for the source page.
3645 WebContentsImpl* source_contents = NULL;
3646 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3647 rvh->GetProcess()->GetID(), params.source_routing_id);
3648 if (source_rvh) {
3649 source_contents = static_cast<WebContentsImpl*>(
3650 source_rvh->GetDelegate()->GetAsWebContents());
3651 }
3652
3653 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363654 if (GetBrowserPluginGuest()) {
3655 // We create a swapped out RenderView for the embedder in the guest's
3656 // render process but we intentionally do not expose the embedder's
3657 // opener chain to it.
3658 new_params.source_routing_id =
3659 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3660 } else {
3661 new_params.source_routing_id =
3662 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3663 }
[email protected]f546640b2012-05-15 00:03:493664 } else {
3665 // We couldn't find it, so don't pass a source frame.
3666 new_params.source_routing_id = MSG_ROUTING_NONE;
3667 }
3668 }
3669
3670 // In most cases, we receive this from a swapped out RenderViewHost.
3671 // It is possible to receive it from one that has just been swapped in,
3672 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183673 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493674}
3675
[email protected]a796f202012-05-30 14:14:253676bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263677 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253678 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263679 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253680 if (!delegate_)
3681 return false;
3682 return delegate_->AddMessageToConsole(this, level, message, line_no,
3683 source_id);
3684}
3685
[email protected]b172aee2012-04-10 17:05:263686WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273687 // We want to base the page config off of the actual URL, rather than the
3688 // virtual URL.
3689 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3690 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003691 GURL url = controller_.GetActiveEntry()
3692 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153693
[email protected]fa944cb82013-11-15 17:51:213694 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323695}
3696
[email protected]0eba810b2012-10-18 03:19:363697int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213698 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413699 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3700 true, true);
[email protected]0eba810b2012-10-18 03:19:363701}
3702
[email protected]b172aee2012-04-10 17:05:263703void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273704 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253705 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223706
[email protected]ea114722012-03-12 01:11:253707 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173708 if (rdh) // NULL in unittests.
3709 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253710}
3711
[email protected]b172aee2012-04-10 17:05:263712void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443713 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253714 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443715}
3716
[email protected]b172aee2012-04-10 17:05:263717void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563718 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263719 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153720 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523721 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153722 return;
3723
[email protected]9f76c1e2012-03-05 15:15:583724 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3725
[email protected]e5fc1632011-08-08 07:51:533726 // Ignore renderer unresponsive event if debugger is attached to the tab
3727 // since the event may be a result of the renderer sitting on a breakpoint.
3728 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363729 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533730 return;
3731
[email protected]2e9d79f2013-08-16 05:45:563732 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323733 // Hang occurred while firing the beforeunload/unload handler.
3734 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583735 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323736
[email protected]fa944cb82013-11-15 17:51:213737 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323738 return;
3739
3740 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563741 // nothing we can do to recover. If the hang is in the beforeunload handler,
3742 // pretend the beforeunload listeners have all fired and allow the delegate
3743 // to continue closing; the user will not have the option of cancelling the
3744 // close. Otherwise, pretend the unload listeners have all fired and close
3745 // the tab.
3746 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463747 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563748 delegate_->BeforeUnloadFired(this, true, &close);
3749 }
3750 if (close)
3751 Close(rvh);
[email protected]420ae012009-04-24 05:16:323752 return;
3753 }
3754
[email protected]9f76c1e2012-03-05 15:15:583755 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473756 return;
3757
[email protected]6934a702011-12-20 00:04:513758 if (delegate_)
3759 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323760}
3761
[email protected]b172aee2012-04-10 17:05:263762void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513763 if (delegate_)
3764 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323765}
3766
[email protected]b172aee2012-04-10 17:05:263767void WebContentsImpl::LoadStateChanged(
3768 const GURL& url,
3769 const net::LoadStateWithParam& load_state,
3770 uint64 upload_position,
3771 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323772 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563773 upload_position_ = upload_position;
3774 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503775 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213776 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303777 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213778 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323779 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463780 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213781 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463782 }
[email protected]420ae012009-04-24 05:16:323783}
3784
[email protected]b172aee2012-04-10 17:05:263785void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553786 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323787 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123788 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3789 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513790 if (delegate_)
3791 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093792 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323793}
3794
[email protected]58d5cfe2013-07-10 02:40:523795void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543796 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233797 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223798 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543799}
3800
[email protected]b172aee2012-04-10 17:05:263801void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103802 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213803 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263804 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3805 // here during container initialization and normal window size will be set
3806 // later. In case of tab duplication this resizing to 0x0 prevents setting
3807 // normal size later so just ignore it.
3808 if (!size.IsEmpty())
3809 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323810}
3811
[email protected]af905902013-10-01 21:38:513812void WebContentsImpl::CancelModalDialogsForRenderManager() {
3813 // We need to cancel modal dialogs when doing a process swap, since the load
3814 // deferrer would prevent us from swapping out.
3815 if (dialog_manager_)
3816 dialog_manager_->CancelActiveAndPendingDialogs(this);
3817}
3818
[email protected]7b712ee22013-10-03 00:57:283819void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3820 RenderViewHost* new_host) {
3821 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083822
3823 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003824 if (delegate_)
3825 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393826
[email protected]7b712ee22013-10-03 00:57:283827 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543828}
3829
[email protected]14392a52012-05-02 20:28:443830int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3831 SiteInstance* instance) {
3832 if (!opener_)
3833 return MSG_ROUTING_NONE;
3834
3835 // Recursively create RenderViews for anything else in the opener chain.
3836 return opener_->CreateOpenerRenderViews(instance);
3837}
3838
3839int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3840 int opener_route_id = MSG_ROUTING_NONE;
3841
3842 // If this tab has an opener, ensure it has a RenderView in the given
3843 // SiteInstance as well.
3844 if (opener_)
3845 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3846
[email protected]45a22ad2013-02-21 03:25:003847 // If any of the renderers (current, pending, or swapped out) for this
3848 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213849 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3850 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373851
[email protected]fa944cb82013-11-15 17:51:213852 if (GetRenderManager()->pending_render_view_host() &&
3853 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3854 instance)
3855 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003856
[email protected]fa944cb82013-11-15 17:51:213857 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373858 instance);
3859 if (rvh)
3860 return rvh->GetRoutingID();
3861
[email protected]14392a52012-05-02 20:28:443862 // Create a swapped out RenderView in the given SiteInstance if none exists,
3863 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413864 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3865 true, true);
[email protected]14392a52012-05-02 20:28:443866}
3867
[email protected]b172aee2012-04-10 17:05:263868NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193869 return GetController();
[email protected]3a3d47472010-07-15 21:03:543870}
3871
[email protected]b172aee2012-04-10 17:05:263872WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563873 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323874}
3875
[email protected]10f417c52011-12-28 21:04:233876NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263877 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323878 return controller_.GetLastCommittedEntry();
3879}
3880
[email protected]b172aee2012-04-10 17:05:263881bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163882 RenderViewHost* render_view_host,
3883 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043884 int proxy_routing_id,
[email protected]6ab9d682014-05-22 03:48:593885 bool for_main_frame) {
[email protected]e11f0e92013-06-12 15:12:033886 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443887 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483888 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163889 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3890 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3891 // case this because RWH is still a base class of RenderViewHost, and child
3892 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]6ab9d682014-05-22 03:48:593893 if (!for_main_frame) {
[email protected]bffc8302014-01-23 20:52:163894 RenderWidgetHostViewChildFrame* rwh_view_child =
3895 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:163896 rwh_view = rwh_view_child;
3897 } else {
3898 rwh_view = view_->CreateViewForWidget(render_view_host);
3899 }
[email protected]1a98a932009-11-17 00:12:523900
[email protected]420ae012009-04-24 05:16:323901 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443902 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213903 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323904
[email protected]74ce1ad2011-12-16 21:51:463905 // Make sure we use the correct starting page_id in the new RenderView.
3906 UpdateMaxPageIDIfNecessary(render_view_host);
3907 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583908 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463909
[email protected]9f76c1e2012-03-05 15:15:583910 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263911 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493912 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043913 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:493914 max_page_id,
3915 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523916 return false;
[email protected]14392a52012-05-02 20:28:443917 }
[email protected]a4127722011-04-27 23:13:523918
[email protected]a220b5932013-09-21 03:47:443919#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503920 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3921 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443922 if (rwh_view) {
3923 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3924 render_widget_host->WasResized();
3925 }
[email protected]f8233cc2011-05-31 20:24:503926#endif
3927
[email protected]420ae012009-04-24 05:16:323928 return true;
3929}
3930
[email protected]7d244f12013-08-22 21:41:513931#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453932
[email protected]155c7f22013-12-09 17:07:183933base::android::ScopedJavaLocalRef<jobject>
3934WebContentsImpl::GetJavaWebContents() {
3935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3936
3937 WebContentsAndroid* web_contents_android =
3938 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3939 if (!web_contents_android) {
3940 web_contents_android = new WebContentsAndroid(this);
3941 SetUserData(kWebContentsAndroidKey, web_contents_android);
3942 }
3943 return web_contents_android->GetJavaObject();
3944}
3945
[email protected]7d244f12013-08-22 21:41:513946bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3947 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163948 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:043949 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:593950 true);
[email protected]7d244f12013-08-22 21:41:513951}
[email protected]fc2b46b2014-05-03 16:33:453952
3953#elif defined(OS_MACOSX)
3954
3955void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
3956 view_->SetAllowOverlappingViews(overlapping);
3957}
3958
3959bool WebContentsImpl::GetAllowOverlappingViews() {
3960 return view_->GetAllowOverlappingViews();
3961}
3962
3963void WebContentsImpl::SetOverlayView(WebContents* overlay,
3964 const gfx::Point& offset) {
3965 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
3966 offset);
3967}
3968
3969void WebContentsImpl::RemoveOverlayView() {
3970 view_->RemoveOverlayView();
3971}
3972
[email protected]7d244f12013-08-22 21:41:513973#endif
3974
[email protected]6fba26d2014-04-29 09:38:283975void WebContentsImpl::OnDialogClosed(int render_process_id,
3976 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:263977 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493978 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263979 bool success,
[email protected]fcf75d42013-12-03 20:11:263980 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:283981 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3982 render_frame_id);
[email protected]87de04b02014-04-08 22:14:493983 last_dialog_suppressed_ = dialog_was_suppressed;
3984
[email protected]beb440c2009-11-06 04:08:543985 if (is_showing_before_unload_dialog_ && !success) {
3986 // If a beforeunload dialog is canceled, we need to stop the throbber from
3987 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:283988 if (rfh)
3989 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353990 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103991
[email protected]6d65a462013-06-21 21:29:123992 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3993 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543994 }
[email protected]87de04b02014-04-08 22:14:493995
[email protected]beb440c2009-11-06 04:08:543996 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:283997 if (rfh) {
3998 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3999 dialog_was_suppressed);
4000 } else {
4001 // Don't leak the sync IPC reply if the RFH or process is gone.
4002 delete reply_msg;
4003 }
[email protected]beb440c2009-11-06 04:08:544004}
4005
[email protected]b172aee2012-04-10 17:05:264006void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544007 if (encoding == last_reported_encoding_)
4008 return;
4009 last_reported_encoding_ = encoding;
4010
4011 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124012 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104013}
[email protected]f45d2a72010-03-08 23:28:354014
[email protected]b172aee2012-04-10 17:05:264015void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:484016 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:444017 // Can be NULL during tests.
4018 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:454019 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:364020}
[email protected]9f76c1e2012-03-05 15:15:584021
[email protected]1ac10dca2013-08-20 20:47:044022bool WebContentsImpl::IsHidden() {
4023 return capturer_count_ == 0 && !should_normally_be_visible_;
4024}
4025
[email protected]b0936d22013-11-28 06:47:364026RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214027 return frame_tree_.root()->render_manager();
4028}
4029
[email protected]b172aee2012-04-10 17:05:264030RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584031 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4032}
[email protected]7900bfdb2012-05-24 19:31:244033
[email protected]f8497342013-02-05 22:15:024034BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394035 return browser_plugin_guest_.get();
4036}
4037
[email protected]738f57a2013-06-29 21:06:544038void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4039 CHECK(!browser_plugin_guest_);
4040 browser_plugin_guest_.reset(guest);
4041}
4042
[email protected]f8497342013-02-05 22:15:024043BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394044 return browser_plugin_embedder_.get();
4045}
[email protected]8ff00d72012-10-23 19:12:214046
[email protected]d9030b82013-07-19 08:26:064047void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194048 RenderFrameHost* render_frame_host) {
4049 STLDeleteValues(&power_save_blockers_[render_frame_host]);
4050 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:064051}
4052
4053void WebContentsImpl::ClearAllPowerSaveBlockers() {
4054 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
4055 i != power_save_blockers_.end(); ++i)
4056 STLDeleteValues(&power_save_blockers_[i->first]);
4057 power_save_blockers_.clear();
4058}
4059
[email protected]fc2b46b2014-05-03 16:33:454060gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214061 gfx::Size size;
4062 if (delegate_)
4063 size = delegate_->GetSizeForNewRenderView(this);
4064 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454065 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214066 return size;
4067}
4068
[email protected]9b159a52013-10-03 17:24:554069void WebContentsImpl::OnFrameRemoved(
4070 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:584071 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:554072 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:584073 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:554074}
4075
[email protected]222f5822014-02-05 23:40:494076void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4077 if (!delegate_)
4078 return;
4079 const gfx::Size new_size = GetPreferredSize();
4080 if (new_size != old_size)
4081 delegate_->UpdatePreferredSize(this, new_size);
4082}
4083
[email protected]8ff00d72012-10-23 19:12:214084} // namespace content