blob: 44a2a78bffa46a2f24a4b6bc49403bf4593f99cd [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]443b80e2010-12-14 00:42:23337 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
338 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34339 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26340 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00341 loading_total_progress_(0.0),
342 loading_weak_factory_(this),
343 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56344 upload_size_(0),
345 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47346 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10347 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55348 capturer_count_(0),
349 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57350 is_being_destroyed_(false),
351 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15352 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01353 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02354 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38355 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21356 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
357 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00358 temporary_zoom_settings_(false),
[email protected]bab38af2014-03-30 17:37:29359 totalPinchGestureAmount_(0),
360 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44361 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42362 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]87de04b02014-04-08 22:14:49363 is_subframe_(false),
364 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46365 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
366 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55367 frame_tree_.SetFrameRemoveListener(
368 base::Bind(&WebContentsImpl::OnFrameRemoved,
369 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35370}
initial.commit09911bf2008-07-26 23:55:29371
[email protected]b172aee2012-04-10 17:05:26372WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32373 is_being_destroyed_ = true;
374
[email protected]21b41c7e892014-02-28 01:52:24375 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
376 // shutdown and be deleted as well.
377 frame_tree_.ForEach(
378 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
379
[email protected]d9030b82013-07-19 08:26:06380 ClearAllPowerSaveBlockers();
381
[email protected]b24b68a2012-09-24 21:57:26382 for (std::set<RenderWidgetHostImpl*>::iterator iter =
383 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
384 (*iter)->DetachDelegate();
385 }
386 created_widgets_.clear();
387
[email protected]3ab9cb82011-06-03 18:02:07388 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15389 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11390 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07391
[email protected]8ed16472014-04-11 19:02:48392 if (color_chooser_info_.get())
393 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20394
[email protected]420ae012009-04-24 05:16:32395 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32396
[email protected]ca13a442012-04-17 14:00:12397 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21398 NotificationService::current()->Notify(
399 NOTIFICATION_WEB_CONTENTS_DESTROYED,
400 Source<WebContents>(this),
401 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32402
[email protected]c06c58c2014-03-12 20:31:59403 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
404 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
405 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
406 run_render_frame_deleted_callback));
407
[email protected]fa944cb82013-11-15 17:51:21408 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27409 if (pending_rvh) {
410 FOR_EACH_OBSERVER(WebContentsObserver,
411 observers_,
412 RenderViewDeleted(pending_rvh));
413 }
414
[email protected]c06c58c2014-03-12 20:31:59415 ForEachFrame(run_render_frame_deleted_callback);
416
[email protected]f273ee52013-10-18 16:05:27417 FOR_EACH_OBSERVER(WebContentsObserver,
418 observers_,
[email protected]fa944cb82013-11-15 17:51:21419 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27420
[email protected]2db9bd72012-04-13 20:20:56421 FOR_EACH_OBSERVER(WebContentsObserver,
422 observers_,
[email protected]12a46832014-05-09 13:35:58423 WebContentsDestroyed());
424
425 FOR_EACH_OBSERVER(WebContentsObserver,
426 observers_,
427 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08428
[email protected]6934a702011-12-20 00:04:51429 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10430
431 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
432 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42433}
434
[email protected]d1198fd2012-08-13 22:50:19435WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59436 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19437 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03438 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59439 WebContentsImpl* new_contents = new WebContentsImpl(
440 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19441
[email protected]83100cd2014-05-10 11:50:06442 if (params.guest_instance_id) {
443 scoped_ptr<base::DictionaryValue> extra_params(
444 params.guest_extra_params->DeepCopy());
445 // This makes |new_contents| act as a guest.
446 // For more info, see comment above class BrowserPluginGuest.
447 BrowserPluginGuest::Create(params.guest_instance_id,
448 params.site_instance,
449 new_contents,
450 extra_params.Pass());
451 // We are instantiating a WebContents for browser plugin. Set its subframe
452 // bit to true.
453 new_contents->is_subframe_ = true;
454 }
[email protected]54944cde2012-12-09 09:24:59455 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19456 return new_contents;
457}
458
[email protected]b0936d22013-11-28 06:47:36459RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21460 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28461}
462
[email protected]7bb761892012-07-20 09:32:47463bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
464 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44465 return OnMessageReceived(render_view_host, NULL, message);
466}
467
468bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
469 RenderFrameHost* render_frame_host,
470 const IPC::Message& message) {
471 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56472 if (GetWebUI() &&
473 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17474 return true;
[email protected]d2353452012-01-19 19:53:56475 }
[email protected]f82d57b52011-04-27 19:13:17476
[email protected]d8c660432011-12-22 20:51:25477 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
478 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33479 if (render_frame_host) {
480 while ((observer = it.GetNext()) != NULL)
481 if (observer->OnMessageReceived(message, render_frame_host))
482 return true;
483 } else {
484 while ((observer = it.GetNext()) != NULL)
485 if (observer->OnMessageReceived(message))
486 return true;
487 }
[email protected]403415a2011-01-10 18:57:53488
[email protected]1d62cf72014-02-07 21:31:57489 // Message handlers should be aware of which
490 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
491 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43492 if (render_frame_host) {
493 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
494 render_frame_host->GetRenderViewHost(), message))
495 return true;
[email protected]1d62cf72014-02-07 21:31:57496 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43497 } else {
498 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
499 render_view_host, message))
500 return true;
[email protected]1d62cf72014-02-07 21:31:57501 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43502 }
[email protected]1d62cf72014-02-07 21:31:57503
[email protected]724159a2010-12-30 01:11:18504 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33505 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]f114fa42013-12-06 17:06:44506 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
507 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40508 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
509 OnDomOperationResponse)
[email protected]8ed16472014-04-11 19:02:48510 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
511 OnDocumentLoadedInFrame)
512 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00513 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
514 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
515 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
516 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48517 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
518 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
519 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
520 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19521 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
522 OnMediaPlayingNotification)
523 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
524 OnMediaPausedNotification)
[email protected]724159a2010-12-30 01:11:18525 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
526 OnDidLoadResourceFromMemoryCache)
527 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
528 OnDidDisplayInsecureContent)
529 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
530 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25531 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26532 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21533 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20534 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
535 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16536 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10537 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50538 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50539 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
540 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55541 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
542 OnBrowserPluginMessage(message))
543 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
544 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02545 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
546 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]9f268072013-11-07 00:02:15547 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
548 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07549 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
550 OnShowValidationMessage)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
552 OnHideValidationMessage)
553 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
554 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48555#if defined(OS_ANDROID)
556 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
557 OnFindMatchRectsReply)
558 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
559 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48560#endif
[email protected]724159a2010-12-30 01:11:18561 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33562 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44563 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57564 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18565
[email protected]724159a2010-12-30 01:11:18566 return handled;
567}
568
[email protected]b172aee2012-04-10 17:05:26569void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18570 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21571 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43572 if (delegate_)
573 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18574}
575
[email protected]d1198fd2012-08-13 22:50:19576NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56577 return controller_;
578}
579
[email protected]d1198fd2012-08-13 22:50:19580const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56581 return controller_;
582}
583
[email protected]8ff00d72012-10-23 19:12:21584BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55585 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30586}
587
[email protected]b172aee2012-04-10 17:05:26588const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24589 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32590 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51591 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31592}
593
[email protected]a093ce02013-07-22 20:53:14594const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24595 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32596 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24597 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
598}
599
600const GURL& WebContentsImpl::GetLastCommittedURL() const {
601 // We may not have a navigation entry yet.
602 NavigationEntry* entry = controller_.GetLastCommittedEntry();
603 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
604}
605
[email protected]8ff00d72012-10-23 19:12:21606WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31607 return delegate_;
608}
609
[email protected]8ff00d72012-10-23 19:12:21610void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31611 // TODO(cbentzel): remove this debugging code?
612 if (delegate == delegate_)
613 return;
614 if (delegate_)
615 delegate_->Detach(this);
616 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08617 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31618 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08619 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00620 if (view_)
621 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08622 }
[email protected]be1f56ab2011-12-22 06:55:31623}
624
[email protected]8ff00d72012-10-23 19:12:21625RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21626 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41627 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16628}
629
[email protected]60eca4eb2013-12-06 00:02:16630RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41631 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16632}
633
[email protected]9c9343b2014-03-08 02:56:07634RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
635 if (!frame_tree_.GetFocusedFrame())
636 return NULL;
637 return frame_tree_.GetFocusedFrame()->current_frame_host();
638}
639
[email protected]a86c0e962013-12-17 17:10:39640void WebContentsImpl::ForEachFrame(
641 const base::Callback<void(RenderFrameHost*)>& on_frame) {
642 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
643}
644
645void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
646 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
647 delete message;
648}
649
[email protected]b172aee2012-04-10 17:05:26650RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21651 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31652}
653
[email protected]bfcfa692013-02-07 06:17:02654WebContents* WebContentsImpl::GetEmbedderWebContents() const {
655 BrowserPluginGuest* guest = GetBrowserPluginGuest();
656 if (guest)
657 return guest->embedder_web_contents();
658 return NULL;
659}
660
661int WebContentsImpl::GetEmbeddedInstanceID() const {
662 BrowserPluginGuest* guest = GetBrowserPluginGuest();
663 if (guest)
664 return guest->instance_id();
665 return 0;
666}
667
[email protected]6b618e62012-08-16 12:59:18668int WebContentsImpl::GetRoutingID() const {
669 if (!GetRenderViewHost())
670 return MSG_ROUTING_NONE;
671
672 return GetRenderViewHost()->GetRoutingID();
673}
674
[email protected]44470a22013-01-24 01:21:54675int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
676 return fullscreen_widget_routing_id_;
677}
678
[email protected]b172aee2012-04-10 17:05:26679RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21680 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31681}
682
[email protected]4aebbca2013-09-17 22:26:49683RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
684 const {
685 RenderWidgetHost* const widget_host =
686 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
687 GetFullscreenWidgetRoutingID());
688 return widget_host ? widget_host->GetView() : NULL;
689}
690
[email protected]8ff00d72012-10-23 19:12:21691WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31692 return view_.get();
693}
694
[email protected]8ff00d72012-10-23 19:12:21695WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56696 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03697 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
698 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22699 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58700 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22701 web_ui->SetController(controller);
702 return web_ui;
703 }
704
705 delete web_ui;
706 return NULL;
707}
708
[email protected]8ff00d72012-10-23 19:12:21709WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21710 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
711 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31712}
713
[email protected]8ff00d72012-10-23 19:12:21714WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21715 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34716}
717
[email protected]86ef6a392012-05-11 22:03:11718void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22719 if (GetUserAgentOverride() == override)
720 return;
721
722 renderer_preferences_.user_agent_override = override;
723
724 // Send the new override string to the renderer.
725 RenderViewHost* host = GetRenderViewHost();
726 if (host)
727 host->SyncRendererPrefs();
728
729 // Reload the page if a load is currently in progress to avoid having
730 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27731 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22732 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
733 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53734
735 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
736 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11737}
738
739const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22740 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11741}
742
[email protected]2ceee8f2014-01-14 18:02:08743#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41744void WebContentsImpl::SetParentNativeViewAccessible(
745gfx::NativeViewAccessible accessible_parent) {
746 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45747 if (GetRenderViewHost())
748 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41749}
750#endif
751
[email protected]fcf75d42013-12-03 20:11:26752const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55753 // Transient entries take precedence. They are used for interstitial pages
754 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23755 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08756 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21757 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30758 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23759 if (entry) {
[email protected]b5cca982011-05-26 04:42:08760 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23761 }
[email protected]fa944cb82013-11-15 17:51:21762 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
763 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58764 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54765 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32766 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54767 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35768 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26769 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54770 if (!title.empty())
771 return title;
772 }
773 }
774
775 // We use the title for the last committed entry rather than a pending
776 // navigation entry. For example, when the user types in a URL, we want to
777 // keep the old page's title until the new load has committed and we get a new
778 // title.
[email protected]96d185d2009-04-24 03:28:54779 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32780
[email protected]9eeafc012013-11-25 23:49:47781 // We make an exception for initial navigations.
782 if (controller_.IsInitialNavigation()) {
783 // We only want to use the title from the visible entry in one of two cases:
784 // 1. There's already a committed entry for an initial navigation, in which
785 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
786 // 2. The pending entry has been explicitly assigned a title to display.
787 //
788 // If there's no last committed entry and no assigned title, we should fall
789 // back to |page_title_when_no_navigation_entry_| rather than showing the
790 // URL.
791 if (entry ||
792 (controller_.GetVisibleEntry() &&
793 !controller_.GetVisibleEntry()->GetTitle().empty())) {
794 entry = controller_.GetVisibleEntry();
795 }
796 }
[email protected]59167c22013-06-03 18:07:32797
[email protected]45d0ef7f2011-01-05 13:46:23798 if (entry) {
[email protected]b5cca982011-05-26 04:42:08799 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23800 }
[email protected]987fc3a2011-05-26 14:18:09801
802 // |page_title_when_no_navigation_entry_| is finally used
803 // if no title cannot be retrieved.
804 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54805}
806
[email protected]b172aee2012-04-10 17:05:26807int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46808 return GetMaxPageIDForSiteInstance(GetSiteInstance());
809}
810
[email protected]b172aee2012-04-10 17:05:26811int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
812 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33813 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
814 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46815
[email protected]b6583592012-01-25 19:52:33816 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34817}
818
[email protected]b172aee2012-04-10 17:05:26819void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46820 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
821}
822
[email protected]b172aee2012-04-10 17:05:26823void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33824 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46825 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33826 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34827}
828
[email protected]ec6c05f2013-10-23 18:41:57829void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
830 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
831 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57832}
833
[email protected]b172aee2012-04-10 17:05:26834SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21835 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54836}
837
[email protected]b172aee2012-04-10 17:05:26838SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21839 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
840 GetRenderManager()->pending_render_view_host() :
841 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58842 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38843}
844
[email protected]b172aee2012-04-10 17:05:26845bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31846 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49847}
848
[email protected]b172aee2012-04-10 17:05:26849bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31850 return waiting_for_response_;
851}
852
[email protected]b172aee2012-04-10 17:05:26853const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31854 return load_state_;
855}
856
[email protected]fcf75d42013-12-03 20:11:26857const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31858 return load_state_host_;
859}
860
[email protected]b172aee2012-04-10 17:05:26861uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31862 return upload_size_;
863}
864
[email protected]b172aee2012-04-10 17:05:26865uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31866 return upload_position_;
867}
868
[email protected]1ae93fb2013-06-14 03:38:56869std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56870 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39871 frame_tree_.ForEach(base::Bind(&CollectSites,
872 base::Unretained(GetBrowserContext()),
873 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56874 return sites;
875}
876
[email protected]b172aee2012-04-10 17:05:26877const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54878 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31879}
880
[email protected]b172aee2012-04-10 17:05:26881bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31882 return displayed_insecure_content_;
883}
884
[email protected]222f5822014-02-05 23:40:49885void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25886 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55887 ++capturer_count_;
888 DVLOG(1) << "There are now " << capturer_count_
889 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49890
891 // Note: This provides a hint to upstream code to size the views optimally
892 // for quality (e.g., to avoid scaling).
893 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
894 preferred_size_for_capture_ = capture_size;
895 OnPreferredSizeChanged(preferred_size_);
896 }
[email protected]54597982013-02-06 01:59:55897}
898
899void WebContentsImpl::DecrementCapturerCount() {
900 --capturer_count_;
901 DVLOG(1) << "There are now " << capturer_count_
902 << " capturing(s) of WebContentsImpl@" << this;
903 DCHECK_LE(0, capturer_count_);
904
[email protected]5a652232013-02-12 06:15:25905 if (is_being_destroyed_)
906 return;
907
[email protected]222f5822014-02-05 23:40:49908 if (capturer_count_ == 0) {
909 const gfx::Size old_size = preferred_size_for_capture_;
910 preferred_size_for_capture_ = gfx::Size();
911 OnPreferredSizeChanged(old_size);
912 }
913
[email protected]1ac10dca2013-08-20 20:47:04914 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55915 DVLOG(1) << "Executing delayed WasHidden().";
916 WasHidden();
917 }
[email protected]be1f56ab2011-12-22 06:55:31918}
919
[email protected]f2bd40812013-07-20 04:30:44920int WebContentsImpl::GetCapturerCount() const {
921 return capturer_count_;
922}
923
[email protected]b172aee2012-04-10 17:05:26924bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31925 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
926 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
927 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49928}
929
[email protected]b172aee2012-04-10 17:05:26930void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
931 int error_code) {
[email protected]443b80e2010-12-14 00:42:23932 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34933 return;
934
[email protected]443b80e2010-12-14 00:42:23935 crashed_status_ = status;
936 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21937 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34938}
939
[email protected]b172aee2012-04-10 17:05:26940base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31941 return crashed_status_;
942}
943
[email protected]b172aee2012-04-10 17:05:26944bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31945 return is_being_destroyed_;
946}
947
[email protected]b172aee2012-04-10 17:05:26948void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34949 if (delegate_)
950 delegate_->NavigationStateChanged(this, changed_flags);
951}
952
[email protected]9a890452014-02-13 22:21:02953base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
954 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33955}
956
[email protected]9e2e4632012-07-27 16:38:41957void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54958 controller_.SetActive(true);
[email protected]cfd80b02014-05-01 17:46:48959 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]8cb5d5b2010-02-09 11:36:16960 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29961 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43962#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16963 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43964#endif
965 }
[email protected]96d185d2009-04-24 03:28:54966
[email protected]9a890452014-02-13 22:21:02967 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38968
[email protected]b9769d82012-02-10 00:23:59969 // The resize rect might have changed while this was inactive -- send the new
970 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58971 RenderViewHostImpl* rvh =
972 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59973 if (rvh) {
974 rvh->ResizeRectChanged(GetRootWindowResizerRect());
975 }
[email protected]96d185d2009-04-24 03:28:54976
[email protected]c0d9d5672013-10-09 07:38:03977 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
978
[email protected]54597982013-02-06 01:59:55979 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31980}
981
[email protected]b172aee2012-04-10 17:05:26982void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55983 // If there are entities capturing screenshots or video (e.g., mirroring),
984 // don't activate the "disable rendering" optimization.
985 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52986 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55987 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26988 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52989 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33990 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52991 // calls us).
[email protected]cfd80b02014-05-01 17:46:48992 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]8cb5d5b2010-02-09 11:36:16993 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29994 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54995 }
996
[email protected]c0d9d5672013-10-09 07:38:03997 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
998
[email protected]54597982013-02-06 01:59:55999 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371000}
1001
[email protected]b172aee2012-04-10 17:05:261002bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311003 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271004 return WillNotifyDisconnection() &&
1005 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581006 !static_cast<RenderViewHostImpl*>(
1007 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311008}
1009
[email protected]1c3f80bd2014-04-08 23:02:061010void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1011 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1012 for_cross_site_transition);
1013}
1014
[email protected]b172aee2012-04-10 17:05:261015void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211016 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401017 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271018}
1019
[email protected]b172aee2012-04-10 17:05:261020WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441021 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451022 // We pass our own opener so that the cloned page can access it if it was
1023 // before.
[email protected]54944cde2012-12-09 09:24:591024 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451025 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591026 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191027 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221028 FOR_EACH_OBSERVER(WebContentsObserver,
1029 observers_,
1030 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271031 return tc;
1032}
1033
[email protected]14392a52012-05-02 20:28:441034void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211035 const NotificationSource& source,
1036 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441037 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211038 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1039 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501040 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1041 i != pending_widget_views_.end(); ++i) {
1042 if (host->GetView() == i->second) {
1043 pending_widget_views_.erase(i);
1044 break;
1045 }
1046 }
1047 break;
1048 }
[email protected]14392a52012-05-02 20:28:441049 default:
1050 NOTREACHED();
1051 }
1052}
1053
[email protected]ec6c05f2013-10-23 18:41:571054WebContents* WebContentsImpl::GetWebContents() {
1055 return this;
1056}
1057
[email protected]54944cde2012-12-09 09:24:591058void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211059 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361060 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211061 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431062 should_normally_be_visible_ = !params.initially_hidden;
1063
[email protected]fa944cb82013-11-15 17:51:211064 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041065 params.browser_context, params.site_instance, params.routing_id,
1066 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191067
[email protected]fc2b46b2014-05-03 16:33:451068 WebContentsViewDelegate* delegate =
1069 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1070
1071 if (browser_plugin_guest_) {
1072 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1073 this, delegate, &render_view_host_delegate_view_));
1074
1075 WebContentsViewGuest* rv = new WebContentsViewGuest(
1076 this, browser_plugin_guest_.get(), platform_view.Pass(),
1077 render_view_host_delegate_view_);
1078 render_view_host_delegate_view_ = rv;
1079 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191080 } else {
[email protected]fc2b46b2014-05-03 16:33:451081 // Regular WebContentsView.
1082 view_.reset(CreateWebContentsView(
1083 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191084 }
[email protected]fc2b46b2014-05-03 16:33:451085 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191086 CHECK(view_.get());
1087
[email protected]ed245db2012-12-18 08:00:451088 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591089 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191090
1091 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101092 if (opener_)
1093 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191094
1095 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211096 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1097 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101098
1099 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
1100
[email protected]c7654a232013-06-12 21:04:441101#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101102 date_time_chooser_.reset(new DateTimeChooserAndroid());
1103#endif
[email protected]d1198fd2012-08-13 22:50:191104}
1105
[email protected]7fff43e2013-05-21 20:21:101106void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1107 RemoveDestructionObserver(web_contents);
1108
[email protected]14392a52012-05-02 20:28:441109 // Clear the opener if it has been closed.
1110 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441111 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511112 return;
[email protected]14392a52012-05-02 20:28:441113 }
[email protected]ceee8cd2013-03-08 04:59:511114 // Clear a pending contents that has been closed before being shown.
1115 for (PendingContents::iterator iter = pending_contents_.begin();
1116 iter != pending_contents_.end();
1117 ++iter) {
1118 if (iter->second != web_contents)
1119 continue;
1120 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511121 return;
1122 }
1123 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441124}
1125
[email protected]7fff43e2013-05-21 20:21:101126void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1127 if (!ContainsKey(destruction_observers_, web_contents)) {
1128 destruction_observers_[web_contents] =
1129 new DestructionObserver(this, web_contents);
1130 }
1131}
1132
1133void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1134 DestructionObservers::iterator iter =
1135 destruction_observers_.find(web_contents);
1136 if (iter != destruction_observers_.end()) {
1137 delete destruction_observers_[web_contents];
1138 destruction_observers_.erase(iter);
1139 }
1140}
1141
[email protected]b172aee2012-04-10 17:05:261142void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311143 observers_.AddObserver(observer);
1144}
1145
[email protected]b172aee2012-04-10 17:05:261146void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311147 observers_.RemoveObserver(observer);
1148}
1149
[email protected]b172aee2012-04-10 17:05:261150void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341151 if (delegate_)
1152 delegate_->ActivateContents(this);
1153}
1154
[email protected]b172aee2012-04-10 17:05:261155void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121156 if (delegate_)
1157 delegate_->DeactivateContents(this);
1158}
1159
[email protected]b172aee2012-04-10 17:05:261160void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481161 if (delegate_)
1162 delegate_->LostCapture();
1163}
1164
[email protected]b24b68a2012-09-24 21:57:261165void WebContentsImpl::RenderWidgetDeleted(
1166 RenderWidgetHostImpl* render_widget_host) {
1167 if (is_being_destroyed_) {
1168 // |created_widgets_| might have been destroyed.
1169 return;
1170 }
1171
1172 std::set<RenderWidgetHostImpl*>::iterator iter =
1173 created_widgets_.find(render_widget_host);
1174 if (iter != created_widgets_.end())
1175 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541176
1177 if (render_widget_host &&
1178 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491179 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1180 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541181 FOR_EACH_OBSERVER(WebContentsObserver,
1182 observers_,
1183 DidDestroyFullscreenWidget(
1184 fullscreen_widget_routing_id_));
1185 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1186 }
[email protected]b24b68a2012-09-24 21:57:261187}
1188
[email protected]b172aee2012-04-10 17:05:261189bool WebContentsImpl::PreHandleKeyboardEvent(
1190 const NativeWebKeyboardEvent& event,
1191 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481192 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131193 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481194}
1195
[email protected]b172aee2012-04-10 17:05:261196void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481197 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131198 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481199}
1200
[email protected]d92026ef2014-03-03 21:04:131201bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461202 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191203#if !defined(OS_MACOSX)
1204 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1205 // isn't done for two reasons:
1206 // -the OS already has a gesture to do this through pinch-zoom
1207 // -if a user starts an inertial scroll, let's go, and presses control
1208 // (i.e. control+tab) then the OS's buffered scroll events will come in
1209 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521210 if (delegate_ &&
1211 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551212 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1213 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1214 // gestures, which are regrettably easy to trigger accidentally.
1215 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521216 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1217 return true;
1218 }
[email protected]bccc4472013-04-18 16:37:191219#endif
[email protected]fb3f066e2013-02-12 19:12:521220 return false;
1221}
1222
[email protected]04bce562014-01-30 05:34:541223bool WebContentsImpl::PreHandleGestureEvent(
1224 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031225 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541226}
1227
[email protected]bab38af2014-03-30 17:37:291228bool WebContentsImpl::HandleGestureEvent(
1229 const blink::WebGestureEvent& event) {
1230 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1231 // Use them to implement browser zoom, as for HandleWheelEvent above.
1232 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1233 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1234 // The scale difference necessary to trigger a zoom action. Derived from
1235 // experimentation to find a value that feels reasonable.
1236 const float kZoomStepValue = 0.6f;
1237
1238 // Find the (absolute) thresholds on either side of the current zoom factor,
1239 // then convert those to actual numbers to trigger a zoom in or out.
1240 // This logic deliberately makes the range around the starting zoom value
1241 // for the gesture twice as large as the other ranges (i.e., the notches are
1242 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1243 // so that it's easier to get back to your starting point than it is to
1244 // overshoot.
1245 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1246 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1247 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1248 : -backStep;
1249 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1250 : backStep;
1251
[email protected]fb546cb2014-04-28 14:09:371252 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291253 if (totalPinchGestureAmount_ > zoomInThreshold) {
1254 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461255 if (delegate_)
1256 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291257 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1258 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461259 if (delegate_)
1260 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291261 }
1262 return true;
1263 }
1264
1265 return false;
1266}
1267
[email protected]2ceee8f2014-01-14 18:02:081268#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411269gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1270 return accessible_parent_;
1271}
1272#endif
1273
[email protected]b172aee2012-04-10 17:05:261274void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431275 if (delegate_)
1276 delegate_->HandleMouseDown();
1277}
1278
[email protected]b172aee2012-04-10 17:05:261279void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481280 if (delegate_)
1281 delegate_->HandleMouseUp();
1282}
1283
[email protected]590a634e2012-07-19 16:38:231284void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481285 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231286 delegate_->HandlePointerActivate();
1287}
1288
1289void WebContentsImpl::HandleGestureBegin() {
1290 if (delegate_)
1291 delegate_->HandleGestureBegin();
1292}
1293
1294void WebContentsImpl::HandleGestureEnd() {
1295 if (delegate_)
1296 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481297}
1298
[email protected]b172aee2012-04-10 17:05:261299void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491300 // This method is being called to enter or leave renderer-initiated fullscreen
1301 // mode. Either way, make sure any existing fullscreen widget is shut down
1302 // first.
1303 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1304 if (widget_view)
1305 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1306
[email protected]8a5e0ca2011-08-25 06:30:471307 if (delegate_)
1308 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371309
1310 FOR_EACH_OBSERVER(WebContentsObserver,
1311 observers_,
1312 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471313}
1314
[email protected]b172aee2012-04-10 17:05:261315bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381316 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121317}
1318
[email protected]a9c81f02012-06-01 00:15:441319void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1320 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371321 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441322 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371323 } else {
1324 GotResponseToLockMouseRequest(false);
1325 }
1326}
1327
[email protected]b172aee2012-04-10 17:05:261328void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371329 if (delegate_)
1330 delegate_->LostMouseLock();
1331}
1332
[email protected]bafe6cd2012-05-23 23:09:501333void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201334 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501335 int route_id,
[email protected]227692c52013-05-31 22:43:041336 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131337 const ViewHostMsg_CreateWindow_Params& params,
1338 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501339 // We usually create the new window in the same BrowsingInstance (group of
1340 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551341 // if the opener is being suppressed (in a non-guest), we create a new
1342 // SiteInstance in its own BrowsingInstance.
1343 bool is_guest = GetRenderProcessHost()->IsGuest();
1344
[email protected]04cbd3d2013-12-04 04:58:201345 // If the opener is to be suppressed, the new window can be in any process.
1346 // Since routing ids are process specific, we must not have one passed in
1347 // as argument here.
1348 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1349
[email protected]bafe6cd2012-05-23 23:09:501350 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551351 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571352 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501353 GetSiteInstance();
1354
[email protected]04cbd3d2013-12-04 04:58:201355 // A message to create a new window can only come from the active process for
1356 // this WebContentsImpl instance. If any other process sends the request,
1357 // it is invalid and the process must be terminated.
1358 if (GetRenderProcessHost()->GetID() != render_process_id) {
1359 base::ProcessHandle process_handle =
1360 RenderProcessHost::FromID(render_process_id)->GetHandle();
1361 if (process_handle != base::kNullProcessHandle) {
1362 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391363 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201364 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1365 }
1366 return;
1367 }
1368
[email protected]d1198fd2012-08-13 22:50:191369 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341370 //
1371 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301372 const std::string& partition_id =
1373 GetContentClient()->browser()->
1374 GetStoragePartitionIdForSite(GetBrowserContext(),
1375 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461376 StoragePartition* partition = BrowserContext::GetStoragePartition(
1377 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411378 DOMStorageContextWrapper* dom_storage_context =
1379 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191380 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1381 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1382 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371383
1384 if (delegate_ &&
1385 !delegate_->ShouldCreateWebContents(this,
1386 route_id,
1387 params.window_container_type,
1388 params.frame_name,
1389 params.target_url,
1390 partition_id,
1391 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011392 if (route_id != MSG_ROUTING_NONE &&
1393 !RenderViewHost::FromID(render_process_id, route_id)) {
1394 // If the embedder didn't create a WebContents for this route, we need to
1395 // delete the RenderView that had already been created.
1396 Send(new ViewMsg_Close(route_id));
1397 }
[email protected]dd6730412013-08-14 15:03:371398 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1399 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1400 main_frame_route_id);
1401 return;
1402 }
1403
1404 // Create the new web contents. This will automatically create the new
1405 // WebContentsView. In the future, we may want to create the view separately.
1406 WebContentsImpl* new_contents =
1407 new WebContentsImpl(GetBrowserContext(),
1408 params.opener_suppressed ? NULL : this);
1409
[email protected]d1198fd2012-08-13 22:50:191410 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301411 partition_id,
[email protected]d1198fd2012-08-13 22:50:191412 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461413 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591414 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041415 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551416 if (!is_guest) {
1417 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451418 create_params.initial_size = GetContainerBounds().size();
[email protected]c4538072013-03-18 02:17:551419 } else {
1420 // This makes |new_contents| act as a guest.
1421 // For more info, see comment above class BrowserPluginGuest.
[email protected]24569262014-05-06 03:31:301422 int instance_id =
[email protected]139355f2014-05-11 14:21:281423 GetBrowserContext()->GetGuestManager()->GetNextInstanceID();
[email protected]c4538072013-03-18 02:17:551424 WebContentsImpl* new_contents_impl =
1425 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461426 BrowserPluginGuest::CreateWithOpener(instance_id,
1427 new_contents_impl->opener() != NULL,
1428 new_contents_impl,
1429 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551430 }
[email protected]1ac10dca2013-08-20 20:47:041431 if (params.disposition == NEW_BACKGROUND_TAB)
1432 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591433 new_contents->Init(create_params);
[email protected]3d1dc3a2014-05-17 17:17:261434 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191435
[email protected]c4538072013-03-18 02:17:551436 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341437 // will be shown immediately).
1438 if (!params.opener_suppressed) {
1439 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451440 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501441
[email protected]d70bea92013-04-05 04:23:341442 // TODO(brettw): It seems bogus that we have to call this function on the
1443 // newly created object and give it one of its own member variables.
1444 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1445 }
[email protected]bafe6cd2012-05-23 23:09:501446 // Save the created window associated with the route so we can show it
1447 // later.
1448 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1449 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101450 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501451 }
1452
1453 if (delegate_) {
1454 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071455 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131456 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501457 }
1458
1459 if (params.opener_suppressed) {
1460 // When the opener is suppressed, the original renderer cannot access the
1461 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001462 bool was_blocked = false;
1463 if (delegate_) {
1464 gfx::Rect initial_pos;
1465 delegate_->AddNewContents(
1466 this, new_contents, params.disposition, initial_pos,
1467 params.user_gesture, &was_blocked);
1468 }
1469 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211470 OpenURLParams open_params(params.target_url,
1471 Referrer(),
1472 CURRENT_TAB,
1473 PAGE_TRANSITION_LINK,
1474 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301475 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001476 new_contents->OpenURL(open_params);
1477 }
[email protected]bafe6cd2012-05-23 23:09:501478 }
1479}
1480
[email protected]a8504022013-12-04 20:23:511481void WebContentsImpl::CreateNewWidget(int render_process_id,
1482 int route_id,
[email protected]180ef242013-11-07 06:50:461483 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511484 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501485}
1486
[email protected]a8504022013-12-04 20:23:511487void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1488 int route_id) {
1489 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501490}
1491
[email protected]a8504022013-12-04 20:23:511492void WebContentsImpl::CreateNewWidget(int render_process_id,
1493 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501494 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461495 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211496 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511497 // A message to create a new widget can only come from the active process for
1498 // this WebContentsImpl instance. If any other process sends the request,
1499 // it is invalid and the process must be terminated.
1500 if (process->GetID() != render_process_id) {
1501 base::ProcessHandle process_handle =
1502 RenderProcessHost::FromID(render_process_id)->GetHandle();
1503 if (process_handle != base::kNullProcessHandle) {
1504 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391505 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511506 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1507 }
1508 return;
1509 }
1510
[email protected]bafe6cd2012-05-23 23:09:501511 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041512 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261513 created_widgets_.insert(widget_host);
1514
[email protected]cfd80b02014-05-01 17:46:481515 RenderWidgetHostViewBase* widget_view =
1516 static_cast<RenderWidgetHostViewBase*>(
1517 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191518 if (!widget_view)
1519 return;
[email protected]bafe6cd2012-05-23 23:09:501520 if (!is_fullscreen) {
1521 // Popups should not get activated.
1522 widget_view->SetPopupType(popup_type);
1523 }
1524 // Save the created widget associated with the route so we can show it later.
1525 pending_widget_views_[route_id] = widget_view;
1526
1527#if defined(OS_MACOSX)
1528 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1529 // to allow it to survive the trip without being hosted.
1530 base::mac::NSObjectRetain(widget_view->GetNativeView());
1531#endif
1532}
1533
1534void WebContentsImpl::ShowCreatedWindow(int route_id,
1535 WindowOpenDisposition disposition,
1536 const gfx::Rect& initial_pos,
1537 bool user_gesture) {
1538 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001539 if (contents) {
1540 WebContentsDelegate* delegate = GetDelegate();
1541 if (delegate) {
1542 delegate->AddNewContents(
1543 this, contents, disposition, initial_pos, user_gesture, NULL);
1544 }
1545 }
[email protected]bafe6cd2012-05-23 23:09:501546}
1547
1548void WebContentsImpl::ShowCreatedWidget(int route_id,
1549 const gfx::Rect& initial_pos) {
1550 ShowCreatedWidget(route_id, false, initial_pos);
1551}
1552
1553void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1554 ShowCreatedWidget(route_id, true, gfx::Rect());
1555}
1556
1557void WebContentsImpl::ShowCreatedWidget(int route_id,
1558 bool is_fullscreen,
1559 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481560 RenderWidgetHostViewBase* widget_host_view =
1561 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501562 if (!widget_host_view)
1563 return;
[email protected]cfd80b02014-05-01 17:46:481564
1565 RenderWidgetHostView* view = NULL;
1566 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1567 if (guest && guest->embedder_web_contents()) {
1568 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1569 } else {
1570 view = GetRenderWidgetHostView();
1571 }
1572
[email protected]4aebbca2013-09-17 22:26:491573 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311574 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1575 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491576 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1577 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1578 delegate_->ToggleFullscreenModeForTab(this, true);
1579 } else {
[email protected]cfd80b02014-05-01 17:46:481580 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491581 }
[email protected]4aebbca2013-09-17 22:26:491582 FOR_EACH_OBSERVER(WebContentsObserver,
1583 observers_,
1584 DidShowFullscreenWidget(route_id));
1585 if (!widget_host_view->HasFocus())
1586 widget_host_view->Focus();
1587 } else {
[email protected]cfd80b02014-05-01 17:46:481588 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491589 }
[email protected]89054502012-06-03 10:29:241590
1591 RenderWidgetHostImpl* render_widget_host_impl =
1592 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1593 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311594 // Only allow privileged mouse lock for fullscreen render widget, which is
1595 // used to implement Pepper Flash fullscreen.
1596 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501597
1598#if defined(OS_MACOSX)
1599 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1600 // properly embedded (or purposefully ignored) we can release the retain we
1601 // took in CreateNewWidget().
1602 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1603#endif
1604}
1605
1606WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1607 PendingContents::iterator iter = pending_contents_.find(route_id);
1608
1609 // Certain systems can block the creation of new windows. If we didn't succeed
1610 // in creating one, just return NULL.
1611 if (iter == pending_contents_.end()) {
1612 return NULL;
1613 }
1614
1615 WebContentsImpl* new_contents = iter->second;
1616 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101617 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501618
[email protected]d70bea92013-04-05 04:23:341619 // Don't initialize the guest WebContents immediately.
1620 if (new_contents->GetRenderProcessHost()->IsGuest())
1621 return new_contents;
1622
[email protected]bafe6cd2012-05-23 23:09:501623 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1624 !new_contents->GetRenderViewHost()->GetView())
1625 return NULL;
1626
1627 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1628 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1629 return new_contents;
1630}
1631
1632RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1633 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1634 if (iter == pending_widget_views_.end()) {
1635 DCHECK(false);
1636 return NULL;
1637 }
1638
1639 RenderWidgetHostView* widget_host_view = iter->second;
1640 pending_widget_views_.erase(route_id);
1641
1642 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1643 if (!widget_host->GetProcess()->HasConnection()) {
1644 // The view has gone away or the renderer crashed. Nothing to do.
1645 return NULL;
1646 }
1647
1648 return widget_host_view;
1649}
1650
[email protected]f13b4202012-06-12 23:53:231651void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091652 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211653 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371654 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231655 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371656 } else {
1657 callback.Run(MediaStreamDevices(),
1658 MEDIA_DEVICE_INVALID_STATE,
1659 scoped_ptr<MediaStreamUI>());
1660 }
[email protected]f13b4202012-06-12 23:53:231661}
1662
[email protected]cc9200432013-07-23 23:02:401663SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1664 SiteInstance* instance) {
1665 return controller_.GetSessionStorageNamespace(instance);
1666}
1667
[email protected]9b159a52013-10-03 17:24:551668FrameTree* WebContentsImpl::GetFrameTree() {
1669 return &frame_tree_;
1670}
1671
[email protected]31a71eaf2014-03-13 01:47:361672void WebContentsImpl::AccessibilityEventReceived(
1673 const std::vector<AXEventNotificationDetails>& details) {
1674 FOR_EACH_OBSERVER(
1675 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1676}
1677
[email protected]edc3af82013-12-12 21:24:071678void WebContentsImpl::OnShowValidationMessage(
1679 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291680 const base::string16& main_text,
1681 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071682 if (delegate_)
1683 delegate_->ShowValidationMessage(
1684 this, anchor_in_root_view, main_text, sub_text);
1685}
1686
1687void WebContentsImpl::OnHideValidationMessage() {
1688 if (delegate_)
1689 delegate_->HideValidationMessage(this);
1690}
1691
1692void WebContentsImpl::OnMoveValidationMessage(
1693 const gfx::Rect& anchor_in_root_view) {
1694 if (delegate_)
1695 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1696}
1697
[email protected]32deec62013-05-15 23:55:041698void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1699 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441700 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041701}
1702
[email protected]b172aee2012-04-10 17:05:261703void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491704 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231705 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491706 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331707}
1708
[email protected]b172aee2012-04-10 17:05:261709void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341710 if (delegate_)
1711 delegate_->ResizeDueToAutoResize(this, new_size);
1712}
1713
[email protected]b172aee2012-04-10 17:05:261714WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201715 if (!delegate_)
1716 return NULL;
[email protected]00c37fc2011-08-02 00:22:501717
[email protected]e5d549d2011-12-28 01:29:201718 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201719 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341720}
1721
[email protected]6b618e62012-08-16 12:59:181722bool WebContentsImpl::Send(IPC::Message* message) {
1723 if (!GetRenderViewHost()) {
1724 delete message;
1725 return false;
1726 }
1727
1728 return GetRenderViewHost()->Send(message);
1729}
1730
[email protected]b172aee2012-04-10 17:05:261731bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501732 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261733 FrameTreeNode* node = frame_tree_.root();
1734
1735 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1736 // specified in the pending entry.
1737 NavigationEntryImpl* pending_entry =
1738 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1739 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1740 pending_entry->frame_tree_node_id() != -1) {
1741 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1742 }
1743
1744 return node->navigator()->NavigateToPendingEntry(
1745 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541746}
[email protected]96d185d2009-04-24 03:28:541747
[email protected]a86c0e962013-12-17 17:10:391748void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1749 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441750 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391751 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441752}
1753
[email protected]20ca0382013-02-28 19:50:071754void WebContentsImpl::AttachInterstitialPage(
1755 InterstitialPageImpl* interstitial_page) {
1756 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211757 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291758
1759 // Cancel any visible dialogs so that they don't interfere with the
1760 // interstitial.
1761 if (dialog_manager_)
1762 dialog_manager_->CancelActiveAndPendingDialogs(this);
1763
[email protected]20ca0382013-02-28 19:50:071764 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1765 DidAttachInterstitialPage());
1766}
1767
1768void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571769 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211770 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071771 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1772 DidDetachInterstitialPage());
1773}
1774
[email protected]b172aee2012-04-10 17:05:261775void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331776 const SiteInstance* site_instance,
1777 int history_length,
1778 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411779 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1780 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211781 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191782 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141783 return;
[email protected]9e1ad4b2011-08-14 16:49:191784 }
[email protected]9f76c1e2012-03-05 15:15:581785 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191786 if (!rvh) {
1787 NOTREACHED();
1788 return;
1789 }
[email protected]9f76c1e2012-03-05 15:15:581790 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191791 NOTREACHED();
1792 return;
1793 }
[email protected]6b618e62012-08-16 12:59:181794 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1795 history_length,
1796 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141797}
1798
[email protected]4fed3702014-04-01 09:08:001799void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171800 RenderFrameHost* focused_frame = GetFocusedFrame();
1801 if (!focused_frame)
1802 return;
1803
[email protected]959be4c2014-04-08 15:01:331804 focused_frame->Send(new FrameMsg_Reload(
1805 focused_frame->GetRoutingID(), ignore_cache));
1806}
1807
1808void WebContentsImpl::Undo() {
1809 RenderFrameHost* focused_frame = GetFocusedFrame();
1810 if (!focused_frame)
1811 return;
1812
1813 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1814 RecordAction(base::UserMetricsAction("Undo"));
1815}
1816
1817void WebContentsImpl::Redo() {
1818 RenderFrameHost* focused_frame = GetFocusedFrame();
1819 if (!focused_frame)
1820 return;
1821 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1822 RecordAction(base::UserMetricsAction("Redo"));
1823}
1824
1825void WebContentsImpl::Cut() {
1826 RenderFrameHost* focused_frame = GetFocusedFrame();
1827 if (!focused_frame)
1828 return;
1829
1830 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1831 RecordAction(base::UserMetricsAction("Cut"));
1832}
1833
1834void WebContentsImpl::Copy() {
1835 RenderFrameHost* focused_frame = GetFocusedFrame();
1836 if (!focused_frame)
1837 return;
1838
1839 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1840 RecordAction(base::UserMetricsAction("Copy"));
1841}
1842
1843void WebContentsImpl::CopyToFindPboard() {
1844#if defined(OS_MACOSX)
1845 RenderFrameHost* focused_frame = GetFocusedFrame();
1846 if (!focused_frame)
1847 return;
1848
1849 // Windows/Linux don't have the concept of a find pasteboard.
1850 focused_frame->Send(
1851 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1852 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1853#endif
1854}
1855
1856void WebContentsImpl::Paste() {
1857 RenderFrameHost* focused_frame = GetFocusedFrame();
1858 if (!focused_frame)
1859 return;
1860
1861 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1862 RecordAction(base::UserMetricsAction("Paste"));
1863}
1864
1865void WebContentsImpl::PasteAndMatchStyle() {
1866 RenderFrameHost* focused_frame = GetFocusedFrame();
1867 if (!focused_frame)
1868 return;
1869
1870 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1871 focused_frame->GetRoutingID()));
1872 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1873}
1874
1875void WebContentsImpl::Delete() {
1876 RenderFrameHost* focused_frame = GetFocusedFrame();
1877 if (!focused_frame)
1878 return;
1879
1880 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1881 RecordAction(base::UserMetricsAction("DeleteSelection"));
1882}
1883
1884void WebContentsImpl::SelectAll() {
1885 RenderFrameHost* focused_frame = GetFocusedFrame();
1886 if (!focused_frame)
1887 return;
1888
1889 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1890 RecordAction(base::UserMetricsAction("SelectAll"));
1891}
1892
1893void WebContentsImpl::Unselect() {
1894 RenderFrameHost* focused_frame = GetFocusedFrame();
1895 if (!focused_frame)
1896 return;
1897
1898 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1899 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171900}
1901
1902void WebContentsImpl::Replace(const base::string16& word) {
1903 RenderFrameHost* focused_frame = GetFocusedFrame();
1904 if (!focused_frame)
1905 return;
1906
[email protected]959be4c2014-04-08 15:01:331907 focused_frame->Send(new InputMsg_Replace(
1908 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171909}
1910
1911void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1912 RenderFrameHost* focused_frame = GetFocusedFrame();
1913 if (!focused_frame)
1914 return;
1915
[email protected]959be4c2014-04-08 15:01:331916 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1917 focused_frame->GetRoutingID(), word));
1918}
1919
1920void WebContentsImpl::NotifyContextMenuClosed(
1921 const CustomContextMenuContext& context) {
1922 RenderFrameHost* focused_frame = GetFocusedFrame();
1923 if (!focused_frame)
1924 return;
1925
1926 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1927 focused_frame->GetRoutingID(), context));
1928}
1929
1930void WebContentsImpl::ExecuteCustomContextMenuCommand(
1931 int action, const CustomContextMenuContext& context) {
1932 RenderFrameHost* focused_frame = GetFocusedFrame();
1933 if (!focused_frame)
1934 return;
1935
1936 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1937 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001938}
1939
[email protected]fc2b46b2014-05-03 16:33:451940gfx::NativeView WebContentsImpl::GetNativeView() {
1941 return view_->GetNativeView();
1942}
1943
1944gfx::NativeView WebContentsImpl::GetContentNativeView() {
1945 return view_->GetContentNativeView();
1946}
1947
1948gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1949 return view_->GetTopLevelNativeWindow();
1950}
1951
1952gfx::Rect WebContentsImpl::GetViewBounds() {
1953 return view_->GetViewBounds();
1954}
1955
1956gfx::Rect WebContentsImpl::GetContainerBounds() {
1957 gfx::Rect rv;
1958 view_->GetContainerBounds(&rv);
1959 return rv;
1960}
1961
1962DropData* WebContentsImpl::GetDropData() {
1963 return view_->GetDropData();
1964}
1965
1966void WebContentsImpl::Focus() {
1967 view_->Focus();
1968}
1969
1970void WebContentsImpl::SetInitialFocus() {
1971 view_->SetInitialFocus();
1972}
1973
1974void WebContentsImpl::StoreFocus() {
1975 view_->StoreFocus();
1976}
1977
1978void WebContentsImpl::RestoreFocus() {
1979 view_->RestoreFocus();
1980}
1981
[email protected]b172aee2012-04-10 17:05:261982void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271983 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211984 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541985 return;
1986 }
[email protected]9f76c1e2012-03-05 15:15:581987 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541988}
1989
[email protected]b172aee2012-04-10 17:05:261990bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211991 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541992}
1993
[email protected]b172aee2012-04-10 17:05:261994InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211995 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221996}
1997
[email protected]b172aee2012-04-10 17:05:261998bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161999 // WebKit creates Document object when MIME type is application/xhtml+xml,
2000 // so we also support this MIME type.
2001 return contents_mime_type_ == "text/html" ||
2002 contents_mime_type_ == "text/xml" ||
2003 contents_mime_type_ == "application/xhtml+xml" ||
2004 contents_mime_type_ == "text/plain" ||
2005 contents_mime_type_ == "text/css" ||
2006 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2007}
2008
[email protected]b172aee2012-04-10 17:05:262009void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592010 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162011 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552012 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012013 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142014 return;
[email protected]c7dd2f62011-07-18 15:57:592015 }
2016
2017 Stop();
2018
2019 // Create the save package and possibly prompt the user for the name to save
2020 // the page as. The user prompt is an asynchronous operation that runs on
2021 // another thread.
2022 save_package_ = new SavePackage(this);
2023 save_package_->GetSaveInfo();
2024}
2025
2026// Used in automated testing to bypass prompting the user for file names.
2027// Instead, the names and paths are hard coded rather than running them through
2028// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342029bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2030 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212031 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592032 // Stop the page from navigating.
2033 Stop();
2034
2035 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212036 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592037}
2038
[email protected]3c71576ce2013-07-23 02:00:012039void WebContentsImpl::SaveFrame(const GURL& url,
2040 const Referrer& referrer) {
2041 if (!GetURL().is_valid())
2042 return;
2043 bool is_main_frame = (url == GetURL());
2044
2045 DownloadManager* dlm =
2046 BrowserContext::GetDownloadManager(GetBrowserContext());
2047 if (!dlm)
2048 return;
2049 int64 post_id = -1;
2050 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272051 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012052 if (entry)
2053 post_id = entry->GetPostID();
2054 }
2055 scoped_ptr<DownloadUrlParameters> params(
2056 DownloadUrlParameters::FromWebContents(this, url));
2057 params->set_referrer(referrer);
2058 params->set_post_id(post_id);
2059 params->set_prefer_cache(true);
2060 if (post_id >= 0)
2061 params->set_method("POST");
2062 params->set_prompt(true);
2063 dlm->DownloadUrl(params.Pass());
2064}
2065
[email protected]b172aee2012-04-10 17:05:262066void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342067 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482068 const base::Callback<void(int64)>& callback) {
2069 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122070}
2071
[email protected]6286a372013-10-09 04:03:272072// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262073bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272074 NavigationEntryImpl* visible_entry =
2075 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2076 return (visible_entry != NULL &&
2077 visible_entry->site_instance() == GetSiteInstance() &&
2078 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322079}
2080
[email protected]b172aee2012-04-10 17:05:262081const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272082 return contents_mime_type_;
2083}
2084
[email protected]b172aee2012-04-10 17:05:262085bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272086 return notify_disconnection_;
2087}
2088
[email protected]b172aee2012-04-10 17:05:262089void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312090 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182091 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162092}
2093
[email protected]b172aee2012-04-10 17:05:262094void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542095 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182096 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162097}
2098
[email protected]8ff00d72012-10-23 19:12:212099RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272100 return &renderer_preferences_;
2101}
2102
[email protected]e35ccd52012-05-23 16:22:472103void WebContentsImpl::Close() {
2104 Close(GetRenderViewHost());
2105}
2106
[email protected]cf200a562013-05-03 16:24:292107void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462108 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292109 if (browser_plugin_embedder_.get())
2110 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2111 screen_x, screen_y, operation);
2112 if (GetRenderViewHost())
2113 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2114 screen_x, screen_y, operation);
2115}
2116
[email protected]d60f3702013-12-26 16:30:242117void WebContentsImpl::DidGetResourceResponseStart(
2118 const ResourceRequestDetails& details) {
2119 controller_.ssl_manager()->DidStartResourceResponse(details);
2120
2121 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2122 DidGetResourceResponseStart(details));
2123
2124 // TODO(avi): Remove. http://crbug.com/170921
2125 NotificationService::current()->Notify(
2126 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2127 Source<WebContents>(this),
2128 Details<const ResourceRequestDetails>(&details));
2129}
2130
2131void WebContentsImpl::DidGetRedirectForResourceRequest(
2132 RenderViewHost* render_view_host,
2133 const ResourceRedirectDetails& details) {
2134 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2135
2136 FOR_EACH_OBSERVER(
2137 WebContentsObserver,
2138 observers_,
2139 DidGetRedirectForResourceRequest(render_view_host, details));
2140
2141 // TODO(avi): Remove. http://crbug.com/170921
2142 NotificationService::current()->Notify(
2143 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2144 Source<WebContents>(this),
2145 Details<const ResourceRedirectDetails>(&details));
2146}
2147
[email protected]b172aee2012-04-10 17:05:262148void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522149 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582150 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512151 if (delegate_)
2152 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292153 if (browser_plugin_embedder_.get())
2154 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342155}
2156
[email protected]e35ccd52012-05-23 16:22:472157void WebContentsImpl::UserGestureDone() {
2158 OnUserGesture();
2159}
2160
[email protected]b172aee2012-04-10 17:05:262161void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272162 closed_by_user_gesture_ = value;
2163}
2164
[email protected]b172aee2012-04-10 17:05:262165bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272166 return closed_by_user_gesture_;
2167}
2168
[email protected]b172aee2012-04-10 17:05:262169double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052170 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562171 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252172 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172173 return 0;
[email protected]b75b8292010-10-01 07:28:252174
2175 double zoom_level;
2176 if (temporary_zoom_settings_) {
2177 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582178 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252179 } else {
[email protected]2ae88d12011-10-14 09:11:192180 GURL url;
[email protected]6286a372013-10-09 04:03:272181 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192182 // Since zoom map is updated using rewritten URL, use rewritten URL
2183 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272184 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022185 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2186 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252187 }
[email protected]d0b8d092010-10-25 04:05:172188 return zoom_level;
2189}
[email protected]b75b8292010-10-01 07:28:252190
[email protected]b172aee2012-04-10 17:05:262191int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592192 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172193 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012194 // Calculate the zoom percent from the factor. Round up to the nearest whole
2195 // number.
[email protected]b75b8292010-10-01 07:28:252196 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492197 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252198 *enable_decrement = percent > minimum_zoom_percent_;
2199 *enable_increment = percent < maximum_zoom_percent_;
2200 return percent;
2201}
2202
[email protected]b172aee2012-04-10 17:05:262203void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502204 if (!delegate_)
2205 return;
2206
[email protected]6286a372013-10-09 04:03:272207 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2208 if (!entry)
[email protected]1788e772010-12-15 16:40:502209 return;
2210
[email protected]6286a372013-10-09 04:03:272211 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122212}
2213
[email protected]b172aee2012-04-10 17:05:262214void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042215 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272216 if (!delegate_)
2217 return;
2218
[email protected]691aa2f2013-05-28 22:52:042219 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272220}
2221
[email protected]b172aee2012-04-10 17:05:262222int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272223 return minimum_zoom_percent_;
2224}
2225
[email protected]b172aee2012-04-10 17:05:262226int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272227 return maximum_zoom_percent_;
2228}
2229
[email protected]b172aee2012-04-10 17:05:262230gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492231 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232232}
2233
[email protected]b172aee2012-04-10 17:05:262234bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052235 if (GetBrowserPluginGuest())
2236 return GetBrowserPluginGuest()->LockMouse(allowed);
2237
[email protected]0bfbf882011-12-22 18:19:272238 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582239 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272240}
2241
[email protected]b172aee2012-04-10 17:05:262242bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442243 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502244}
2245
[email protected]cb805452013-05-22 15:16:212246void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482247 if (!color_chooser_info_.get())
2248 return;
2249 RenderFrameHost* rfh = RenderFrameHost::FromID(
2250 color_chooser_info_->render_process_id,
2251 color_chooser_info_->render_frame_id);
2252 if (!rfh)
2253 return;
2254
2255 rfh->Send(new FrameMsg_DidChooseColorResponse(
2256 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202257}
2258
[email protected]cb805452013-05-22 15:16:212259void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482260 if (!color_chooser_info_.get())
2261 return;
2262 RenderFrameHost* rfh = RenderFrameHost::FromID(
2263 color_chooser_info_->render_process_id,
2264 color_chooser_info_->render_frame_id);
2265 if (!rfh)
2266 return;
2267
2268 rfh->Send(new FrameMsg_DidEndColorChooser(
2269 rfh->GetRoutingID(), color_chooser_info_->identifier));
2270 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202271}
2272
[email protected]41225fe2013-03-29 05:32:022273int WebContentsImpl::DownloadImage(const GURL& url,
2274 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302275 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022276 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582277 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022278 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392279 return id;
2280}
2281
[email protected]5dcaf8e2013-12-28 01:31:422282bool WebContentsImpl::IsSubframe() const {
2283 return is_subframe_;
2284}
2285
[email protected]9649d492014-01-10 07:15:522286void WebContentsImpl::SetZoomLevel(double level) {
2287 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2288 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2289 if (embedder)
2290 embedder->SetZoomLevel(level);
2291}
2292
[email protected]36ec24f2014-01-09 00:32:082293void WebContentsImpl::Find(int request_id,
2294 const base::string16& search_text,
2295 const blink::WebFindOptions& options) {
2296 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2297}
2298
2299void WebContentsImpl::StopFinding(StopFindAction action) {
2300 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2301}
2302
[email protected]4fe53add2014-04-08 19:53:362303void WebContentsImpl::InsertCSS(const std::string& css) {
2304 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2305 GetMainFrame()->GetRoutingID(), css));
2306}
2307
[email protected]b172aee2012-04-10 17:05:262308bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272309 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202310 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332311 return true;
2312 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272313}
2314
[email protected]b172aee2012-04-10 17:05:262315void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272316 if (delegate_)
2317 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212318}
2319
[email protected]52913802013-12-10 05:52:182320void WebContentsImpl::DidStartProvisionalLoad(
2321 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072322 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182323 const GURL& validated_url,
2324 bool is_error_page,
2325 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262326 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]d974a0a2013-01-10 01:43:572327
[email protected]0d60f0192011-04-14 12:40:102328 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272329 int render_frame_id = render_frame_host->GetRoutingID();
2330 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252331 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072332 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272333 render_frame_id, parent_routing_id, is_main_frame,
2334 validated_url, is_error_page, is_iframe_srcdoc,
2335 render_view_host));
[email protected]400992b2012-06-14 00:03:542336
2337 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182338 FOR_EACH_OBSERVER(
2339 WebContentsObserver,
2340 observers_,
2341 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582342 render_frame_host));
[email protected]400992b2012-06-14 00:03:542343 }
2344}
2345
[email protected]3109fbb72014-01-06 23:57:152346void WebContentsImpl::DidFailProvisionalLoadWithError(
2347 RenderFrameHostImpl* render_frame_host,
2348 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2349 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272350 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262351 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272352 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152353 FOR_EACH_OBSERVER(
2354 WebContentsObserver,
2355 observers_,
[email protected]161eabd2014-03-19 19:47:272356 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152357 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262358 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152359 validated_url,
2360 params.error_code,
2361 params.error_description,
[email protected]161eabd2014-03-19 19:47:272362 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152363}
2364
[email protected]b80624c2014-02-09 02:46:552365void WebContentsImpl::DidFailLoadWithError(
2366 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552367 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552368 int error_code,
2369 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272370 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262371 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272372 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552373 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272374 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262375 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552376}
2377
[email protected]52913802013-12-10 05:52:182378void WebContentsImpl::NotifyChangedNavigationState(
2379 InvalidateTypes changed_flags) {
2380 NotifyNavigationStateChanged(changed_flags);
2381}
2382
[email protected]3691e5cf2014-01-22 10:16:202383void WebContentsImpl::AboutToNavigateRenderFrame(
2384 RenderFrameHostImpl* render_frame_host) {
2385 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272386 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202387 FOR_EACH_OBSERVER(
2388 WebContentsObserver,
2389 observers_,
[email protected]161eabd2014-03-19 19:47:272390 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202391}
2392
2393void WebContentsImpl::DidStartNavigationToPendingEntry(
2394 RenderFrameHostImpl* render_frame_host,
2395 const GURL& url,
2396 NavigationController::ReloadType reload_type) {
2397 // Notify observers about navigation.
2398 FOR_EACH_OBSERVER(
2399 WebContentsObserver,
2400 observers_,
2401 DidStartNavigationToPendingEntry(url, reload_type));
2402}
2403
[email protected]8cb834e2014-03-06 14:23:232404void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2405 const OpenURLParams& params) {
2406 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182407 WebContents* new_contents = OpenURL(params);
2408
2409 if (new_contents) {
2410 // Notify observers.
2411 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2412 DidOpenRequestedURL(new_contents,
2413 params.url,
2414 params.referrer,
2415 params.disposition,
2416 params.transition,
[email protected]8cb834e2014-03-06 14:23:232417 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182418 }
2419}
2420
[email protected]aa62afd2014-04-22 19:22:462421bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2422 if (!delegate_)
2423 return false;
2424 return delegate_->ShouldPreserveAbortedURLs(this);
2425}
2426
[email protected]400992b2012-06-14 00:03:542427void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582428 RenderFrameHostImpl* render_frame_host,
2429 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542430 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582431 FOR_EACH_OBSERVER(
2432 WebContentsObserver,
2433 observers_,
2434 ProvisionalChangeToMainFrameUrl(validated_target_url,
2435 render_frame_host));
[email protected]724159a2010-12-30 01:11:182436}
2437
[email protected]37567b432014-02-12 01:12:222438void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432439 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222440 const base::string16& frame_unique_name,
2441 bool is_main_frame,
2442 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432443 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432444 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272445 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222446 // Notify observers about the commit of the provisional load.
2447 FOR_EACH_OBSERVER(
2448 WebContentsObserver,
2449 observers_,
[email protected]27dd82fd2014-03-03 22:11:432450 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222451 frame_unique_name,
2452 is_main_frame,
2453 url,
2454 transition_type,
2455 render_view_host));
2456}
2457
[email protected]0d0f4c492014-04-02 06:42:572458void WebContentsImpl::DidNavigateMainFramePreCommit(
2459 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2460 // Ensure fullscreen mode is exited before committing the navigation to a
2461 // different page. The next page will not start out assuming it is in
2462 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192463 if (controller_.IsURLInPageNavigation(params.url,
2464 params.was_within_same_page,
2465 NAVIGATION_TYPE_UNKNOWN)) {
2466 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572467 return;
2468 }
2469 if (IsFullscreenForCurrentTab())
2470 GetRenderViewHost()->ExitFullscreen();
2471 DCHECK(!IsFullscreenForCurrentTab());
2472}
2473
[email protected]37567b432014-02-12 01:12:222474void WebContentsImpl::DidNavigateMainFramePostCommit(
2475 const LoadCommittedDetails& details,
2476 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2477 if (details.is_navigation_to_different_page()) {
2478 // Clear the status bubble. This is a workaround for a bug where WebKit
2479 // doesn't let us know that the cursor left an element during a
2480 // transition (this is also why the mouse cursor remains as a hand after
2481 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2482 // clear the bubble when a user navigates to a named anchor in the same
2483 // page.
2484 UpdateTargetURL(details.entry->GetPageID(), GURL());
2485 }
2486
2487 if (!details.is_in_page) {
2488 // Once the main frame is navigated, we're no longer considered to have
2489 // displayed insecure content.
2490 displayed_insecure_content_ = false;
2491 SSLManager::NotifySSLInternalStateChanged(
2492 GetController().GetBrowserContext());
2493 }
2494
2495 // Notify observers about navigation.
2496 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2497 DidNavigateMainFrame(details, params));
2498
2499 if (delegate_) {
2500 delegate_->DidNavigateMainFramePostCommit(this);
2501 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2502 }
2503}
2504
2505void WebContentsImpl::DidNavigateAnyFramePostCommit(
2506 RenderFrameHostImpl* render_frame_host,
2507 const LoadCommittedDetails& details,
2508 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102509 // Now that something has committed, we don't need to track whether the
2510 // initial page has been accessed.
2511 has_accessed_initial_document_ = false;
2512
[email protected]37567b432014-02-12 01:12:222513 // If we navigate off the page, close all JavaScript dialogs.
2514 if (dialog_manager_ && !details.is_in_page)
2515 dialog_manager_->CancelActiveAndPendingDialogs(this);
2516
2517 // Notify observers about navigation.
2518 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2519 DidNavigateAnyFrame(details, params));
2520}
2521
2522void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2523 contents_mime_type_ = mime_type;
2524}
2525
2526bool WebContentsImpl::CanOverscrollContent() {
2527 if (delegate_)
2528 return delegate_->CanOverscrollContent();
2529
2530 return false;
2531}
2532
[email protected]b172aee2012-04-10 17:05:262533void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182534 const GURL& url,
[email protected]70435962011-08-02 20:13:282535 const std::string& security_info,
2536 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182537 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282538 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192539 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182540 cache.Increment();
2541
2542 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082543 int cert_id = 0;
2544 net::CertStatus cert_status = 0;
2545 int security_bits = -1;
2546 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122547 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212548 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122549 &security_bits, &connection_status,
2550 &signed_certificate_timestamp_ids);
2551 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212552 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002553 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2554 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182555
[email protected]b0f724c2013-09-05 04:21:132556 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2557
2558 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2559 DidLoadResourceFromMemoryCache(details));
2560
[email protected]8bfc8272013-09-09 20:10:532561 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2562 scoped_refptr<net::URLRequestContextGetter> request_context(
2563 resource_type == ResourceType::MEDIA ?
2564 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2565 GetRenderProcessHost()->GetID()) :
2566 GetBrowserContext()->GetRequestContextForRenderProcess(
2567 GetRenderProcessHost()->GetID()));
2568 BrowserThread::PostTask(
2569 BrowserThread::IO,
2570 FROM_HERE,
2571 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2572 }
[email protected]724159a2010-12-30 01:11:182573}
2574
[email protected]b172aee2012-04-10 17:05:262575void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392576 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182577 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192578 SSLManager::NotifySSLInternalStateChanged(
2579 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182580}
2581
[email protected]b172aee2012-04-10 17:05:262582void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022583 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582584 LOG(WARNING) << security_origin << " ran insecure content from "
2585 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392586 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412587 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392588 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182589 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412590 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192591 SSLManager::NotifySSLInternalStateChanged(
2592 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182593}
2594
[email protected]501052ff2014-02-21 22:19:072595void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572596 CHECK(render_frame_message_source_);
2597 CHECK(!render_view_message_source_);
2598 RenderFrameHostImpl* rfh =
2599 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2600
[email protected]161eabd2014-03-19 19:47:272601 int render_frame_id = rfh->GetRoutingID();
2602 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572603 FOR_EACH_OBSERVER(WebContentsObserver,
2604 observers_,
[email protected]161eabd2014-03-19 19:47:272605 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182606}
2607
[email protected]b172aee2012-04-10 17:05:262608void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262609 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372610 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122611 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2612 GetRenderProcessHost()->ReceivedBadMessage();
2613 return;
2614 }
[email protected]a1b99262013-12-27 21:56:222615
[email protected]8b3af1e2014-01-24 13:29:122616 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442617 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372618 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422619 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372620
[email protected]61ac9e242014-03-21 20:55:262621 RenderFrameHostImpl* rfh =
2622 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272623 int render_frame_id = rfh->GetRoutingID();
2624 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262625 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252626 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272627 DidFinishLoad(render_frame_id, validated_url,
2628 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312629}
2630
[email protected]960b0372014-05-19 18:01:002631void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2632 RenderFrameHostImpl* rfh =
2633 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2634 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2635
2636 // It is possible to get multiple calls to OnDidStartLoading that don't have
2637 // corresponding calls to OnDidStopLoading:
2638 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2639 // out for a cross-process navigation, and it turns into a placeholder for
2640 // one being rendered in a different process.
2641 // - Also, there might be more than one RenderFrameHost sharing the same
2642 // FrameTreeNode (and thus sharing its ID) each sending a start.
2643 // - But in the future, once clamy@ moves navigation network requests to the
2644 // browser process, there's a good chance that callbacks about starting and
2645 // stopping will all be handled by the browser. When that happens, there
2646 // should no longer be a start/stop call imbalance. TODO(avi): When this
2647 // future arrives, update this code to not allow this case.
2648 DCHECK_GE(loading_frames_in_progress_, 0);
2649 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2650 if (loading_frames_in_progress_ == 0)
2651 DidStartLoading(rfh, to_different_document);
2652 ++loading_frames_in_progress_;
2653 }
2654
2655 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2656 SendLoadProgressChanged();
2657}
2658
2659void WebContentsImpl::OnDidStopLoading() {
2660 RenderFrameHostImpl* rfh =
2661 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2662 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2663
2664 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2665 // Load stopped while we were still tracking load. Make sure we update
2666 // progress based on this frame's completion.
2667 loading_progresses_[render_frame_id] = 1.0;
2668 SendLoadProgressChanged();
2669 // Then we clean-up our states.
2670 if (loading_total_progress_ == 1.0)
2671 ResetLoadProgressState();
2672 }
2673
2674 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2675 // calls DidStopLoading() without a matching DidStartLoading().
2676 if (loading_frames_in_progress_ == 0)
2677 return;
2678 --loading_frames_in_progress_;
2679 if (loading_frames_in_progress_ == 0)
2680 DidStopLoading(rfh);
2681}
2682
2683void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2684 RenderFrameHostImpl* rfh =
2685 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2686 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2687
2688 loading_progresses_[render_frame_id] = load_progress;
2689
2690 // We notify progress change immediately for the first and last updates.
2691 // Also, since the message loop may be pretty busy when a page is loaded, it
2692 // might not execute a posted task in a timely manner so we make sure to
2693 // immediately send progress report if enough time has passed.
2694 base::TimeDelta min_delay =
2695 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2696 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2697 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2698 // If there is a pending task to send progress, it is now obsolete.
2699 loading_weak_factory_.InvalidateWeakPtrs();
2700 SendLoadProgressChanged();
2701 if (loading_total_progress_ == 1.0)
2702 ResetLoadProgressState();
2703 return;
2704 }
2705
2706 if (loading_weak_factory_.HasWeakPtrs())
2707 return;
2708
2709 base::MessageLoop::current()->PostDelayedTask(
2710 FROM_HERE,
2711 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2712 loading_weak_factory_.GetWeakPtr()),
2713 min_delay);
2714}
2715
[email protected]b172aee2012-04-10 17:05:262716void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222717 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2718 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262719}
2720
[email protected]b172aee2012-04-10 17:05:262721void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2722 int maximum_percent,
2723 bool remember) {
[email protected]216813952011-05-19 22:21:262724 minimum_zoom_percent_ = minimum_percent;
2725 maximum_zoom_percent_ = maximum_percent;
2726 temporary_zoom_settings_ = !remember;
2727}
2728
[email protected]b172aee2012-04-10 17:05:262729void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342730 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432731 if (!delegate_)
2732 return;
2733
[email protected]b9535422012-02-09 01:47:592734 ChildProcessSecurityPolicyImpl* policy =
2735 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222736 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592737 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212738}
2739
[email protected]b172aee2012-04-10 17:05:262740void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2741 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262742 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362743 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432744 if (!delegate_)
2745 return;
2746
[email protected]b9535422012-02-09 01:47:592747 ChildProcessSecurityPolicyImpl* policy =
2748 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322749 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592750 return;
[email protected]8f810632013-06-06 22:33:322751
[email protected]c125e532014-05-10 20:39:062752 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202753}
2754
[email protected]b172aee2012-04-10 17:05:262755void WebContentsImpl::OnFindReply(int request_id,
2756 int number_of_matches,
2757 const gfx::Rect& selection_rect,
2758 int active_match_ordinal,
2759 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432760 if (delegate_) {
2761 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2762 active_match_ordinal, final_update);
2763 }
[email protected]b888919c2011-09-02 00:32:162764}
2765
[email protected]59363fc92012-09-05 03:46:312766#if defined(OS_ANDROID)
2767void WebContentsImpl::OnFindMatchRectsReply(
2768 int version,
2769 const std::vector<gfx::RectF>& rects,
2770 const gfx::RectF& active_rect) {
2771 if (delegate_)
2772 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2773}
[email protected]583418cc2013-01-17 14:01:102774
[email protected]1ff427972013-02-07 21:14:072775void WebContentsImpl::OnOpenDateTimeDialog(
2776 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092777 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2778 GetRenderViewHost(),
2779 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132780 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092781 value.minimum,
2782 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172783 value.step,
2784 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102785}
2786
[email protected]59363fc92012-09-05 03:46:312787#endif
2788
[email protected]f114fa42013-12-06 17:06:442789void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2790 const base::FilePath& path,
2791 bool is_hung) {
2792 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2793
2794 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2795 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2796}
2797
2798void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422799 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442800 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422801 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452802}
2803
[email protected]cfa856d62014-02-22 07:58:402804void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2805 int automation_id) {
2806 DomOperationNotificationDetails details(json_string, automation_id);
2807 NotificationService::current()->Notify(
2808 NOTIFICATION_DOM_OPERATION_RESPONSE,
2809 Source<WebContents>(this),
2810 Details<DomOperationNotificationDetails>(&details));
2811}
2812
[email protected]b172aee2012-04-10 17:05:262813void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2814 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102815 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252816 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102817 AppCacheAccessed(manifest_url, blocked_by_policy));
2818}
2819
[email protected]8bc5ff02013-11-29 06:34:032820void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482821 int color_chooser_id,
2822 SkColor color,
2823 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462824 ColorChooser* new_color_chooser = delegate_ ?
2825 delegate_->OpenColorChooser(this, color, suggestions) :
2826 NULL;
[email protected]820957a2014-01-14 14:56:302827 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212828 return;
[email protected]8ed16472014-04-11 19:02:482829 if (color_chooser_info_.get())
2830 color_chooser_info_->chooser->End();
2831
2832 color_chooser_info_.reset(new ColorChooserInfo(
2833 render_frame_message_source_->GetProcess()->GetID(),
2834 render_frame_message_source_->GetRoutingID(),
2835 new_color_chooser,
2836 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202837}
2838
[email protected]b172aee2012-04-10 17:05:262839void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482840 if (color_chooser_info_ &&
2841 color_chooser_id == color_chooser_info_->identifier)
2842 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202843}
2844
[email protected]b172aee2012-04-10 17:05:262845void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322846 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482847 if (color_chooser_info_ &&
2848 color_chooser_id == color_chooser_info_->identifier)
2849 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202850}
2851
[email protected]d0759f492012-04-19 22:50:502852// This exists for render views that don't have a WebUI, but do have WebUI
2853// bindings enabled.
2854void WebContentsImpl::OnWebUISend(const GURL& source_url,
2855 const std::string& name,
2856 const base::ListValue& args) {
2857 if (delegate_)
2858 delegate_->WebUISend(this, source_url, name, args);
2859}
2860
[email protected]d8415ad92012-08-23 14:40:502861void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442862 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502863 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342864 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162865 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442866 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162867 return;
[email protected]d8415ad92012-08-23 14:40:502868 }
2869
[email protected]8c8fc292012-11-23 18:57:162870 if (!delegate_->RequestPpapiBrokerPermission(
2871 this, url, plugin_path,
2872 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442873 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162874 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442875 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162876 }
[email protected]d8415ad92012-08-23 14:40:502877}
2878
[email protected]ea0309c2013-08-06 19:35:442879void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502880 bool result) {
[email protected]ea0309c2013-08-06 19:35:442881 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502882}
2883
[email protected]c4538072013-03-18 02:17:552884void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372885 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082886 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552887 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392888 // For more info, see comment above classes BrowserPluginEmbedder and
2889 // BrowserPluginGuest.
2890 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142891 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082892 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372893}
2894
[email protected]41225fe2013-03-29 05:32:022895void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392896 int id,
[email protected]749fadd2013-05-15 08:37:482897 int http_status_code,
[email protected]795c28972012-12-06 06:13:392898 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302899 const std::vector<SkBitmap>& bitmaps,
2900 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132901 if (bitmaps.size() != original_bitmap_sizes.size())
2902 return;
2903
[email protected]41225fe2013-03-29 05:32:022904 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2905 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392906 // Currently WebContents notifies us of ANY downloads so that it is
2907 // possible to get here.
2908 return;
2909 }
2910 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302911 iter->second.Run(
2912 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392913 }
[email protected]41225fe2013-03-29 05:32:022914 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392915}
2916
2917void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392918 const std::vector<FaviconURL>& candidates) {
2919 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292920 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392921}
2922
[email protected]1dd0bb752014-02-01 01:16:262923void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2924 bool has_video,
2925 bool has_audio) {
2926// Chrome OS does its own detection of audio and video.
2927#if !defined(OS_CHROMEOS)
2928 scoped_ptr<PowerSaveBlocker> blocker;
2929 if (has_video) {
2930 blocker = PowerSaveBlocker::Create(
2931 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2932#if defined(OS_ANDROID)
2933 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2934 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2935#endif
2936 } else if (has_audio) {
2937 blocker = PowerSaveBlocker::Create(
2938 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2939 }
2940
2941 if (blocker) {
[email protected]96307312014-05-04 01:00:192942 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262943 blocker.release();
2944 }
2945#endif // !defined(OS_CHROMEOS)
2946}
2947
2948void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062949 // Chrome OS does its own detection of audio and video.
2950#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192951 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2952 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062953#endif // !defined(OS_CHROMEOS)
2954}
2955
[email protected]50279492014-05-05 23:24:292956void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152957 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292958 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152959}
[email protected]d9030b82013-07-19 08:26:062960
[email protected]e67ebf32013-02-13 11:07:192961void WebContentsImpl::DidChangeVisibleSSLState() {
2962 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2963 DidChangeVisibleSSLState());
2964}
2965
[email protected]17e286e2013-03-01 23:29:392966void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2967 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2968 BeforeFormRepostWarningShow());
2969}
2970
[email protected]ec6c05f2013-10-23 18:41:572971
2972void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2973 Activate();
2974 if (delegate_)
2975 delegate_->ShowRepostFormWarningDialog(this);
2976}
2977
[email protected]b4c84012014-04-28 19:51:102978bool WebContentsImpl::HasAccessedInitialDocument() {
2979 return has_accessed_initial_document_;
2980}
2981
[email protected]96d185d2009-04-24 03:28:542982// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592983// loading, or done loading.
2984void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2985 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092986 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262987 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542988 if (is_loading == is_loading_)
2989 return;
2990
2991 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262992 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2993 base::string16());
[email protected]96d185d2009-04-24 03:28:542994 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562995 upload_size_ = 0;
2996 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542997 }
2998
[email protected]fa944cb82013-11-15 17:51:212999 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543000
3001 is_loading_ = is_loading;
3002 waiting_for_response_ = is_loading;
3003
[email protected]6ebdc9b2010-09-27 16:55:573004 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093005 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213006 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543007
[email protected]eab61442013-11-14 18:35:483008 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593009 if (is_loading) {
[email protected]eab61442013-11-14 18:35:483010 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
3011 "URL", url);
[email protected]91621872013-10-08 04:04:593012 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3013 DidStartLoading(render_view_host));
3014 } else {
[email protected]eab61442013-11-14 18:35:483015 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
3016 "URL", url);
[email protected]91621872013-10-08 04:04:593017 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3018 DidStopLoading(render_view_host));
3019 }
[email protected]66798902013-10-01 18:40:163020
3021 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213022 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3023 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543024 if (details)
[email protected]8ff00d72012-10-23 19:12:213025 det = Details<LoadNotificationDetails>(details);
3026 NotificationService::current()->Notify(
3027 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543028}
3029
[email protected]959be4c2014-04-08 15:01:333030void WebContentsImpl::SelectRange(const gfx::Point& start,
3031 const gfx::Point& end) {
3032 RenderFrameHost* focused_frame = GetFocusedFrame();
3033 if (!focused_frame)
3034 return;
3035
3036 focused_frame->Send(
3037 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
3038}
3039
[email protected]b172aee2012-04-10 17:05:263040void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463041 // If we are creating a RVH for a restored controller, then we need to make
3042 // sure the RenderView starts with a next_page_id_ larger than the number
3043 // of restored entries. This must be called before the RenderView starts
3044 // navigating (to avoid a race between the browser updating max_page_id and
3045 // the renderer updating next_page_id_). Because of this, we only call this
3046 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563047 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583048 if (max_restored_page_id >
3049 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3050 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3051 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323052}
3053
[email protected]b172aee2012-04-10 17:05:263054bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263055 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323056 // For file URLs without a title, use the pathname instead. In the case of a
3057 // synthesized title, we don't want the update to count toward the "one set
3058 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263059 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323060 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513061 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243062 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323063 explicit_set = false; // Don't count synthetic titles toward the set limit.
3064 } else {
[email protected]8af69c6c2014-03-03 19:05:313065 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323066 explicit_set = true;
3067 }
3068
[email protected]987fc3a2011-05-26 14:18:093069 // If a page is created via window.open and never navigated,
3070 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553071 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093072 if (entry) {
[email protected]36fc0392011-12-25 03:59:513073 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093074 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323075
[email protected]36fc0392011-12-25 03:59:513076 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093077 } else {
3078 if (page_title_when_no_navigation_entry_ == final_title)
3079 return false; // Nothing changed, don't bother.
3080
3081 page_title_when_no_navigation_entry_ = final_title;
3082 }
[email protected]420ae012009-04-24 05:16:323083
[email protected]420ae012009-04-24 05:16:323084 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233085 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323086
[email protected]66798902013-10-01 18:40:163087 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533088 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163089
3090 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213091 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463092 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213093 NotificationService::current()->Notify(
3094 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3095 Source<WebContents>(this),
3096 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043097
[email protected]420ae012009-04-24 05:16:323098 return true;
3099}
3100
[email protected]960b0372014-05-19 18:01:003101void WebContentsImpl::SendLoadProgressChanged() {
3102 loading_last_progress_update_ = base::TimeTicks::Now();
3103 double progress = 0.0;
3104 int frame_count = 0;
3105
3106 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3107 it != loading_progresses_.end();
3108 ++it) {
3109 progress += it->second;
3110 ++frame_count;
3111 }
3112 if (frame_count == 0)
3113 return;
3114 progress /= frame_count;
3115 DCHECK(progress <= 1.0);
3116
3117 if (progress <= loading_total_progress_)
3118 return;
3119 loading_total_progress_ = progress;
3120
3121 if (delegate_)
3122 delegate_->LoadProgressChanged(this, progress);
3123}
3124
3125void WebContentsImpl::ResetLoadProgressState() {
3126 loading_progresses_.clear();
3127 loading_total_progress_ = 0.0;
3128 loading_weak_factory_.InvalidateWeakPtrs();
3129 loading_last_progress_update_ = base::TimeTicks();
3130}
3131
[email protected]7b712ee22013-10-03 00:57:283132void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
3133 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323134 // After sending out a swap notification, we need to send a disconnect
3135 // notification so that clients that pick up a pointer to |this| can NULL the
3136 // pointer. See Bug 1230284.
3137 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113138 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283139 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113140
3141 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283142 std::pair<RenderViewHost*, RenderViewHost*> details =
3143 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213144 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283145 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213146 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283147 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393148
3149 // Ensure that the associated embedder gets cleared after a RenderViewHost
3150 // gets swapped, so we don't reuse the same embedder next time a
3151 // RenderViewHost is attached to this WebContents.
3152 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323153}
3154
[email protected]da7a7182013-09-06 08:11:113155// TODO(avi): Remove this entire function because this notification is already
3156// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263157void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323158 if (!notify_disconnection_)
3159 return;
3160
3161 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213162 NotificationService::current()->Notify(
3163 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3164 Source<WebContents>(this),
3165 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323166}
3167
[email protected]cbb1ef592013-06-05 19:49:463168void WebContentsImpl::NotifyNavigationEntryCommitted(
3169 const LoadCommittedDetails& load_details) {
3170 FOR_EACH_OBSERVER(
3171 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3172}
3173
[email protected]f114fa42013-12-06 17:06:443174bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3175 const IPC::Message& message) {
3176 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313177}
3178
[email protected]c31a84802014-04-03 15:55:493179const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3180 return GetLastCommittedURL();
3181}
3182
[email protected]b849847b2013-12-10 21:57:583183void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3184 // Note this is only for subframes, the notification for the main frame
3185 // happens in RenderViewCreated.
3186 FOR_EACH_OBSERVER(WebContentsObserver,
3187 observers_,
3188 RenderFrameCreated(render_frame_host));
3189}
3190
3191void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193192 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583193 FOR_EACH_OBSERVER(WebContentsObserver,
3194 observers_,
3195 RenderFrameDeleted(render_frame_host));
3196}
3197
[email protected]a09d53ce2014-01-31 00:46:423198void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303199 if (delegate_)
3200 delegate_->WorkerCrashed(this);
3201}
3202
[email protected]a09d53ce2014-01-31 00:46:423203void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3204 const ContextMenuParams& params) {
3205 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:403206 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:423207 return;
3208
3209 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
3210}
3211
[email protected]87de04b02014-04-08 22:14:493212void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013213 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493214 const base::string16& message,
3215 const base::string16& default_prompt,
3216 const GURL& frame_url,
3217 JavaScriptMessageType javascript_message_type,
3218 IPC::Message* reply_msg) {
3219 // Suppress JavaScript dialogs when requested. Also suppress messages when
3220 // showing an interstitial as it's shown over the previous page and we don't
3221 // want the hidden page's dialogs to interfere with the interstitial.
3222 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013223 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493224 IsSwappedOut() ||
3225 ShowingInterstitialPage() ||
3226 !delegate_ ||
3227 delegate_->ShouldSuppressDialogs() ||
3228 !delegate_->GetJavaScriptDialogManager();
3229
3230 if (!suppress_this_message) {
3231 std::string accept_lang = GetContentClient()->browser()->
3232 GetAcceptLangs(GetBrowserContext());
3233 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3234 dialog_manager_->RunJavaScriptDialog(
3235 this,
3236 frame_url.GetOrigin(),
3237 accept_lang,
3238 javascript_message_type,
3239 message,
3240 default_prompt,
3241 base::Bind(&WebContentsImpl::OnDialogClosed,
3242 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013243 render_frame_host->GetProcess()->GetID(),
3244 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493245 reply_msg,
3246 false),
3247 &suppress_this_message);
3248 }
3249
3250 if (suppress_this_message) {
3251 // If we are suppressing messages, just reply as if the user immediately
3252 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013253 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3254 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283255 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493256 }
3257
3258 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3259 // http://crbug.com/288961 ). The only safe thing to do here is return.
3260}
3261
3262void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013263 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493264 const base::string16& message,
3265 bool is_reload,
3266 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013267 RenderFrameHostImpl* rfhi =
3268 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493269 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013270 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493271 if (delegate_)
3272 delegate_->WillRunBeforeUnloadConfirm();
3273
3274 bool suppress_this_message =
3275 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3276 !delegate_ ||
3277 delegate_->ShouldSuppressDialogs() ||
3278 !delegate_->GetJavaScriptDialogManager();
3279 if (suppress_this_message) {
3280 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3281 return;
3282 }
3283
3284 is_showing_before_unload_dialog_ = true;
3285 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3286 dialog_manager_->RunBeforeUnloadDialog(
3287 this, message, is_reload,
3288 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013289 render_frame_host->GetProcess()->GetID(),
3290 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283291 false));
[email protected]87de04b02014-04-08 22:14:493292}
3293
[email protected]a86c0e962013-12-17 17:10:393294WebContents* WebContentsImpl::GetAsWebContents() {
3295 return this;
3296}
3297
[email protected]7912e822014-04-16 02:37:033298bool WebContentsImpl::IsNeverVisible() {
3299 if (!delegate_)
3300 return false;
3301 return delegate_->IsNeverVisible(this);
3302}
3303
[email protected]5a3bdf52012-05-24 15:12:573304RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3305 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323306}
3307
[email protected]8ff00d72012-10-23 19:12:213308RendererPreferences WebContentsImpl::GetRendererPrefs(
3309 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463310 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513311}
3312
[email protected]b172aee2012-04-10 17:05:263313gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173314 if (delegate_)
3315 return delegate_->GetRootWindowResizerRect();
3316 return gfx::Rect();
3317}
3318
[email protected]7a846df2012-09-20 19:17:393319void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273320 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393321 browser_plugin_embedder_.reset();
3322}
3323
[email protected]b172aee2012-04-10 17:05:263324void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443325 // Don't send notifications if we are just creating a swapped-out RVH for
3326 // the opener chain. These won't be used for view-source or WebUI, so it's
3327 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243328 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443329 return;
3330
[email protected]86f98a22013-03-20 14:35:003331 if (delegate_)
3332 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083333
[email protected]8ff00d72012-10-23 19:12:213334 NotificationService::current()->Notify(
3335 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3336 Source<WebContents>(this),
3337 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323338
3339 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353340 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213341 if (GetRenderManager()->pending_web_ui())
3342 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323343
[email protected]6286a372013-10-09 04:03:273344 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333345 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323346 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183347 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583348 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323349 }
[email protected]0666aef2009-05-13 19:48:083350
[email protected]60780f412013-02-25 16:34:103351 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263352
3353 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253354 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583355
3356 // We tell the observers now instead of when the main RenderFrameHostImpl is
3357 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3358 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363359 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583360 FOR_EACH_OBSERVER(
3361 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323362}
3363
[email protected]b172aee2012-04-10 17:05:263364void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523365 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323366 // Don't notify the world, since this came from a renderer in the
3367 // background.
3368 return;
3369 }
3370
[email protected]da7a7182013-09-06 08:11:113371 notify_disconnection_ = true;
3372 // TODO(avi): Remove. http://crbug.com/170921
3373 NotificationService::current()->Notify(
3374 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3375 Source<WebContents>(this),
3376 NotificationService::NoDetails());
3377
[email protected]be1f56ab2011-12-22 06:55:313378 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233379 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303380
3381 // Restore the focus to the tab (otherwise the focus will be on the top
3382 // window).
[email protected]484ae5912010-09-29 19:16:143383 if (was_crashed && !FocusLocationBarByDefault() &&
3384 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063385 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143386 }
[email protected]32ded2212011-11-10 18:51:433387
[email protected]d8c660432011-12-22 20:51:253388 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323389}
3390
[email protected]ec6a7eb2013-04-22 17:34:223391void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3392 base::TerminationStatus status,
3393 int error_code) {
[email protected]151a63d2011-12-20 22:32:523394 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323395 // The pending page's RenderViewHost is gone.
3396 return;
3397 }
3398
[email protected]2fcdcc32014-03-05 02:14:073399 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3400 // renderer may not have made a clean exit.
3401 if (IsFullscreenForCurrentTab())
3402 ToggleFullscreenMode(false);
3403
[email protected]698191dc2014-02-25 01:06:133404 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3405 if (dialog_manager_)
3406 dialog_manager_->CancelActiveAndPendingDialogs(this);
3407
[email protected]e3b10d12014-03-28 16:06:093408 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323409 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233410 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453411
[email protected]960b0372014-05-19 18:01:003412 // Reset the loading progress. TODO(avi): What does it mean to have a
3413 // "renderer crash" when there is more than one renderer process serving a
3414 // webpage? Once this function is called at a more granular frame level, we
3415 // probably will need to more granularly reset the state here.
3416 ResetLoadProgressState();
3417 loading_frames_in_progress_ = 0;
3418
[email protected]fc2b46b2014-05-03 16:33:453419#if defined(OS_ANDROID)
3420 if (GetRenderViewHostImpl()->media_player_manager())
3421 GetRenderViewHostImpl()->media_player_manager()->DestroyAllMediaPlayers();
3422#endif
[email protected]420ae012009-04-24 05:16:323423
[email protected]d8c660432011-12-22 20:51:253424 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273425 observers_,
[email protected]58d5cfe2013-07-10 02:40:523426 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323427}
3428
[email protected]b172aee2012-04-10 17:05:263429void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253430 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063431}
3432
[email protected]b172aee2012-04-10 17:05:263433void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3434 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043435 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153436 // Ensure that this state update comes from either the active RVH or one of
3437 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413438 // TODO(nasko): This should go through RenderFrameHost.
3439 // TODO(creis): We can't update state for cross-process subframes until we
3440 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3441 if (rvh != GetRenderViewHost() &&
3442 !GetRenderManager()->IsRVHOnSwappedOutList(
3443 static_cast<RenderViewHostImpl*>(rvh)))
3444 return;
[email protected]420ae012009-04-24 05:16:323445
3446 // We must be prepared to handle state updates for any page, these occur
3447 // when the user is scrolling and entering form data, as well as when we're
3448 // leaving a page, in which case our state may have already been moved to
3449 // the next page. The navigation controller will look up the appropriate
3450 // NavigationEntry and update it when it is notified via the delegate.
3451
3452 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583453 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323454 if (entry_index < 0)
3455 return;
[email protected]10f417c52011-12-28 21:04:233456 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323457
[email protected]691aa2f2013-05-28 22:52:043458 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323459 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043460 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323461 controller_.NotifyEntryChanged(entry, entry_index);
3462}
3463
[email protected]b172aee2012-04-10 17:05:263464void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513465 if (delegate_)
3466 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323467}
3468
[email protected]b172aee2012-04-10 17:05:263469void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103470#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293471 // The UI may be in an event-tracking loop, such as between the
3472 // mouse-down and mouse-up in text selection or a button click.
3473 // Defer the close until after tracking is complete, so that we
3474 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293475 // TODO(shess): This could get more fine-grained. For instance,
3476 // closing a tab in another window while selecting text in the
3477 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103478 if (view_->IsEventTracking()) {
3479 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293480 return;
3481 }
[email protected]60780f412013-02-25 16:34:103482#endif
[email protected]07707302009-11-06 00:50:293483
[email protected]420ae012009-04-24 05:16:323484 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523485 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513486 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323487}
3488
[email protected]66bbadaf2014-03-28 16:25:543489void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573490 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3491 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573492}
3493
[email protected]b172aee2012-04-10 17:05:263494void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513495 if (delegate_ && delegate_->IsPopupOrPanel(this))
3496 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323497}
3498
[email protected]e3b10d12014-03-28 16:06:093499void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3500 bool to_different_document) {
3501 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3502 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323503}
3504
[email protected]723971b2014-02-12 11:08:253505void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323506 scoped_ptr<LoadNotificationDetails> details;
3507
[email protected]9595fd82013-04-19 21:28:493508 // Use the last committed entry rather than the active one, in case a
3509 // pending entry has been created.
3510 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203511 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493512
[email protected]420ae012009-04-24 05:16:323513 // An entry may not exist for a stop when loading an initial blank page or
3514 // if an iframe injected by script into a blank page finishes loading.
3515 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203516 base::TimeDelta elapsed =
3517 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323518
3519 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513520 entry->GetVirtualURL(),
3521 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323522 elapsed,
3523 &controller_,
3524 controller_.GetCurrentEntryIndex()));
3525 }
3526
[email protected]e3b10d12014-03-28 16:06:093527 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3528 details.get());
[email protected]420ae012009-04-24 05:16:323529}
3530
[email protected]b172aee2012-04-10 17:05:263531void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163532 controller_.DiscardNonCommittedEntries();
3533
3534 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213535 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163536}
3537
[email protected]59167c22013-06-03 18:07:323538void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103539 has_accessed_initial_document_ = true;
3540
[email protected]d1371bf8e2014-04-19 03:26:243541 // We may have left a failed browser-initiated navigation in the address bar
3542 // to let the user edit it and try again. Clear it now that content might
3543 // show up underneath it.
3544 if (!IsLoading() && controller_.GetPendingEntry())
3545 controller_.DiscardPendingEntry();
3546
[email protected]59167c22013-06-03 18:07:323547 // Update the URL display.
3548 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3549}
3550
[email protected]3f19f1a2014-05-02 05:23:273551void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3552 if (opener_) {
3553 // Clear our opener so that future cross-process navigations don't have an
3554 // opener assigned.
3555 RemoveDestructionObserver(opener_);
3556 opener_ = NULL;
3557 }
3558
3559 // Notify all swapped out RenderViewHosts for this tab. This is important
3560 // in case we go back to them, or if another window in those processes tries
3561 // to access window.opener.
3562 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3563}
3564
[email protected]39f2f9252014-05-03 00:54:013565void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293566 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093567 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293568 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093569
3570 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213571 NotificationService::current()->Notify(
3572 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3573 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293574 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083575}
3576
[email protected]ef3adfc2014-05-11 00:04:543577void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3578 int32 page_id,
3579 const base::string16& title,
3580 base::i18n::TextDirection title_direction) {
3581 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3582
3583 // If we have a title, that's a pretty good indication that we've started
3584 // getting useful data.
3585 SetNotWaitingForResponse();
3586
3587 // Try to find the navigation entry, which might not be the current one.
3588 // For example, it might be from a pending RVH for the pending entry.
3589 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3590 rvh->GetSiteInstance(), page_id);
3591
3592 // We can handle title updates when we don't have an entry in
3593 // UpdateTitleForEntry, but only if the update is from the current RVH.
3594 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3595 if (!entry && rvh != GetRenderViewHost())
3596 return;
3597
3598 // TODO(evan): make use of title_direction.
3599 // http://code.google.com/p/chromium/issues/detail?id=27094
3600 if (!UpdateTitleForEntry(entry, title))
3601 return;
3602
3603 // Broadcast notifications when the UI should be updated.
3604 if (entry == controller_.GetEntryAtOffset(0))
3605 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3606}
3607
3608void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3609 const std::string& encoding) {
3610 SetEncoding(encoding);
3611}
3612
[email protected]39f2f9252014-05-03 00:54:013613void WebContentsImpl::DocumentAvailableInMainFrame(
3614 RenderViewHost* render_view_host) {
3615 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3616 DocumentAvailableInMainFrame());
3617}
[email protected]e1c3a552012-05-04 20:51:323618void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3619 // Tell the active RenderViewHost to run unload handlers and close, as long
3620 // as the request came from a RenderViewHost in the same BrowsingInstance.
3621 // In most cases, we receive this from a swapped out RenderViewHost.
3622 // It is possible to receive it from one that has just been swapped in,
3623 // in which case we might as well deliver the message anyway.
3624 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3625 GetRenderViewHost()->ClosePage();
3626}
3627
[email protected]f546640b2012-05-15 00:03:493628void WebContentsImpl::RouteMessageEvent(
3629 RenderViewHost* rvh,
3630 const ViewMsg_PostMessage_Params& params) {
3631 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363632 // came from a RenderViewHost in the same BrowsingInstance or if this
3633 // WebContents is dedicated to a browser plugin guest.
3634 // Note: This check means that an embedder could theoretically receive a
3635 // postMessage from anyone (not just its own guests). However, this is
3636 // probably not a risk for apps since other pages won't have references
3637 // to App windows.
3638 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3639 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493640 return;
3641
3642 ViewMsg_PostMessage_Params new_params(params);
3643
[email protected]0bc7f3542013-10-21 15:05:533644 if (!params.message_port_ids.empty()) {
3645 MessagePortMessageFilter* message_port_message_filter =
3646 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3647 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093648 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3649 params.message_port_ids,
3650 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533651 }
3652
[email protected]f546640b2012-05-15 00:03:493653 // If there is a source_routing_id, translate it to the routing ID for
3654 // the equivalent swapped out RVH in the target process. If we need
3655 // to create a swapped out RVH for the source tab, we create its opener
3656 // chain as well, since those will also be accessible to the target page.
3657 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3658 // Try to look up the WebContents for the source page.
3659 WebContentsImpl* source_contents = NULL;
3660 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3661 rvh->GetProcess()->GetID(), params.source_routing_id);
3662 if (source_rvh) {
3663 source_contents = static_cast<WebContentsImpl*>(
3664 source_rvh->GetDelegate()->GetAsWebContents());
3665 }
3666
3667 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363668 if (GetBrowserPluginGuest()) {
3669 // We create a swapped out RenderView for the embedder in the guest's
3670 // render process but we intentionally do not expose the embedder's
3671 // opener chain to it.
3672 new_params.source_routing_id =
3673 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3674 } else {
3675 new_params.source_routing_id =
3676 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3677 }
[email protected]f546640b2012-05-15 00:03:493678 } else {
3679 // We couldn't find it, so don't pass a source frame.
3680 new_params.source_routing_id = MSG_ROUTING_NONE;
3681 }
3682 }
3683
3684 // In most cases, we receive this from a swapped out RenderViewHost.
3685 // It is possible to receive it from one that has just been swapped in,
3686 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183687 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493688}
3689
[email protected]a796f202012-05-30 14:14:253690bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263691 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253692 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263693 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253694 if (!delegate_)
3695 return false;
3696 return delegate_->AddMessageToConsole(this, level, message, line_no,
3697 source_id);
3698}
3699
[email protected]b172aee2012-04-10 17:05:263700WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273701 // We want to base the page config off of the actual URL, rather than the
3702 // virtual URL.
3703 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3704 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003705 GURL url = controller_.GetActiveEntry()
3706 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153707
[email protected]fa944cb82013-11-15 17:51:213708 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323709}
3710
[email protected]0eba810b2012-10-18 03:19:363711int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213712 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413713 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3714 true, true);
[email protected]0eba810b2012-10-18 03:19:363715}
3716
[email protected]b172aee2012-04-10 17:05:263717void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273718 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253719 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223720
[email protected]ea114722012-03-12 01:11:253721 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173722 if (rdh) // NULL in unittests.
3723 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253724}
3725
[email protected]b172aee2012-04-10 17:05:263726void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443727 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253728 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443729}
3730
[email protected]b172aee2012-04-10 17:05:263731void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563732 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263733 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153734 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523735 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153736 return;
3737
[email protected]9f76c1e2012-03-05 15:15:583738 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3739
[email protected]e5fc1632011-08-08 07:51:533740 // Ignore renderer unresponsive event if debugger is attached to the tab
3741 // since the event may be a result of the renderer sitting on a breakpoint.
3742 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363743 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533744 return;
3745
[email protected]2e9d79f2013-08-16 05:45:563746 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323747 // Hang occurred while firing the beforeunload/unload handler.
3748 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583749 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323750
[email protected]fa944cb82013-11-15 17:51:213751 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323752 return;
3753
3754 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563755 // nothing we can do to recover. If the hang is in the beforeunload handler,
3756 // pretend the beforeunload listeners have all fired and allow the delegate
3757 // to continue closing; the user will not have the option of cancelling the
3758 // close. Otherwise, pretend the unload listeners have all fired and close
3759 // the tab.
3760 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463761 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563762 delegate_->BeforeUnloadFired(this, true, &close);
3763 }
3764 if (close)
3765 Close(rvh);
[email protected]420ae012009-04-24 05:16:323766 return;
3767 }
3768
[email protected]9f76c1e2012-03-05 15:15:583769 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473770 return;
3771
[email protected]6934a702011-12-20 00:04:513772 if (delegate_)
3773 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323774}
3775
[email protected]b172aee2012-04-10 17:05:263776void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513777 if (delegate_)
3778 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323779}
3780
[email protected]b172aee2012-04-10 17:05:263781void WebContentsImpl::LoadStateChanged(
3782 const GURL& url,
3783 const net::LoadStateWithParam& load_state,
3784 uint64 upload_position,
3785 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323786 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563787 upload_position_ = upload_position;
3788 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503789 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213790 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303791 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213792 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323793 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463794 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213795 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463796 }
[email protected]420ae012009-04-24 05:16:323797}
3798
[email protected]b172aee2012-04-10 17:05:263799void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553800 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323801 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123802 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3803 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513804 if (delegate_)
3805 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093806 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323807}
3808
[email protected]58d5cfe2013-07-10 02:40:523809void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543810 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233811 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223812 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543813}
3814
[email protected]b172aee2012-04-10 17:05:263815void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103816 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213817 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263818 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3819 // here during container initialization and normal window size will be set
3820 // later. In case of tab duplication this resizing to 0x0 prevents setting
3821 // normal size later so just ignore it.
3822 if (!size.IsEmpty())
3823 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323824}
3825
[email protected]af905902013-10-01 21:38:513826void WebContentsImpl::CancelModalDialogsForRenderManager() {
3827 // We need to cancel modal dialogs when doing a process swap, since the load
3828 // deferrer would prevent us from swapping out.
3829 if (dialog_manager_)
3830 dialog_manager_->CancelActiveAndPendingDialogs(this);
3831}
3832
[email protected]7b712ee22013-10-03 00:57:283833void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3834 RenderViewHost* new_host) {
3835 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083836
3837 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003838 if (delegate_)
3839 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393840
[email protected]7b712ee22013-10-03 00:57:283841 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543842}
3843
[email protected]14392a52012-05-02 20:28:443844int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3845 SiteInstance* instance) {
3846 if (!opener_)
3847 return MSG_ROUTING_NONE;
3848
3849 // Recursively create RenderViews for anything else in the opener chain.
3850 return opener_->CreateOpenerRenderViews(instance);
3851}
3852
3853int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3854 int opener_route_id = MSG_ROUTING_NONE;
3855
3856 // If this tab has an opener, ensure it has a RenderView in the given
3857 // SiteInstance as well.
3858 if (opener_)
3859 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3860
[email protected]45a22ad2013-02-21 03:25:003861 // If any of the renderers (current, pending, or swapped out) for this
3862 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213863 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3864 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373865
[email protected]fa944cb82013-11-15 17:51:213866 if (GetRenderManager()->pending_render_view_host() &&
3867 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3868 instance)
3869 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003870
[email protected]fa944cb82013-11-15 17:51:213871 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373872 instance);
3873 if (rvh)
3874 return rvh->GetRoutingID();
3875
[email protected]14392a52012-05-02 20:28:443876 // Create a swapped out RenderView in the given SiteInstance if none exists,
3877 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413878 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3879 true, true);
[email protected]14392a52012-05-02 20:28:443880}
3881
[email protected]b172aee2012-04-10 17:05:263882NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193883 return GetController();
[email protected]3a3d47472010-07-15 21:03:543884}
3885
[email protected]b172aee2012-04-10 17:05:263886WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563887 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323888}
3889
[email protected]10f417c52011-12-28 21:04:233890NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263891 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323892 return controller_.GetLastCommittedEntry();
3893}
3894
[email protected]b172aee2012-04-10 17:05:263895bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163896 RenderViewHost* render_view_host,
3897 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043898 int proxy_routing_id,
[email protected]bffc8302014-01-23 20:52:163899 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033900 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443901 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483902 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163903 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3904 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3905 // case this because RWH is still a base class of RenderViewHost, and child
3906 // frame RWHVs are unique in that they do not have their own WebContents.
3907 if (frame_connector) {
3908 RenderWidgetHostViewChildFrame* rwh_view_child =
3909 new RenderWidgetHostViewChildFrame(render_view_host);
3910 frame_connector->set_view(rwh_view_child);
3911 rwh_view = rwh_view_child;
3912 } else {
3913 rwh_view = view_->CreateViewForWidget(render_view_host);
3914 }
[email protected]1a98a932009-11-17 00:12:523915
[email protected]420ae012009-04-24 05:16:323916 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443917 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213918 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323919
[email protected]74ce1ad2011-12-16 21:51:463920 // Make sure we use the correct starting page_id in the new RenderView.
3921 UpdateMaxPageIDIfNecessary(render_view_host);
3922 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583923 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463924
[email protected]9f76c1e2012-03-05 15:15:583925 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263926 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493927 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043928 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:493929 max_page_id,
3930 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523931 return false;
[email protected]14392a52012-05-02 20:28:443932 }
[email protected]a4127722011-04-27 23:13:523933
[email protected]a220b5932013-09-21 03:47:443934#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503935 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3936 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443937 if (rwh_view) {
3938 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3939 render_widget_host->WasResized();
3940 }
[email protected]f8233cc2011-05-31 20:24:503941#endif
3942
[email protected]420ae012009-04-24 05:16:323943 return true;
3944}
3945
[email protected]7d244f12013-08-22 21:41:513946#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453947
[email protected]155c7f22013-12-09 17:07:183948base::android::ScopedJavaLocalRef<jobject>
3949WebContentsImpl::GetJavaWebContents() {
3950 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3951
3952 WebContentsAndroid* web_contents_android =
3953 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3954 if (!web_contents_android) {
3955 web_contents_android = new WebContentsAndroid(this);
3956 SetUserData(kWebContentsAndroidKey, web_contents_android);
3957 }
3958 return web_contents_android->GetJavaObject();
3959}
3960
[email protected]7d244f12013-08-22 21:41:513961bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3962 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163963 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:043964 MSG_ROUTING_NONE,
[email protected]bffc8302014-01-23 20:52:163965 NULL);
[email protected]7d244f12013-08-22 21:41:513966}
[email protected]fc2b46b2014-05-03 16:33:453967
3968#elif defined(OS_MACOSX)
3969
3970void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
3971 view_->SetAllowOverlappingViews(overlapping);
3972}
3973
3974bool WebContentsImpl::GetAllowOverlappingViews() {
3975 return view_->GetAllowOverlappingViews();
3976}
3977
3978void WebContentsImpl::SetOverlayView(WebContents* overlay,
3979 const gfx::Point& offset) {
3980 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
3981 offset);
3982}
3983
3984void WebContentsImpl::RemoveOverlayView() {
3985 view_->RemoveOverlayView();
3986}
3987
[email protected]7d244f12013-08-22 21:41:513988#endif
3989
[email protected]6fba26d2014-04-29 09:38:283990void WebContentsImpl::OnDialogClosed(int render_process_id,
3991 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:263992 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493993 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263994 bool success,
[email protected]fcf75d42013-12-03 20:11:263995 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:283996 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3997 render_frame_id);
[email protected]87de04b02014-04-08 22:14:493998 last_dialog_suppressed_ = dialog_was_suppressed;
3999
[email protected]beb440c2009-11-06 04:08:544000 if (is_showing_before_unload_dialog_ && !success) {
4001 // If a beforeunload dialog is canceled, we need to stop the throbber from
4002 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284003 if (rfh)
4004 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354005 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104006
[email protected]6d65a462013-06-21 21:29:124007 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4008 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544009 }
[email protected]87de04b02014-04-08 22:14:494010
[email protected]beb440c2009-11-06 04:08:544011 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284012 if (rfh) {
4013 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4014 dialog_was_suppressed);
4015 } else {
4016 // Don't leak the sync IPC reply if the RFH or process is gone.
4017 delete reply_msg;
4018 }
[email protected]beb440c2009-11-06 04:08:544019}
4020
[email protected]b172aee2012-04-10 17:05:264021void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544022 if (encoding == last_reported_encoding_)
4023 return;
4024 last_reported_encoding_ = encoding;
4025
4026 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124027 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104028}
[email protected]f45d2a72010-03-08 23:28:354029
[email protected]b172aee2012-04-10 17:05:264030void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:484031 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:444032 // Can be NULL during tests.
4033 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:454034 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:364035}
[email protected]9f76c1e2012-03-05 15:15:584036
[email protected]1ac10dca2013-08-20 20:47:044037bool WebContentsImpl::IsHidden() {
4038 return capturer_count_ == 0 && !should_normally_be_visible_;
4039}
4040
[email protected]b0936d22013-11-28 06:47:364041RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214042 return frame_tree_.root()->render_manager();
4043}
4044
[email protected]b172aee2012-04-10 17:05:264045RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584046 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4047}
[email protected]7900bfdb2012-05-24 19:31:244048
[email protected]f8497342013-02-05 22:15:024049BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394050 return browser_plugin_guest_.get();
4051}
4052
[email protected]738f57a2013-06-29 21:06:544053void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4054 CHECK(!browser_plugin_guest_);
4055 browser_plugin_guest_.reset(guest);
4056}
4057
[email protected]f8497342013-02-05 22:15:024058BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394059 return browser_plugin_embedder_.get();
4060}
[email protected]8ff00d72012-10-23 19:12:214061
[email protected]d9030b82013-07-19 08:26:064062void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194063 RenderFrameHost* render_frame_host) {
4064 STLDeleteValues(&power_save_blockers_[render_frame_host]);
4065 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:064066}
4067
4068void WebContentsImpl::ClearAllPowerSaveBlockers() {
4069 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
4070 i != power_save_blockers_.end(); ++i)
4071 STLDeleteValues(&power_save_blockers_[i->first]);
4072 power_save_blockers_.clear();
4073}
4074
[email protected]fc2b46b2014-05-03 16:33:454075gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214076 gfx::Size size;
4077 if (delegate_)
4078 size = delegate_->GetSizeForNewRenderView(this);
4079 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454080 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214081 return size;
4082}
4083
[email protected]9b159a52013-10-03 17:24:554084void WebContentsImpl::OnFrameRemoved(
4085 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:584086 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:554087 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:584088 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:554089}
4090
[email protected]222f5822014-02-05 23:40:494091void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4092 if (!delegate_)
4093 return;
4094 const gfx::Size new_size = GetPreferredSize();
4095 if (new_size != old_size)
4096 delegate_->UpdatePreferredSize(this, new_size);
4097}
4098
[email protected]8ff00d72012-10-23 19:12:214099} // namespace content