blob: f5301e6942270c392922f23b7c849daf6b234e14 [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]38b098f2012-03-14 21:11:57106#endif
[email protected]3e45ba92009-02-20 21:09:00107
[email protected]420ae012009-04-24 05:16:32108// Cross-Site Navigations
109//
[email protected]b172aee2012-04-10 17:05:26110// If a WebContentsImpl is told to navigate to a different web site (as
111// determined by SiteInstance), it will replace its current RenderViewHost with
112// a new RenderViewHost dedicated to the new SiteInstance. This works as
113// follows:
[email protected]420ae012009-04-24 05:16:32114//
[email protected]fc6c1872013-10-03 01:22:35115// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46116// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32117// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35118// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32119// run in the current RVH.
120// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35121// that it has a pending cross-site request. We will check this on the IO
122// thread when deciding how to handle the response.
123// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46124// cancel all the pending logic. Otherwise we allow the pending RVH to send
125// the navigation request to its renderer.
126// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35127// main resource load on the pending RVH. It creates a
128// CrossSiteResourceHandler to check whether a process swap is needed when
129// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46130// - When RDH receives a response, the BufferedResourceHandler determines
131// whether it is a download. If so, it sends a message to the new renderer
132// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26133// pending RVH remains until the next DidNavigate event for this
134// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32135// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35136// download, the CrossSiteResourceHandler checks whether a process swap is
137// needed (either because CrossSiteRequestManager has state for it or because
138// a transfer was needed for a redirect).
139// - If so, CrossSiteResourceHandler pauses the response to first run the old
140// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36141// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
142// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35143// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
144// to a new process is needed, based on the stored pending_nav_params_. (This
145// is independent of whether we started out with a cross-process navigation.)
146// - If not, it just tells the ResourceDispatcherHost to resume the response
147// to its current RenderViewHost.
148// - If so, it cancels the current pending RenderViewHost and sets up a new
149// navigation using RequestTransferURL. When the transferred request
150// arrives in the ResourceDispatcherHost, we transfer the response and
151// resume it.
[email protected]420ae012009-04-24 05:16:32152// - The pending renderer sends a FrameNavigate message that invokes the
153// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46154// pending RVH.
[email protected]b0936d22013-11-28 06:47:36155// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15156// the user goes back. The process only stays live if another tab is using
157// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32158
[email protected]8ff00d72012-10-23 19:12:21159namespace content {
[email protected]420ae012009-04-24 05:16:32160namespace {
161
[email protected]960b0372014-05-19 18:01:00162const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
163
164// This matches what Blink's ProgressTracker has traditionally used for a
165// minimum progress value.
166const double kMinimumLoadingProgress = 0.1;
167
[email protected]82114f52012-03-20 22:53:41168const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05169
[email protected]155c7f22013-12-09 17:07:18170#if defined(OS_ANDROID)
171const char kWebContentsAndroidKey[] = "web_contents_android";
172#endif // OS_ANDROID
173
[email protected]e4abd3b42013-11-12 18:28:47174base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46175g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
176
[email protected]988ed7132014-03-31 16:25:58177static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39178 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29179 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30180 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02181 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58182 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02183 ++g_next_image_download_id,
184 url,
185 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30186 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02187 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39188}
189
[email protected]8bfc8272013-09-09 20:10:53190void NotifyCacheOnIO(
191 scoped_refptr<net::URLRequestContextGetter> request_context,
192 const GURL& url,
193 const std::string& http_method) {
194 request_context->GetURLRequestContext()->http_transaction_factory()->
195 GetCache()->OnExternalCacheHit(url, http_method);
196}
197
[email protected]9b159a52013-10-03 17:24:55198// Helper function for retrieving all the sites in a frame tree.
199bool CollectSites(BrowserContext* context,
200 std::set<GURL>* sites,
201 FrameTreeNode* node) {
202 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
203 return true;
204}
205
[email protected]a86c0e962013-12-17 17:10:39206bool ForEachFrameInternal(
207 const base::Callback<void(RenderFrameHost*)>& on_frame,
208 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41209 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39210 return true;
211}
212
213void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
214 IPC::Message* message_copy = new IPC::Message(*message);
215 message_copy->set_routing_id(rfh->GetRoutingID());
216 rfh->Send(message_copy);
217}
218
[email protected]948481d2014-06-11 18:32:22219void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
220 RenderFrameHost* rfh) {
221 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
222 ->frame_tree_node()
223 ->render_manager()
224 ->GetRenderWidgetHostView();
225 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59226}
227
[email protected]420ae012009-04-24 05:16:32228} // namespace
229
[email protected]54944cde2012-12-09 09:24:59230WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15231 return WebContentsImpl::CreateWithOpener(
232 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19233}
234
235WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59236 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30237 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59238 WebContentsImpl* new_contents = new WebContentsImpl(
239 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30240
241 for (SessionStorageNamespaceMap::const_iterator it =
242 session_storage_namespace_map.begin();
243 it != session_storage_namespace_map.end();
244 ++it) {
245 new_contents->GetController()
246 .SetSessionStorageNamespace(it->first, it->second.get());
247 }
248
[email protected]54944cde2012-12-09 09:24:59249 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19250 return new_contents;
[email protected]a81343d232011-12-27 07:39:20251}
[email protected]746d3052012-05-22 15:15:47252
[email protected]e4abd3b42013-11-12 18:28:47253void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46254 g_created_callbacks.Get().push_back(callback);
255}
256
[email protected]e4abd3b42013-11-12 18:28:47257void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46258 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
259 if (g_created_callbacks.Get().at(i).Equals(callback)) {
260 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
261 return;
262 }
263 }
264}
265
[email protected]299d7f12012-05-23 05:31:15266WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47267 return rvh->GetDelegate()->GetAsWebContents();
268}
269
[email protected]a86c0e962013-12-17 17:10:39270WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
271 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
272 if (!rfh_impl)
273 return NULL;
274 return rfh_impl->delegate()->GetAsWebContents();
275}
276
[email protected]7fff43e2013-05-21 20:21:10277// WebContentsImpl::DestructionObserver ----------------------------------------
278
279class WebContentsImpl::DestructionObserver : public WebContentsObserver {
280 public:
281 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
282 : WebContentsObserver(watched_contents),
283 owner_(owner) {
284 }
285
286 // WebContentsObserver:
[email protected]12a46832014-05-09 13:35:58287 virtual void WebContentsDestroyed() OVERRIDE {
288 owner_->OnWebContentsDestroyed(
289 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10290 }
291
292 private:
293 WebContentsImpl* owner_;
294
295 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
296};
297
[email protected]8ed16472014-04-11 19:02:48298WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
299 int render_frame_id,
300 ColorChooser* chooser,
301 int identifier)
302 : render_process_id(render_process_id),
303 render_frame_id(render_frame_id),
304 chooser(chooser),
305 identifier(identifier) {
306}
307
308WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
309}
310
[email protected]b172aee2012-04-10 17:05:26311// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32312
[email protected]b172aee2012-04-10 17:05:26313WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21314 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19315 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42316 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22317 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57318 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44319 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49320 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08321#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41322 accessible_parent_(NULL),
323#endif
[email protected]6ea6bdf2013-12-06 13:35:01324 frame_tree_(new NavigatorImpl(&controller_, this),
325 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34326 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03327 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23328 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
329 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34330 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26331 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00332 loading_total_progress_(0.0),
333 loading_weak_factory_(this),
334 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56335 upload_size_(0),
336 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47337 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10338 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55339 capturer_count_(0),
340 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57341 is_being_destroyed_(false),
342 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15343 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01344 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02345 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38346 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21347 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
348 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29349 totalPinchGestureAmount_(0),
350 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44351 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42352 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]87de04b02014-04-08 22:14:49353 is_subframe_(false),
[email protected]e85165c642014-06-10 14:34:31354 touch_emulation_enabled_(false),
[email protected]87de04b02014-04-08 22:14:49355 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46356 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
357 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55358 frame_tree_.SetFrameRemoveListener(
359 base::Bind(&WebContentsImpl::OnFrameRemoved,
360 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35361}
initial.commit09911bf2008-07-26 23:55:29362
[email protected]b172aee2012-04-10 17:05:26363WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32364 is_being_destroyed_ = true;
365
[email protected]21b41c7e892014-02-28 01:52:24366 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
367 // shutdown and be deleted as well.
368 frame_tree_.ForEach(
369 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
370
[email protected]d9030b82013-07-19 08:26:06371 ClearAllPowerSaveBlockers();
372
[email protected]b24b68a2012-09-24 21:57:26373 for (std::set<RenderWidgetHostImpl*>::iterator iter =
374 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
375 (*iter)->DetachDelegate();
376 }
377 created_widgets_.clear();
378
[email protected]3ab9cb82011-06-03 18:02:07379 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15380 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11381 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07382
[email protected]8ed16472014-04-11 19:02:48383 if (color_chooser_info_.get())
384 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20385
[email protected]420ae012009-04-24 05:16:32386 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32387
[email protected]ca13a442012-04-17 14:00:12388 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21389 NotificationService::current()->Notify(
390 NOTIFICATION_WEB_CONTENTS_DESTROYED,
391 Source<WebContents>(this),
392 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32393
[email protected]df0c843f2014-05-23 20:37:23394 // Destroy all frame tree nodes except for the root; this notifies observers.
395 frame_tree_.ResetForMainFrameSwap();
396 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59397
[email protected]df0c843f2014-05-23 20:37:23398 // Manually call the observer methods for the root frame tree node.
399 RenderFrameHostManager* root = GetRenderManager();
400 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27401 FOR_EACH_OBSERVER(WebContentsObserver,
402 observers_,
[email protected]df0c843f2014-05-23 20:37:23403 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27404 }
[email protected]df0c843f2014-05-23 20:37:23405 FOR_EACH_OBSERVER(WebContentsObserver,
406 observers_,
407 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27408
[email protected]df0c843f2014-05-23 20:37:23409 if (root->pending_render_view_host()) {
410 FOR_EACH_OBSERVER(WebContentsObserver,
411 observers_,
412 RenderViewDeleted(root->pending_render_view_host()));
413 }
[email protected]c06c58c2014-03-12 20:31:59414
[email protected]f273ee52013-10-18 16:05:27415 FOR_EACH_OBSERVER(WebContentsObserver,
416 observers_,
[email protected]df0c843f2014-05-23 20:37:23417 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27418
[email protected]2db9bd72012-04-13 20:20:56419 FOR_EACH_OBSERVER(WebContentsObserver,
420 observers_,
[email protected]12a46832014-05-09 13:35:58421 WebContentsDestroyed());
422
423 FOR_EACH_OBSERVER(WebContentsObserver,
424 observers_,
425 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08426
[email protected]6934a702011-12-20 00:04:51427 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10428
429 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
430 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42431}
432
[email protected]d1198fd2012-08-13 22:50:19433WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59434 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19435 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03436 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59437 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06438 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19439
[email protected]83100cd2014-05-10 11:50:06440 if (params.guest_instance_id) {
[email protected]50d326e2014-05-20 17:59:06441 scoped_ptr<base::DictionaryValue> extra_params;
442 if (params.guest_extra_params)
443 extra_params.reset(params.guest_extra_params->DeepCopy());
[email protected]83100cd2014-05-10 11:50:06444 // This makes |new_contents| act as a guest.
445 // For more info, see comment above class BrowserPluginGuest.
446 BrowserPluginGuest::Create(params.guest_instance_id,
447 params.site_instance,
448 new_contents,
[email protected]50d326e2014-05-20 17:59:06449 extra_params.Pass(),
450 opener ? opener->GetBrowserPluginGuest() : NULL);
[email protected]83100cd2014-05-10 11:50:06451 // 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_Attach,
542 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02543 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
544 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]9f268072013-11-07 00:02:15545 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
546 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07547 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
548 OnShowValidationMessage)
549 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
550 OnHideValidationMessage)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
552 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48553#if defined(OS_ANDROID)
554 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
555 OnFindMatchRectsReply)
556 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
557 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48558#endif
[email protected]724159a2010-12-30 01:11:18559 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33560 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44561 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57562 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18563
[email protected]724159a2010-12-30 01:11:18564 return handled;
565}
566
[email protected]b172aee2012-04-10 17:05:26567void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18568 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21569 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43570 if (delegate_)
571 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18572}
573
[email protected]d1198fd2012-08-13 22:50:19574NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56575 return controller_;
576}
577
[email protected]d1198fd2012-08-13 22:50:19578const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56579 return controller_;
580}
581
[email protected]8ff00d72012-10-23 19:12:21582BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55583 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30584}
585
[email protected]b172aee2012-04-10 17:05:26586const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24587 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32588 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51589 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31590}
591
[email protected]a093ce02013-07-22 20:53:14592const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24593 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32594 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24595 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
596}
597
598const GURL& WebContentsImpl::GetLastCommittedURL() const {
599 // We may not have a navigation entry yet.
600 NavigationEntry* entry = controller_.GetLastCommittedEntry();
601 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
602}
603
[email protected]8ff00d72012-10-23 19:12:21604WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31605 return delegate_;
606}
607
[email protected]8ff00d72012-10-23 19:12:21608void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31609 // TODO(cbentzel): remove this debugging code?
610 if (delegate == delegate_)
611 return;
612 if (delegate_)
613 delegate_->Detach(this);
614 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08615 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31616 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08617 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00618 if (view_)
[email protected]e85165c642014-06-10 14:34:31619 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08620 }
[email protected]be1f56ab2011-12-22 06:55:31621}
622
[email protected]8ff00d72012-10-23 19:12:21623RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21624 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41625 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16626}
627
[email protected]60eca4eb2013-12-06 00:02:16628RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41629 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16630}
631
[email protected]9c9343b2014-03-08 02:56:07632RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
633 if (!frame_tree_.GetFocusedFrame())
634 return NULL;
635 return frame_tree_.GetFocusedFrame()->current_frame_host();
636}
637
[email protected]a86c0e962013-12-17 17:10:39638void WebContentsImpl::ForEachFrame(
639 const base::Callback<void(RenderFrameHost*)>& on_frame) {
640 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
641}
642
643void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
644 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
645 delete message;
646}
647
[email protected]b172aee2012-04-10 17:05:26648RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21649 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31650}
651
[email protected]6b618e62012-08-16 12:59:18652int WebContentsImpl::GetRoutingID() const {
653 if (!GetRenderViewHost())
654 return MSG_ROUTING_NONE;
655
656 return GetRenderViewHost()->GetRoutingID();
657}
658
[email protected]44470a22013-01-24 01:21:54659int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
660 return fullscreen_widget_routing_id_;
661}
662
[email protected]b172aee2012-04-10 17:05:26663RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21664 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31665}
666
[email protected]4aebbca2013-09-17 22:26:49667RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
668 const {
669 RenderWidgetHost* const widget_host =
670 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
671 GetFullscreenWidgetRoutingID());
672 return widget_host ? widget_host->GetView() : NULL;
673}
674
[email protected]8ff00d72012-10-23 19:12:21675WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31676 return view_.get();
677}
678
[email protected]8ff00d72012-10-23 19:12:21679WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56680 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03681 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
682 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22683 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58684 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22685 web_ui->SetController(controller);
686 return web_ui;
687 }
688
689 delete web_ui;
690 return NULL;
691}
692
[email protected]8ff00d72012-10-23 19:12:21693WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21694 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
695 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31696}
697
[email protected]8ff00d72012-10-23 19:12:21698WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21699 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34700}
701
[email protected]86ef6a392012-05-11 22:03:11702void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22703 if (GetUserAgentOverride() == override)
704 return;
705
706 renderer_preferences_.user_agent_override = override;
707
708 // Send the new override string to the renderer.
709 RenderViewHost* host = GetRenderViewHost();
710 if (host)
711 host->SyncRendererPrefs();
712
713 // Reload the page if a load is currently in progress to avoid having
714 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27715 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22716 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
717 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53718
719 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
720 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11721}
722
723const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22724 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11725}
726
[email protected]2ceee8f2014-01-14 18:02:08727#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41728void WebContentsImpl::SetParentNativeViewAccessible(
729gfx::NativeViewAccessible accessible_parent) {
730 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45731 if (GetRenderViewHost())
732 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41733}
734#endif
735
[email protected]fcf75d42013-12-03 20:11:26736const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55737 // Transient entries take precedence. They are used for interstitial pages
738 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23739 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08740 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21741 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30742 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23743 if (entry) {
[email protected]b5cca982011-05-26 04:42:08744 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23745 }
[email protected]fa944cb82013-11-15 17:51:21746 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
747 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58748 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54749 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32750 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54751 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35752 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26753 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54754 if (!title.empty())
755 return title;
756 }
757 }
758
759 // We use the title for the last committed entry rather than a pending
760 // navigation entry. For example, when the user types in a URL, we want to
761 // keep the old page's title until the new load has committed and we get a new
762 // title.
[email protected]96d185d2009-04-24 03:28:54763 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32764
[email protected]9eeafc012013-11-25 23:49:47765 // We make an exception for initial navigations.
766 if (controller_.IsInitialNavigation()) {
767 // We only want to use the title from the visible entry in one of two cases:
768 // 1. There's already a committed entry for an initial navigation, in which
769 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
770 // 2. The pending entry has been explicitly assigned a title to display.
771 //
772 // If there's no last committed entry and no assigned title, we should fall
773 // back to |page_title_when_no_navigation_entry_| rather than showing the
774 // URL.
775 if (entry ||
776 (controller_.GetVisibleEntry() &&
777 !controller_.GetVisibleEntry()->GetTitle().empty())) {
778 entry = controller_.GetVisibleEntry();
779 }
780 }
[email protected]59167c22013-06-03 18:07:32781
[email protected]45d0ef7f2011-01-05 13:46:23782 if (entry) {
[email protected]b5cca982011-05-26 04:42:08783 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23784 }
[email protected]987fc3a2011-05-26 14:18:09785
786 // |page_title_when_no_navigation_entry_| is finally used
787 // if no title cannot be retrieved.
788 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54789}
790
[email protected]b172aee2012-04-10 17:05:26791int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46792 return GetMaxPageIDForSiteInstance(GetSiteInstance());
793}
794
[email protected]b172aee2012-04-10 17:05:26795int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
796 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33797 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
798 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46799
[email protected]b6583592012-01-25 19:52:33800 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34801}
802
[email protected]b172aee2012-04-10 17:05:26803void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46804 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
805}
806
[email protected]b172aee2012-04-10 17:05:26807void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33808 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46809 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33810 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34811}
812
[email protected]ec6c05f2013-10-23 18:41:57813void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
814 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
815 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57816}
817
[email protected]b172aee2012-04-10 17:05:26818SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21819 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54820}
821
[email protected]b172aee2012-04-10 17:05:26822SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21823 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
824 GetRenderManager()->pending_render_view_host() :
825 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58826 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38827}
828
[email protected]b172aee2012-04-10 17:05:26829bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31830 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49831}
832
[email protected]6dfed692014-05-22 04:18:03833bool WebContentsImpl::IsLoadingToDifferentDocument() const {
834 return is_loading_ && is_load_to_different_document_;
835}
836
[email protected]b172aee2012-04-10 17:05:26837bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03838 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31839}
840
[email protected]b172aee2012-04-10 17:05:26841const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31842 return load_state_;
843}
844
[email protected]fcf75d42013-12-03 20:11:26845const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31846 return load_state_host_;
847}
848
[email protected]b172aee2012-04-10 17:05:26849uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31850 return upload_size_;
851}
852
[email protected]b172aee2012-04-10 17:05:26853uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31854 return upload_position_;
855}
856
[email protected]1ae93fb2013-06-14 03:38:56857std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56858 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39859 frame_tree_.ForEach(base::Bind(&CollectSites,
860 base::Unretained(GetBrowserContext()),
861 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56862 return sites;
863}
864
[email protected]b172aee2012-04-10 17:05:26865const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54866 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31867}
868
[email protected]b172aee2012-04-10 17:05:26869bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31870 return displayed_insecure_content_;
871}
872
[email protected]222f5822014-02-05 23:40:49873void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25874 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55875 ++capturer_count_;
876 DVLOG(1) << "There are now " << capturer_count_
877 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49878
879 // Note: This provides a hint to upstream code to size the views optimally
880 // for quality (e.g., to avoid scaling).
881 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
882 preferred_size_for_capture_ = capture_size;
883 OnPreferredSizeChanged(preferred_size_);
884 }
[email protected]54597982013-02-06 01:59:55885}
886
887void WebContentsImpl::DecrementCapturerCount() {
888 --capturer_count_;
889 DVLOG(1) << "There are now " << capturer_count_
890 << " capturing(s) of WebContentsImpl@" << this;
891 DCHECK_LE(0, capturer_count_);
892
[email protected]5a652232013-02-12 06:15:25893 if (is_being_destroyed_)
894 return;
895
[email protected]222f5822014-02-05 23:40:49896 if (capturer_count_ == 0) {
897 const gfx::Size old_size = preferred_size_for_capture_;
898 preferred_size_for_capture_ = gfx::Size();
899 OnPreferredSizeChanged(old_size);
900 }
901
[email protected]1ac10dca2013-08-20 20:47:04902 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55903 DVLOG(1) << "Executing delayed WasHidden().";
904 WasHidden();
905 }
[email protected]be1f56ab2011-12-22 06:55:31906}
907
[email protected]f2bd40812013-07-20 04:30:44908int WebContentsImpl::GetCapturerCount() const {
909 return capturer_count_;
910}
911
[email protected]b172aee2012-04-10 17:05:26912bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31913 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
914 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
915 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49916}
917
[email protected]b172aee2012-04-10 17:05:26918void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
919 int error_code) {
[email protected]443b80e2010-12-14 00:42:23920 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34921 return;
922
[email protected]443b80e2010-12-14 00:42:23923 crashed_status_ = status;
924 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21925 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34926}
927
[email protected]b172aee2012-04-10 17:05:26928base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31929 return crashed_status_;
930}
931
[email protected]b172aee2012-04-10 17:05:26932bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31933 return is_being_destroyed_;
934}
935
[email protected]b172aee2012-04-10 17:05:26936void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34937 if (delegate_)
938 delegate_->NavigationStateChanged(this, changed_flags);
939}
940
[email protected]9a890452014-02-13 22:21:02941base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
942 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33943}
944
[email protected]9e2e4632012-07-27 16:38:41945void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54946 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:59947
[email protected]948481d2014-06-11 18:32:22948 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
949 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:59950 iter != widgets.end();
951 iter++) {
[email protected]948481d2014-06-11 18:32:22952 if (*iter) {
953 (*iter)->Show();
[email protected]789e9152009-08-04 21:59:43954#if defined(OS_MACOSX)
[email protected]948481d2014-06-11 18:32:22955 (*iter)->SetActive(true);
[email protected]789e9152009-08-04 21:59:43956#endif
[email protected]de3c5d82014-05-28 22:12:59957 }
[email protected]789e9152009-08-04 21:59:43958 }
[email protected]96d185d2009-04-24 03:28:54959
[email protected]9a890452014-02-13 22:21:02960 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38961
[email protected]b9769d82012-02-10 00:23:59962 // The resize rect might have changed while this was inactive -- send the new
963 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58964 RenderViewHostImpl* rvh =
965 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59966 if (rvh) {
967 rvh->ResizeRectChanged(GetRootWindowResizerRect());
968 }
[email protected]96d185d2009-04-24 03:28:54969
[email protected]c0d9d5672013-10-09 07:38:03970 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
971
[email protected]54597982013-02-06 01:59:55972 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31973}
974
[email protected]b172aee2012-04-10 17:05:26975void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55976 // If there are entities capturing screenshots or video (e.g., mirroring),
977 // don't activate the "disable rendering" optimization.
978 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52979 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55980 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26981 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52982 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33983 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52984 // calls us).
[email protected]948481d2014-06-11 18:32:22985 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
986 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:59987 iter != widgets.end();
988 iter++) {
[email protected]948481d2014-06-11 18:32:22989 if (*iter)
990 (*iter)->Hide();
[email protected]de3c5d82014-05-28 22:12:59991 }
[email protected]96d185d2009-04-24 03:28:54992 }
993
[email protected]c0d9d5672013-10-09 07:38:03994 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
995
[email protected]54597982013-02-06 01:59:55996 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37997}
998
[email protected]b172aee2012-04-10 17:05:26999bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311000 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271001 return WillNotifyDisconnection() &&
1002 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581003 !static_cast<RenderViewHostImpl*>(
1004 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311005}
1006
[email protected]1c3f80bd2014-04-08 23:02:061007void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1008 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1009 for_cross_site_transition);
1010}
1011
[email protected]b172aee2012-04-10 17:05:261012void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211013 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401014 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271015}
1016
[email protected]b172aee2012-04-10 17:05:261017WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441018 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451019 // We pass our own opener so that the cloned page can access it if it was
1020 // before.
[email protected]54944cde2012-12-09 09:24:591021 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451022 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591023 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191024 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221025 FOR_EACH_OBSERVER(WebContentsObserver,
1026 observers_,
1027 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271028 return tc;
1029}
1030
[email protected]14392a52012-05-02 20:28:441031void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211032 const NotificationSource& source,
1033 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441034 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211035 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1036 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501037 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1038 i != pending_widget_views_.end(); ++i) {
1039 if (host->GetView() == i->second) {
1040 pending_widget_views_.erase(i);
1041 break;
1042 }
1043 }
1044 break;
1045 }
[email protected]14392a52012-05-02 20:28:441046 default:
1047 NOTREACHED();
1048 }
1049}
1050
[email protected]ec6c05f2013-10-23 18:41:571051WebContents* WebContentsImpl::GetWebContents() {
1052 return this;
1053}
1054
[email protected]54944cde2012-12-09 09:24:591055void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211056 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361057 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211058 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431059 should_normally_be_visible_ = !params.initially_hidden;
1060
[email protected]fa944cb82013-11-15 17:51:211061 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041062 params.browser_context, params.site_instance, params.routing_id,
1063 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191064
[email protected]fc2b46b2014-05-03 16:33:451065 WebContentsViewDelegate* delegate =
1066 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1067
1068 if (browser_plugin_guest_) {
1069 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1070 this, delegate, &render_view_host_delegate_view_));
1071
1072 WebContentsViewGuest* rv = new WebContentsViewGuest(
1073 this, browser_plugin_guest_.get(), platform_view.Pass(),
1074 render_view_host_delegate_view_);
1075 render_view_host_delegate_view_ = rv;
1076 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191077 } else {
[email protected]fc2b46b2014-05-03 16:33:451078 // Regular WebContentsView.
1079 view_.reset(CreateWebContentsView(
1080 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191081 }
[email protected]fc2b46b2014-05-03 16:33:451082 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191083 CHECK(view_.get());
1084
[email protected]ed245db2012-12-18 08:00:451085 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591086 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191087
1088 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101089 if (opener_)
1090 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191091
1092 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211093 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1094 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101095
1096 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
1097
[email protected]c7654a232013-06-12 21:04:441098#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101099 date_time_chooser_.reset(new DateTimeChooserAndroid());
1100#endif
[email protected]d1198fd2012-08-13 22:50:191101}
1102
[email protected]7fff43e2013-05-21 20:21:101103void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1104 RemoveDestructionObserver(web_contents);
1105
[email protected]14392a52012-05-02 20:28:441106 // Clear the opener if it has been closed.
1107 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441108 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511109 return;
[email protected]14392a52012-05-02 20:28:441110 }
[email protected]ceee8cd2013-03-08 04:59:511111 // Clear a pending contents that has been closed before being shown.
1112 for (PendingContents::iterator iter = pending_contents_.begin();
1113 iter != pending_contents_.end();
1114 ++iter) {
1115 if (iter->second != web_contents)
1116 continue;
1117 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511118 return;
1119 }
1120 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441121}
1122
[email protected]7fff43e2013-05-21 20:21:101123void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1124 if (!ContainsKey(destruction_observers_, web_contents)) {
1125 destruction_observers_[web_contents] =
1126 new DestructionObserver(this, web_contents);
1127 }
1128}
1129
1130void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1131 DestructionObservers::iterator iter =
1132 destruction_observers_.find(web_contents);
1133 if (iter != destruction_observers_.end()) {
1134 delete destruction_observers_[web_contents];
1135 destruction_observers_.erase(iter);
1136 }
1137}
1138
[email protected]b172aee2012-04-10 17:05:261139void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311140 observers_.AddObserver(observer);
1141}
1142
[email protected]b172aee2012-04-10 17:05:261143void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311144 observers_.RemoveObserver(observer);
1145}
1146
[email protected]948481d2014-06-11 18:32:221147std::set<RenderWidgetHostView*>
1148WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1149 std::set<RenderWidgetHostView*> set;
1150 if (ShowingInterstitialPage()) {
1151 set.insert(GetRenderWidgetHostView());
1152 } else {
1153 ForEachFrame(
1154 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1155 }
[email protected]de3c5d82014-05-28 22:12:591156 return set;
1157}
1158
[email protected]b172aee2012-04-10 17:05:261159void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341160 if (delegate_)
1161 delegate_->ActivateContents(this);
1162}
1163
[email protected]b172aee2012-04-10 17:05:261164void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121165 if (delegate_)
1166 delegate_->DeactivateContents(this);
1167}
1168
[email protected]b172aee2012-04-10 17:05:261169void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481170 if (delegate_)
1171 delegate_->LostCapture();
1172}
1173
[email protected]b24b68a2012-09-24 21:57:261174void WebContentsImpl::RenderWidgetDeleted(
1175 RenderWidgetHostImpl* render_widget_host) {
1176 if (is_being_destroyed_) {
1177 // |created_widgets_| might have been destroyed.
1178 return;
1179 }
1180
1181 std::set<RenderWidgetHostImpl*>::iterator iter =
1182 created_widgets_.find(render_widget_host);
1183 if (iter != created_widgets_.end())
1184 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541185
1186 if (render_widget_host &&
1187 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491188 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1189 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541190 FOR_EACH_OBSERVER(WebContentsObserver,
1191 observers_,
1192 DidDestroyFullscreenWidget(
1193 fullscreen_widget_routing_id_));
1194 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1195 }
[email protected]b24b68a2012-09-24 21:57:261196}
1197
[email protected]b172aee2012-04-10 17:05:261198bool WebContentsImpl::PreHandleKeyboardEvent(
1199 const NativeWebKeyboardEvent& event,
1200 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481201 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131202 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481203}
1204
[email protected]b172aee2012-04-10 17:05:261205void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481206 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131207 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481208}
1209
[email protected]d92026ef2014-03-03 21:04:131210bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461211 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191212#if !defined(OS_MACOSX)
1213 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1214 // isn't done for two reasons:
1215 // -the OS already has a gesture to do this through pinch-zoom
1216 // -if a user starts an inertial scroll, let's go, and presses control
1217 // (i.e. control+tab) then the OS's buffered scroll events will come in
1218 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521219 if (delegate_ &&
1220 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551221 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1222 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1223 // gestures, which are regrettably easy to trigger accidentally.
1224 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521225 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1226 return true;
1227 }
[email protected]bccc4472013-04-18 16:37:191228#endif
[email protected]fb3f066e2013-02-12 19:12:521229 return false;
1230}
1231
[email protected]04bce562014-01-30 05:34:541232bool WebContentsImpl::PreHandleGestureEvent(
1233 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031234 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541235}
1236
[email protected]bab38af2014-03-30 17:37:291237bool WebContentsImpl::HandleGestureEvent(
1238 const blink::WebGestureEvent& event) {
1239 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1240 // Use them to implement browser zoom, as for HandleWheelEvent above.
1241 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331242 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291243 // The scale difference necessary to trigger a zoom action. Derived from
1244 // experimentation to find a value that feels reasonable.
1245 const float kZoomStepValue = 0.6f;
1246
1247 // Find the (absolute) thresholds on either side of the current zoom factor,
1248 // then convert those to actual numbers to trigger a zoom in or out.
1249 // This logic deliberately makes the range around the starting zoom value
1250 // for the gesture twice as large as the other ranges (i.e., the notches are
1251 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1252 // so that it's easier to get back to your starting point than it is to
1253 // overshoot.
1254 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1255 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1256 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1257 : -backStep;
1258 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1259 : backStep;
1260
[email protected]fb546cb2014-04-28 14:09:371261 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291262 if (totalPinchGestureAmount_ > zoomInThreshold) {
1263 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461264 if (delegate_)
1265 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291266 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1267 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461268 if (delegate_)
1269 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291270 }
1271 return true;
1272 }
1273
1274 return false;
1275}
1276
[email protected]2ceee8f2014-01-14 18:02:081277#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411278gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1279 return accessible_parent_;
1280}
1281#endif
1282
[email protected]b172aee2012-04-10 17:05:261283void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431284 if (delegate_)
1285 delegate_->HandleMouseDown();
1286}
1287
[email protected]b172aee2012-04-10 17:05:261288void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481289 if (delegate_)
1290 delegate_->HandleMouseUp();
1291}
1292
[email protected]590a634e2012-07-19 16:38:231293void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481294 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231295 delegate_->HandlePointerActivate();
1296}
1297
1298void WebContentsImpl::HandleGestureBegin() {
1299 if (delegate_)
1300 delegate_->HandleGestureBegin();
1301}
1302
1303void WebContentsImpl::HandleGestureEnd() {
1304 if (delegate_)
1305 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481306}
1307
[email protected]b172aee2012-04-10 17:05:261308void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491309 // This method is being called to enter or leave renderer-initiated fullscreen
1310 // mode. Either way, make sure any existing fullscreen widget is shut down
1311 // first.
1312 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1313 if (widget_view)
1314 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1315
[email protected]8a5e0ca2011-08-25 06:30:471316 if (delegate_)
1317 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371318
1319 FOR_EACH_OBSERVER(WebContentsObserver,
1320 observers_,
1321 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471322}
1323
[email protected]b172aee2012-04-10 17:05:261324bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381325 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121326}
1327
[email protected]a9c81f02012-06-01 00:15:441328void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1329 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371330 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441331 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371332 } else {
1333 GotResponseToLockMouseRequest(false);
1334 }
1335}
1336
[email protected]b172aee2012-04-10 17:05:261337void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371338 if (delegate_)
1339 delegate_->LostMouseLock();
1340}
1341
[email protected]bafe6cd2012-05-23 23:09:501342void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201343 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501344 int route_id,
[email protected]227692c52013-05-31 22:43:041345 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131346 const ViewHostMsg_CreateWindow_Params& params,
1347 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501348 // We usually create the new window in the same BrowsingInstance (group of
1349 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551350 // if the opener is being suppressed (in a non-guest), we create a new
1351 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251352 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551353
[email protected]04cbd3d2013-12-04 04:58:201354 // If the opener is to be suppressed, the new window can be in any process.
1355 // Since routing ids are process specific, we must not have one passed in
1356 // as argument here.
1357 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1358
[email protected]bafe6cd2012-05-23 23:09:501359 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551360 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571361 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501362 GetSiteInstance();
1363
[email protected]04cbd3d2013-12-04 04:58:201364 // A message to create a new window can only come from the active process for
1365 // this WebContentsImpl instance. If any other process sends the request,
1366 // it is invalid and the process must be terminated.
1367 if (GetRenderProcessHost()->GetID() != render_process_id) {
1368 base::ProcessHandle process_handle =
1369 RenderProcessHost::FromID(render_process_id)->GetHandle();
1370 if (process_handle != base::kNullProcessHandle) {
1371 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391372 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201373 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1374 }
1375 return;
1376 }
1377
[email protected]d1198fd2012-08-13 22:50:191378 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341379 //
1380 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301381 const std::string& partition_id =
1382 GetContentClient()->browser()->
1383 GetStoragePartitionIdForSite(GetBrowserContext(),
1384 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461385 StoragePartition* partition = BrowserContext::GetStoragePartition(
1386 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411387 DOMStorageContextWrapper* dom_storage_context =
1388 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191389 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1390 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1391 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371392
1393 if (delegate_ &&
1394 !delegate_->ShouldCreateWebContents(this,
1395 route_id,
1396 params.window_container_type,
1397 params.frame_name,
1398 params.target_url,
1399 partition_id,
1400 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011401 if (route_id != MSG_ROUTING_NONE &&
1402 !RenderViewHost::FromID(render_process_id, route_id)) {
1403 // If the embedder didn't create a WebContents for this route, we need to
1404 // delete the RenderView that had already been created.
1405 Send(new ViewMsg_Close(route_id));
1406 }
[email protected]dd6730412013-08-14 15:03:371407 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1408 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1409 main_frame_route_id);
1410 return;
1411 }
1412
1413 // Create the new web contents. This will automatically create the new
1414 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461415 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591416 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041417 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061418 create_params.opener = this;
1419 create_params.opener_suppressed = params.opener_suppressed;
1420 if (params.disposition == NEW_BACKGROUND_TAB)
1421 create_params.initially_hidden = true;
1422
[email protected]c4538072013-03-18 02:17:551423 if (!is_guest) {
1424 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451425 create_params.initial_size = GetContainerBounds().size();
[email protected]c4538072013-03-18 02:17:551426 } else {
[email protected]50d326e2014-05-20 17:59:061427 create_params.guest_instance_id =
[email protected]139355f2014-05-11 14:21:281428 GetBrowserContext()->GetGuestManager()->GetNextInstanceID();
[email protected]c4538072013-03-18 02:17:551429 }
[email protected]50d326e2014-05-20 17:59:061430 WebContentsImpl* new_contents = static_cast<WebContentsImpl*>(
1431 WebContents::Create(create_params));
1432 new_contents->GetController().SetSessionStorageNamespace(
1433 partition_id,
1434 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261435 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191436
[email protected]c4538072013-03-18 02:17:551437 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341438 // will be shown immediately).
1439 if (!params.opener_suppressed) {
1440 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451441 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501442
[email protected]d70bea92013-04-05 04:23:341443 // TODO(brettw): It seems bogus that we have to call this function on the
1444 // newly created object and give it one of its own member variables.
1445 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1446 }
[email protected]bafe6cd2012-05-23 23:09:501447 // Save the created window associated with the route so we can show it
1448 // later.
1449 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1450 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101451 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501452 }
1453
1454 if (delegate_) {
1455 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071456 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131457 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501458 }
1459
1460 if (params.opener_suppressed) {
1461 // When the opener is suppressed, the original renderer cannot access the
1462 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001463 bool was_blocked = false;
1464 if (delegate_) {
1465 gfx::Rect initial_pos;
1466 delegate_->AddNewContents(
1467 this, new_contents, params.disposition, initial_pos,
1468 params.user_gesture, &was_blocked);
1469 }
1470 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211471 OpenURLParams open_params(params.target_url,
1472 Referrer(),
1473 CURRENT_TAB,
1474 PAGE_TRANSITION_LINK,
1475 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301476 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001477 new_contents->OpenURL(open_params);
1478 }
[email protected]bafe6cd2012-05-23 23:09:501479 }
1480}
1481
[email protected]a8504022013-12-04 20:23:511482void WebContentsImpl::CreateNewWidget(int render_process_id,
1483 int route_id,
[email protected]180ef242013-11-07 06:50:461484 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511485 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501486}
1487
[email protected]a8504022013-12-04 20:23:511488void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1489 int route_id) {
1490 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501491}
1492
[email protected]a8504022013-12-04 20:23:511493void WebContentsImpl::CreateNewWidget(int render_process_id,
1494 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501495 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461496 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211497 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511498 // A message to create a new widget can only come from the active process for
1499 // this WebContentsImpl instance. If any other process sends the request,
1500 // it is invalid and the process must be terminated.
1501 if (process->GetID() != render_process_id) {
1502 base::ProcessHandle process_handle =
1503 RenderProcessHost::FromID(render_process_id)->GetHandle();
1504 if (process_handle != base::kNullProcessHandle) {
1505 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391506 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511507 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1508 }
1509 return;
1510 }
1511
[email protected]bafe6cd2012-05-23 23:09:501512 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041513 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261514 created_widgets_.insert(widget_host);
1515
[email protected]cfd80b02014-05-01 17:46:481516 RenderWidgetHostViewBase* widget_view =
1517 static_cast<RenderWidgetHostViewBase*>(
1518 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191519 if (!widget_view)
1520 return;
[email protected]bafe6cd2012-05-23 23:09:501521 if (!is_fullscreen) {
1522 // Popups should not get activated.
1523 widget_view->SetPopupType(popup_type);
1524 }
1525 // Save the created widget associated with the route so we can show it later.
1526 pending_widget_views_[route_id] = widget_view;
1527
1528#if defined(OS_MACOSX)
1529 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1530 // to allow it to survive the trip without being hosted.
1531 base::mac::NSObjectRetain(widget_view->GetNativeView());
1532#endif
1533}
1534
1535void WebContentsImpl::ShowCreatedWindow(int route_id,
1536 WindowOpenDisposition disposition,
1537 const gfx::Rect& initial_pos,
1538 bool user_gesture) {
1539 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001540 if (contents) {
1541 WebContentsDelegate* delegate = GetDelegate();
1542 if (delegate) {
1543 delegate->AddNewContents(
1544 this, contents, disposition, initial_pos, user_gesture, NULL);
1545 }
1546 }
[email protected]bafe6cd2012-05-23 23:09:501547}
1548
1549void WebContentsImpl::ShowCreatedWidget(int route_id,
1550 const gfx::Rect& initial_pos) {
1551 ShowCreatedWidget(route_id, false, initial_pos);
1552}
1553
1554void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1555 ShowCreatedWidget(route_id, true, gfx::Rect());
1556}
1557
1558void WebContentsImpl::ShowCreatedWidget(int route_id,
1559 bool is_fullscreen,
1560 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481561 RenderWidgetHostViewBase* widget_host_view =
1562 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501563 if (!widget_host_view)
1564 return;
[email protected]cfd80b02014-05-01 17:46:481565
1566 RenderWidgetHostView* view = NULL;
1567 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1568 if (guest && guest->embedder_web_contents()) {
1569 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1570 } else {
1571 view = GetRenderWidgetHostView();
1572 }
1573
[email protected]4aebbca2013-09-17 22:26:491574 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311575 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1576 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491577 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1578 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1579 delegate_->ToggleFullscreenModeForTab(this, true);
1580 } else {
[email protected]cfd80b02014-05-01 17:46:481581 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491582 }
[email protected]4aebbca2013-09-17 22:26:491583 FOR_EACH_OBSERVER(WebContentsObserver,
1584 observers_,
1585 DidShowFullscreenWidget(route_id));
1586 if (!widget_host_view->HasFocus())
1587 widget_host_view->Focus();
1588 } else {
[email protected]cfd80b02014-05-01 17:46:481589 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491590 }
[email protected]89054502012-06-03 10:29:241591
1592 RenderWidgetHostImpl* render_widget_host_impl =
1593 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1594 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311595 // Only allow privileged mouse lock for fullscreen render widget, which is
1596 // used to implement Pepper Flash fullscreen.
1597 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501598
1599#if defined(OS_MACOSX)
1600 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1601 // properly embedded (or purposefully ignored) we can release the retain we
1602 // took in CreateNewWidget().
1603 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1604#endif
1605}
1606
1607WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1608 PendingContents::iterator iter = pending_contents_.find(route_id);
1609
1610 // Certain systems can block the creation of new windows. If we didn't succeed
1611 // in creating one, just return NULL.
1612 if (iter == pending_contents_.end()) {
1613 return NULL;
1614 }
1615
1616 WebContentsImpl* new_contents = iter->second;
1617 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101618 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501619
[email protected]d70bea92013-04-05 04:23:341620 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251621 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341622 return new_contents;
1623
[email protected]bafe6cd2012-05-23 23:09:501624 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1625 !new_contents->GetRenderViewHost()->GetView())
1626 return NULL;
1627
1628 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1629 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1630 return new_contents;
1631}
1632
1633RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1634 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1635 if (iter == pending_widget_views_.end()) {
1636 DCHECK(false);
1637 return NULL;
1638 }
1639
1640 RenderWidgetHostView* widget_host_view = iter->second;
1641 pending_widget_views_.erase(route_id);
1642
1643 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1644 if (!widget_host->GetProcess()->HasConnection()) {
1645 // The view has gone away or the renderer crashed. Nothing to do.
1646 return NULL;
1647 }
1648
1649 return widget_host_view;
1650}
1651
[email protected]f13b4202012-06-12 23:53:231652void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091653 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211654 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371655 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231656 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371657 } else {
1658 callback.Run(MediaStreamDevices(),
1659 MEDIA_DEVICE_INVALID_STATE,
1660 scoped_ptr<MediaStreamUI>());
1661 }
[email protected]f13b4202012-06-12 23:53:231662}
1663
[email protected]cc9200432013-07-23 23:02:401664SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1665 SiteInstance* instance) {
1666 return controller_.GetSessionStorageNamespace(instance);
1667}
1668
[email protected]6de7fc482014-06-06 10:46:441669SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1670 return controller_.GetSessionStorageNamespaceMap();
1671}
1672
[email protected]9b159a52013-10-03 17:24:551673FrameTree* WebContentsImpl::GetFrameTree() {
1674 return &frame_tree_;
1675}
1676
[email protected]31a71eaf2014-03-13 01:47:361677void WebContentsImpl::AccessibilityEventReceived(
1678 const std::vector<AXEventNotificationDetails>& details) {
1679 FOR_EACH_OBSERVER(
1680 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1681}
1682
[email protected]edc3af82013-12-12 21:24:071683void WebContentsImpl::OnShowValidationMessage(
1684 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291685 const base::string16& main_text,
1686 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071687 if (delegate_)
1688 delegate_->ShowValidationMessage(
1689 this, anchor_in_root_view, main_text, sub_text);
1690}
1691
1692void WebContentsImpl::OnHideValidationMessage() {
1693 if (delegate_)
1694 delegate_->HideValidationMessage(this);
1695}
1696
1697void WebContentsImpl::OnMoveValidationMessage(
1698 const gfx::Rect& anchor_in_root_view) {
1699 if (delegate_)
1700 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1701}
1702
[email protected]32deec62013-05-15 23:55:041703void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1704 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441705 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041706}
1707
[email protected]e85165c642014-06-10 14:34:311708void WebContentsImpl::OnTouchEmulationEnabled(bool enabled) {
1709 touch_emulation_enabled_ = enabled;
1710 if (view_)
1711 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
1712}
1713
[email protected]b172aee2012-04-10 17:05:261714void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491715 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231716 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491717 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331718}
1719
[email protected]b172aee2012-04-10 17:05:261720void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341721 if (delegate_)
1722 delegate_->ResizeDueToAutoResize(this, new_size);
1723}
1724
[email protected]b172aee2012-04-10 17:05:261725WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201726 if (!delegate_)
1727 return NULL;
[email protected]00c37fc2011-08-02 00:22:501728
[email protected]e5d549d2011-12-28 01:29:201729 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201730 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341731}
1732
[email protected]6b618e62012-08-16 12:59:181733bool WebContentsImpl::Send(IPC::Message* message) {
1734 if (!GetRenderViewHost()) {
1735 delete message;
1736 return false;
1737 }
1738
1739 return GetRenderViewHost()->Send(message);
1740}
1741
[email protected]b172aee2012-04-10 17:05:261742bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501743 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261744 FrameTreeNode* node = frame_tree_.root();
1745
1746 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1747 // specified in the pending entry.
1748 NavigationEntryImpl* pending_entry =
1749 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1750 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1751 pending_entry->frame_tree_node_id() != -1) {
1752 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1753 }
1754
1755 return node->navigator()->NavigateToPendingEntry(
1756 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541757}
[email protected]96d185d2009-04-24 03:28:541758
[email protected]a86c0e962013-12-17 17:10:391759void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1760 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441761 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391762 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441763}
1764
[email protected]20ca0382013-02-28 19:50:071765void WebContentsImpl::AttachInterstitialPage(
1766 InterstitialPageImpl* interstitial_page) {
1767 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211768 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291769
1770 // Cancel any visible dialogs so that they don't interfere with the
1771 // interstitial.
1772 if (dialog_manager_)
1773 dialog_manager_->CancelActiveAndPendingDialogs(this);
1774
[email protected]20ca0382013-02-28 19:50:071775 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1776 DidAttachInterstitialPage());
1777}
1778
1779void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571780 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211781 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071782 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1783 DidDetachInterstitialPage());
1784}
1785
[email protected]b172aee2012-04-10 17:05:261786void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331787 const SiteInstance* site_instance,
1788 int history_length,
1789 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411790 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1791 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211792 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191793 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141794 return;
[email protected]9e1ad4b2011-08-14 16:49:191795 }
[email protected]9f76c1e2012-03-05 15:15:581796 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191797 if (!rvh) {
1798 NOTREACHED();
1799 return;
1800 }
[email protected]9f76c1e2012-03-05 15:15:581801 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191802 NOTREACHED();
1803 return;
1804 }
[email protected]6b618e62012-08-16 12:59:181805 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1806 history_length,
1807 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141808}
1809
[email protected]4fed3702014-04-01 09:08:001810void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171811 RenderFrameHost* focused_frame = GetFocusedFrame();
1812 if (!focused_frame)
1813 return;
1814
[email protected]959be4c2014-04-08 15:01:331815 focused_frame->Send(new FrameMsg_Reload(
1816 focused_frame->GetRoutingID(), ignore_cache));
1817}
1818
1819void WebContentsImpl::Undo() {
1820 RenderFrameHost* focused_frame = GetFocusedFrame();
1821 if (!focused_frame)
1822 return;
1823
1824 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1825 RecordAction(base::UserMetricsAction("Undo"));
1826}
1827
1828void WebContentsImpl::Redo() {
1829 RenderFrameHost* focused_frame = GetFocusedFrame();
1830 if (!focused_frame)
1831 return;
1832 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1833 RecordAction(base::UserMetricsAction("Redo"));
1834}
1835
1836void WebContentsImpl::Cut() {
1837 RenderFrameHost* focused_frame = GetFocusedFrame();
1838 if (!focused_frame)
1839 return;
1840
1841 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1842 RecordAction(base::UserMetricsAction("Cut"));
1843}
1844
1845void WebContentsImpl::Copy() {
1846 RenderFrameHost* focused_frame = GetFocusedFrame();
1847 if (!focused_frame)
1848 return;
1849
1850 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1851 RecordAction(base::UserMetricsAction("Copy"));
1852}
1853
1854void WebContentsImpl::CopyToFindPboard() {
1855#if defined(OS_MACOSX)
1856 RenderFrameHost* focused_frame = GetFocusedFrame();
1857 if (!focused_frame)
1858 return;
1859
1860 // Windows/Linux don't have the concept of a find pasteboard.
1861 focused_frame->Send(
1862 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1863 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1864#endif
1865}
1866
1867void WebContentsImpl::Paste() {
1868 RenderFrameHost* focused_frame = GetFocusedFrame();
1869 if (!focused_frame)
1870 return;
1871
1872 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1873 RecordAction(base::UserMetricsAction("Paste"));
1874}
1875
1876void WebContentsImpl::PasteAndMatchStyle() {
1877 RenderFrameHost* focused_frame = GetFocusedFrame();
1878 if (!focused_frame)
1879 return;
1880
1881 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1882 focused_frame->GetRoutingID()));
1883 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1884}
1885
1886void WebContentsImpl::Delete() {
1887 RenderFrameHost* focused_frame = GetFocusedFrame();
1888 if (!focused_frame)
1889 return;
1890
1891 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1892 RecordAction(base::UserMetricsAction("DeleteSelection"));
1893}
1894
1895void WebContentsImpl::SelectAll() {
1896 RenderFrameHost* focused_frame = GetFocusedFrame();
1897 if (!focused_frame)
1898 return;
1899
1900 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1901 RecordAction(base::UserMetricsAction("SelectAll"));
1902}
1903
1904void WebContentsImpl::Unselect() {
1905 RenderFrameHost* focused_frame = GetFocusedFrame();
1906 if (!focused_frame)
1907 return;
1908
1909 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1910 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171911}
1912
1913void WebContentsImpl::Replace(const base::string16& word) {
1914 RenderFrameHost* focused_frame = GetFocusedFrame();
1915 if (!focused_frame)
1916 return;
1917
[email protected]959be4c2014-04-08 15:01:331918 focused_frame->Send(new InputMsg_Replace(
1919 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171920}
1921
1922void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1923 RenderFrameHost* focused_frame = GetFocusedFrame();
1924 if (!focused_frame)
1925 return;
1926
[email protected]959be4c2014-04-08 15:01:331927 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1928 focused_frame->GetRoutingID(), word));
1929}
1930
1931void WebContentsImpl::NotifyContextMenuClosed(
1932 const CustomContextMenuContext& context) {
1933 RenderFrameHost* focused_frame = GetFocusedFrame();
1934 if (!focused_frame)
1935 return;
1936
1937 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1938 focused_frame->GetRoutingID(), context));
1939}
1940
1941void WebContentsImpl::ExecuteCustomContextMenuCommand(
1942 int action, const CustomContextMenuContext& context) {
1943 RenderFrameHost* focused_frame = GetFocusedFrame();
1944 if (!focused_frame)
1945 return;
1946
1947 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1948 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001949}
1950
[email protected]fc2b46b2014-05-03 16:33:451951gfx::NativeView WebContentsImpl::GetNativeView() {
1952 return view_->GetNativeView();
1953}
1954
1955gfx::NativeView WebContentsImpl::GetContentNativeView() {
1956 return view_->GetContentNativeView();
1957}
1958
1959gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1960 return view_->GetTopLevelNativeWindow();
1961}
1962
1963gfx::Rect WebContentsImpl::GetViewBounds() {
1964 return view_->GetViewBounds();
1965}
1966
1967gfx::Rect WebContentsImpl::GetContainerBounds() {
1968 gfx::Rect rv;
1969 view_->GetContainerBounds(&rv);
1970 return rv;
1971}
1972
1973DropData* WebContentsImpl::GetDropData() {
1974 return view_->GetDropData();
1975}
1976
1977void WebContentsImpl::Focus() {
1978 view_->Focus();
1979}
1980
1981void WebContentsImpl::SetInitialFocus() {
1982 view_->SetInitialFocus();
1983}
1984
1985void WebContentsImpl::StoreFocus() {
1986 view_->StoreFocus();
1987}
1988
1989void WebContentsImpl::RestoreFocus() {
1990 view_->RestoreFocus();
1991}
1992
[email protected]b172aee2012-04-10 17:05:261993void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271994 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211995 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541996 return;
1997 }
[email protected]9f76c1e2012-03-05 15:15:581998 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541999}
2000
[email protected]b172aee2012-04-10 17:05:262001bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212002 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542003}
2004
[email protected]b172aee2012-04-10 17:05:262005InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212006 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222007}
2008
[email protected]b172aee2012-04-10 17:05:262009bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162010 // WebKit creates Document object when MIME type is application/xhtml+xml,
2011 // so we also support this MIME type.
2012 return contents_mime_type_ == "text/html" ||
2013 contents_mime_type_ == "text/xml" ||
2014 contents_mime_type_ == "application/xhtml+xml" ||
2015 contents_mime_type_ == "text/plain" ||
2016 contents_mime_type_ == "text/css" ||
2017 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2018}
2019
[email protected]b172aee2012-04-10 17:05:262020void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592021 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162022 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552023 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012024 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142025 return;
[email protected]c7dd2f62011-07-18 15:57:592026 }
2027
2028 Stop();
2029
2030 // Create the save package and possibly prompt the user for the name to save
2031 // the page as. The user prompt is an asynchronous operation that runs on
2032 // another thread.
2033 save_package_ = new SavePackage(this);
2034 save_package_->GetSaveInfo();
2035}
2036
2037// Used in automated testing to bypass prompting the user for file names.
2038// Instead, the names and paths are hard coded rather than running them through
2039// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342040bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2041 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212042 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592043 // Stop the page from navigating.
2044 Stop();
2045
2046 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212047 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592048}
2049
[email protected]3c71576ce2013-07-23 02:00:012050void WebContentsImpl::SaveFrame(const GURL& url,
2051 const Referrer& referrer) {
2052 if (!GetURL().is_valid())
2053 return;
2054 bool is_main_frame = (url == GetURL());
2055
2056 DownloadManager* dlm =
2057 BrowserContext::GetDownloadManager(GetBrowserContext());
2058 if (!dlm)
2059 return;
2060 int64 post_id = -1;
2061 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272062 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012063 if (entry)
2064 post_id = entry->GetPostID();
2065 }
2066 scoped_ptr<DownloadUrlParameters> params(
2067 DownloadUrlParameters::FromWebContents(this, url));
2068 params->set_referrer(referrer);
2069 params->set_post_id(post_id);
2070 params->set_prefer_cache(true);
2071 if (post_id >= 0)
2072 params->set_method("POST");
2073 params->set_prompt(true);
2074 dlm->DownloadUrl(params.Pass());
2075}
2076
[email protected]b172aee2012-04-10 17:05:262077void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342078 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482079 const base::Callback<void(int64)>& callback) {
2080 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122081}
2082
[email protected]b172aee2012-04-10 17:05:262083const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272084 return contents_mime_type_;
2085}
2086
[email protected]b172aee2012-04-10 17:05:262087bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272088 return notify_disconnection_;
2089}
2090
[email protected]b172aee2012-04-10 17:05:262091void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312092 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182093 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162094}
2095
[email protected]b172aee2012-04-10 17:05:262096void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542097 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182098 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162099}
2100
[email protected]8ff00d72012-10-23 19:12:212101RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272102 return &renderer_preferences_;
2103}
2104
[email protected]e35ccd52012-05-23 16:22:472105void WebContentsImpl::Close() {
2106 Close(GetRenderViewHost());
2107}
2108
[email protected]cf200a562013-05-03 16:24:292109void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462110 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292111 if (browser_plugin_embedder_.get())
2112 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2113 screen_x, screen_y, operation);
2114 if (GetRenderViewHost())
2115 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2116 screen_x, screen_y, operation);
2117}
2118
[email protected]d60f3702013-12-26 16:30:242119void WebContentsImpl::DidGetResourceResponseStart(
2120 const ResourceRequestDetails& details) {
2121 controller_.ssl_manager()->DidStartResourceResponse(details);
2122
2123 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2124 DidGetResourceResponseStart(details));
2125
2126 // TODO(avi): Remove. http://crbug.com/170921
2127 NotificationService::current()->Notify(
2128 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2129 Source<WebContents>(this),
2130 Details<const ResourceRequestDetails>(&details));
2131}
2132
2133void WebContentsImpl::DidGetRedirectForResourceRequest(
2134 RenderViewHost* render_view_host,
2135 const ResourceRedirectDetails& details) {
2136 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2137
2138 FOR_EACH_OBSERVER(
2139 WebContentsObserver,
2140 observers_,
2141 DidGetRedirectForResourceRequest(render_view_host, details));
2142
2143 // TODO(avi): Remove. http://crbug.com/170921
2144 NotificationService::current()->Notify(
2145 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2146 Source<WebContents>(this),
2147 Details<const ResourceRedirectDetails>(&details));
2148}
2149
[email protected]b172aee2012-04-10 17:05:262150void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522151 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582152 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512153 if (delegate_)
2154 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292155 if (browser_plugin_embedder_.get())
2156 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342157}
2158
[email protected]e35ccd52012-05-23 16:22:472159void WebContentsImpl::UserGestureDone() {
2160 OnUserGesture();
2161}
2162
[email protected]b172aee2012-04-10 17:05:262163void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272164 closed_by_user_gesture_ = value;
2165}
2166
[email protected]b172aee2012-04-10 17:05:262167bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272168 return closed_by_user_gesture_;
2169}
2170
[email protected]b172aee2012-04-10 17:05:262171int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592172 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172173 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012174 // Calculate the zoom percent from the factor. Round up to the nearest whole
2175 // number.
[email protected]b75b8292010-10-01 07:28:252176 int percent = static_cast<int>(
[email protected]fce823222014-05-30 16:24:302177 ZoomLevelToZoomFactor(HostZoomMap::GetZoomLevel(this)) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252178 *enable_decrement = percent > minimum_zoom_percent_;
2179 *enable_increment = percent < maximum_zoom_percent_;
2180 return percent;
2181}
2182
[email protected]b172aee2012-04-10 17:05:262183void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502184 if (!delegate_)
2185 return;
2186
[email protected]6286a372013-10-09 04:03:272187 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2188 if (!entry)
[email protected]1788e772010-12-15 16:40:502189 return;
2190
[email protected]6286a372013-10-09 04:03:272191 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122192}
2193
[email protected]b172aee2012-04-10 17:05:262194void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042195 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272196 if (!delegate_)
2197 return;
2198
[email protected]691aa2f2013-05-28 22:52:042199 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272200}
2201
[email protected]b172aee2012-04-10 17:05:262202int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272203 return minimum_zoom_percent_;
2204}
2205
[email protected]b172aee2012-04-10 17:05:262206int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272207 return maximum_zoom_percent_;
2208}
2209
[email protected]b172aee2012-04-10 17:05:262210gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492211 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232212}
2213
[email protected]b172aee2012-04-10 17:05:262214bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052215 if (GetBrowserPluginGuest())
2216 return GetBrowserPluginGuest()->LockMouse(allowed);
2217
[email protected]0bfbf882011-12-22 18:19:272218 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582219 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272220}
2221
[email protected]b172aee2012-04-10 17:05:262222bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442223 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502224}
2225
[email protected]cb805452013-05-22 15:16:212226void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482227 if (!color_chooser_info_.get())
2228 return;
2229 RenderFrameHost* rfh = RenderFrameHost::FromID(
2230 color_chooser_info_->render_process_id,
2231 color_chooser_info_->render_frame_id);
2232 if (!rfh)
2233 return;
2234
2235 rfh->Send(new FrameMsg_DidChooseColorResponse(
2236 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202237}
2238
[email protected]cb805452013-05-22 15:16:212239void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482240 if (!color_chooser_info_.get())
2241 return;
2242 RenderFrameHost* rfh = RenderFrameHost::FromID(
2243 color_chooser_info_->render_process_id,
2244 color_chooser_info_->render_frame_id);
2245 if (!rfh)
2246 return;
2247
2248 rfh->Send(new FrameMsg_DidEndColorChooser(
2249 rfh->GetRoutingID(), color_chooser_info_->identifier));
2250 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202251}
2252
[email protected]41225fe2013-03-29 05:32:022253int WebContentsImpl::DownloadImage(const GURL& url,
2254 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302255 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022256 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582257 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022258 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392259 return id;
2260}
2261
[email protected]5dcaf8e2013-12-28 01:31:422262bool WebContentsImpl::IsSubframe() const {
2263 return is_subframe_;
2264}
2265
[email protected]36ec24f2014-01-09 00:32:082266void WebContentsImpl::Find(int request_id,
2267 const base::string16& search_text,
2268 const blink::WebFindOptions& options) {
2269 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2270}
2271
2272void WebContentsImpl::StopFinding(StopFindAction action) {
2273 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2274}
2275
[email protected]4fe53add2014-04-08 19:53:362276void WebContentsImpl::InsertCSS(const std::string& css) {
2277 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2278 GetMainFrame()->GetRoutingID(), css));
2279}
2280
[email protected]b172aee2012-04-10 17:05:262281bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272282 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172283 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332284 return true;
2285 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272286}
2287
[email protected]b172aee2012-04-10 17:05:262288void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272289 if (delegate_)
2290 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212291}
2292
[email protected]52913802013-12-10 05:52:182293void WebContentsImpl::DidStartProvisionalLoad(
2294 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072295 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182296 const GURL& validated_url,
2297 bool is_error_page,
2298 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262299 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]d974a0a2013-01-10 01:43:572300
[email protected]0d60f0192011-04-14 12:40:102301 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272302 int render_frame_id = render_frame_host->GetRoutingID();
2303 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252304 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072305 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272306 render_frame_id, parent_routing_id, is_main_frame,
2307 validated_url, is_error_page, is_iframe_srcdoc,
2308 render_view_host));
[email protected]400992b2012-06-14 00:03:542309
2310 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182311 FOR_EACH_OBSERVER(
2312 WebContentsObserver,
2313 observers_,
2314 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582315 render_frame_host));
[email protected]400992b2012-06-14 00:03:542316 }
2317}
2318
[email protected]3109fbb72014-01-06 23:57:152319void WebContentsImpl::DidFailProvisionalLoadWithError(
2320 RenderFrameHostImpl* render_frame_host,
2321 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2322 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272323 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262324 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272325 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152326 FOR_EACH_OBSERVER(
2327 WebContentsObserver,
2328 observers_,
[email protected]161eabd2014-03-19 19:47:272329 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152330 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262331 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152332 validated_url,
2333 params.error_code,
2334 params.error_description,
[email protected]161eabd2014-03-19 19:47:272335 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152336}
2337
[email protected]b80624c2014-02-09 02:46:552338void WebContentsImpl::DidFailLoadWithError(
2339 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552340 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552341 int error_code,
2342 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272343 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262344 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272345 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552346 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272347 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262348 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552349}
2350
[email protected]52913802013-12-10 05:52:182351void WebContentsImpl::NotifyChangedNavigationState(
2352 InvalidateTypes changed_flags) {
2353 NotifyNavigationStateChanged(changed_flags);
2354}
2355
[email protected]3691e5cf2014-01-22 10:16:202356void WebContentsImpl::AboutToNavigateRenderFrame(
2357 RenderFrameHostImpl* render_frame_host) {
2358 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272359 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202360 FOR_EACH_OBSERVER(
2361 WebContentsObserver,
2362 observers_,
[email protected]161eabd2014-03-19 19:47:272363 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202364}
2365
2366void WebContentsImpl::DidStartNavigationToPendingEntry(
2367 RenderFrameHostImpl* render_frame_host,
2368 const GURL& url,
2369 NavigationController::ReloadType reload_type) {
2370 // Notify observers about navigation.
2371 FOR_EACH_OBSERVER(
2372 WebContentsObserver,
2373 observers_,
2374 DidStartNavigationToPendingEntry(url, reload_type));
2375}
2376
[email protected]8cb834e2014-03-06 14:23:232377void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2378 const OpenURLParams& params) {
2379 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182380 WebContents* new_contents = OpenURL(params);
2381
2382 if (new_contents) {
2383 // Notify observers.
2384 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2385 DidOpenRequestedURL(new_contents,
2386 params.url,
2387 params.referrer,
2388 params.disposition,
2389 params.transition,
[email protected]8cb834e2014-03-06 14:23:232390 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182391 }
2392}
2393
[email protected]aa62afd2014-04-22 19:22:462394bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2395 if (!delegate_)
2396 return false;
2397 return delegate_->ShouldPreserveAbortedURLs(this);
2398}
2399
[email protected]400992b2012-06-14 00:03:542400void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582401 RenderFrameHostImpl* render_frame_host,
2402 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542403 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582404 FOR_EACH_OBSERVER(
2405 WebContentsObserver,
2406 observers_,
2407 ProvisionalChangeToMainFrameUrl(validated_target_url,
2408 render_frame_host));
[email protected]724159a2010-12-30 01:11:182409}
2410
[email protected]37567b432014-02-12 01:12:222411void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432412 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222413 const base::string16& frame_unique_name,
2414 bool is_main_frame,
2415 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432416 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432417 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272418 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222419 // Notify observers about the commit of the provisional load.
2420 FOR_EACH_OBSERVER(
2421 WebContentsObserver,
2422 observers_,
[email protected]27dd82fd2014-03-03 22:11:432423 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222424 frame_unique_name,
2425 is_main_frame,
2426 url,
2427 transition_type,
2428 render_view_host));
2429}
2430
[email protected]0d0f4c492014-04-02 06:42:572431void WebContentsImpl::DidNavigateMainFramePreCommit(
2432 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2433 // Ensure fullscreen mode is exited before committing the navigation to a
2434 // different page. The next page will not start out assuming it is in
2435 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192436 if (controller_.IsURLInPageNavigation(params.url,
2437 params.was_within_same_page,
2438 NAVIGATION_TYPE_UNKNOWN)) {
2439 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572440 return;
2441 }
2442 if (IsFullscreenForCurrentTab())
2443 GetRenderViewHost()->ExitFullscreen();
2444 DCHECK(!IsFullscreenForCurrentTab());
2445}
2446
[email protected]37567b432014-02-12 01:12:222447void WebContentsImpl::DidNavigateMainFramePostCommit(
2448 const LoadCommittedDetails& details,
2449 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2450 if (details.is_navigation_to_different_page()) {
2451 // Clear the status bubble. This is a workaround for a bug where WebKit
2452 // doesn't let us know that the cursor left an element during a
2453 // transition (this is also why the mouse cursor remains as a hand after
2454 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2455 // clear the bubble when a user navigates to a named anchor in the same
2456 // page.
2457 UpdateTargetURL(details.entry->GetPageID(), GURL());
2458 }
2459
2460 if (!details.is_in_page) {
2461 // Once the main frame is navigated, we're no longer considered to have
2462 // displayed insecure content.
2463 displayed_insecure_content_ = false;
2464 SSLManager::NotifySSLInternalStateChanged(
2465 GetController().GetBrowserContext());
2466 }
2467
2468 // Notify observers about navigation.
2469 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2470 DidNavigateMainFrame(details, params));
2471
[email protected]e85165c642014-06-10 14:34:312472 if (delegate_)
[email protected]37567b432014-02-12 01:12:222473 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312474 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222475}
2476
2477void WebContentsImpl::DidNavigateAnyFramePostCommit(
2478 RenderFrameHostImpl* render_frame_host,
2479 const LoadCommittedDetails& details,
2480 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102481 // Now that something has committed, we don't need to track whether the
2482 // initial page has been accessed.
2483 has_accessed_initial_document_ = false;
2484
[email protected]37567b432014-02-12 01:12:222485 // If we navigate off the page, close all JavaScript dialogs.
2486 if (dialog_manager_ && !details.is_in_page)
2487 dialog_manager_->CancelActiveAndPendingDialogs(this);
2488
2489 // Notify observers about navigation.
2490 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2491 DidNavigateAnyFrame(details, params));
2492}
2493
2494void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2495 contents_mime_type_ = mime_type;
2496}
2497
[email protected]277857a2014-06-03 10:38:012498bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312499 // Disable overscroll when touch emulation is on. See crbug.com/369938.
2500 if (touch_emulation_enabled_)
2501 return false;
2502
[email protected]37567b432014-02-12 01:12:222503 if (delegate_)
2504 return delegate_->CanOverscrollContent();
2505
2506 return false;
2507}
2508
[email protected]b172aee2012-04-10 17:05:262509void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182510 const GURL& url,
[email protected]70435962011-08-02 20:13:282511 const std::string& security_info,
2512 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182513 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282514 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192515 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182516 cache.Increment();
2517
2518 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082519 int cert_id = 0;
2520 net::CertStatus cert_status = 0;
2521 int security_bits = -1;
2522 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122523 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212524 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122525 &security_bits, &connection_status,
2526 &signed_certificate_timestamp_ids);
2527 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212528 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002529 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2530 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182531
[email protected]b0f724c2013-09-05 04:21:132532 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2533
2534 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2535 DidLoadResourceFromMemoryCache(details));
2536
[email protected]8bfc8272013-09-09 20:10:532537 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2538 scoped_refptr<net::URLRequestContextGetter> request_context(
2539 resource_type == ResourceType::MEDIA ?
2540 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2541 GetRenderProcessHost()->GetID()) :
2542 GetBrowserContext()->GetRequestContextForRenderProcess(
2543 GetRenderProcessHost()->GetID()));
2544 BrowserThread::PostTask(
2545 BrowserThread::IO,
2546 FROM_HERE,
2547 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2548 }
[email protected]724159a2010-12-30 01:11:182549}
2550
[email protected]b172aee2012-04-10 17:05:262551void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392552 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182553 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192554 SSLManager::NotifySSLInternalStateChanged(
2555 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182556}
2557
[email protected]b172aee2012-04-10 17:05:262558void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022559 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582560 LOG(WARNING) << security_origin << " ran insecure content from "
2561 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392562 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412563 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392564 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182565 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412566 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192567 SSLManager::NotifySSLInternalStateChanged(
2568 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182569}
2570
[email protected]501052ff2014-02-21 22:19:072571void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572572 CHECK(render_frame_message_source_);
2573 CHECK(!render_view_message_source_);
2574 RenderFrameHostImpl* rfh =
2575 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2576
[email protected]161eabd2014-03-19 19:47:272577 int render_frame_id = rfh->GetRoutingID();
2578 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572579 FOR_EACH_OBSERVER(WebContentsObserver,
2580 observers_,
[email protected]161eabd2014-03-19 19:47:272581 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182582}
2583
[email protected]b172aee2012-04-10 17:05:262584void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262585 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372586 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122587 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2588 GetRenderProcessHost()->ReceivedBadMessage();
2589 return;
2590 }
[email protected]a1b99262013-12-27 21:56:222591
[email protected]8b3af1e2014-01-24 13:29:122592 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442593 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372594 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422595 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372596
[email protected]61ac9e242014-03-21 20:55:262597 RenderFrameHostImpl* rfh =
2598 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272599 int render_frame_id = rfh->GetRoutingID();
2600 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262601 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252602 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272603 DidFinishLoad(render_frame_id, validated_url,
2604 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312605}
2606
[email protected]960b0372014-05-19 18:01:002607void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2608 RenderFrameHostImpl* rfh =
2609 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2610 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2611
2612 // It is possible to get multiple calls to OnDidStartLoading that don't have
2613 // corresponding calls to OnDidStopLoading:
2614 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2615 // out for a cross-process navigation, and it turns into a placeholder for
2616 // one being rendered in a different process.
2617 // - Also, there might be more than one RenderFrameHost sharing the same
2618 // FrameTreeNode (and thus sharing its ID) each sending a start.
2619 // - But in the future, once clamy@ moves navigation network requests to the
2620 // browser process, there's a good chance that callbacks about starting and
2621 // stopping will all be handled by the browser. When that happens, there
2622 // should no longer be a start/stop call imbalance. TODO(avi): When this
2623 // future arrives, update this code to not allow this case.
2624 DCHECK_GE(loading_frames_in_progress_, 0);
2625 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2626 if (loading_frames_in_progress_ == 0)
2627 DidStartLoading(rfh, to_different_document);
2628 ++loading_frames_in_progress_;
2629 }
2630
2631 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2632 SendLoadProgressChanged();
2633}
2634
2635void WebContentsImpl::OnDidStopLoading() {
2636 RenderFrameHostImpl* rfh =
2637 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2638 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2639
2640 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2641 // Load stopped while we were still tracking load. Make sure we update
2642 // progress based on this frame's completion.
2643 loading_progresses_[render_frame_id] = 1.0;
2644 SendLoadProgressChanged();
2645 // Then we clean-up our states.
2646 if (loading_total_progress_ == 1.0)
2647 ResetLoadProgressState();
2648 }
2649
2650 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2651 // calls DidStopLoading() without a matching DidStartLoading().
2652 if (loading_frames_in_progress_ == 0)
2653 return;
2654 --loading_frames_in_progress_;
2655 if (loading_frames_in_progress_ == 0)
2656 DidStopLoading(rfh);
2657}
2658
2659void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
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 loading_progresses_[render_frame_id] = load_progress;
2665
2666 // We notify progress change immediately for the first and last updates.
2667 // Also, since the message loop may be pretty busy when a page is loaded, it
2668 // might not execute a posted task in a timely manner so we make sure to
2669 // immediately send progress report if enough time has passed.
2670 base::TimeDelta min_delay =
2671 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2672 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2673 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2674 // If there is a pending task to send progress, it is now obsolete.
2675 loading_weak_factory_.InvalidateWeakPtrs();
2676 SendLoadProgressChanged();
2677 if (loading_total_progress_ == 1.0)
2678 ResetLoadProgressState();
2679 return;
2680 }
2681
2682 if (loading_weak_factory_.HasWeakPtrs())
2683 return;
2684
2685 base::MessageLoop::current()->PostDelayedTask(
2686 FROM_HERE,
2687 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2688 loading_weak_factory_.GetWeakPtr()),
2689 min_delay);
2690}
2691
[email protected]b172aee2012-04-10 17:05:262692void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222693 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2694 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262695}
2696
[email protected]b172aee2012-04-10 17:05:262697void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302698 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262699 minimum_zoom_percent_ = minimum_percent;
2700 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262701}
2702
[email protected]b172aee2012-04-10 17:05:262703void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342704 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432705 if (!delegate_)
2706 return;
2707
[email protected]b9535422012-02-09 01:47:592708 ChildProcessSecurityPolicyImpl* policy =
2709 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222710 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592711 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212712}
2713
[email protected]b172aee2012-04-10 17:05:262714void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2715 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262716 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362717 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432718 if (!delegate_)
2719 return;
2720
[email protected]b9535422012-02-09 01:47:592721 ChildProcessSecurityPolicyImpl* policy =
2722 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322723 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592724 return;
[email protected]8f810632013-06-06 22:33:322725
[email protected]c125e532014-05-10 20:39:062726 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202727}
2728
[email protected]b172aee2012-04-10 17:05:262729void WebContentsImpl::OnFindReply(int request_id,
2730 int number_of_matches,
2731 const gfx::Rect& selection_rect,
2732 int active_match_ordinal,
2733 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432734 if (delegate_) {
2735 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2736 active_match_ordinal, final_update);
2737 }
[email protected]b888919c2011-09-02 00:32:162738}
2739
[email protected]59363fc92012-09-05 03:46:312740#if defined(OS_ANDROID)
2741void WebContentsImpl::OnFindMatchRectsReply(
2742 int version,
2743 const std::vector<gfx::RectF>& rects,
2744 const gfx::RectF& active_rect) {
2745 if (delegate_)
2746 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2747}
[email protected]583418cc2013-01-17 14:01:102748
[email protected]1ff427972013-02-07 21:14:072749void WebContentsImpl::OnOpenDateTimeDialog(
2750 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092751 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2752 GetRenderViewHost(),
2753 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132754 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092755 value.minimum,
2756 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172757 value.step,
2758 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102759}
2760
[email protected]59363fc92012-09-05 03:46:312761#endif
2762
[email protected]f114fa42013-12-06 17:06:442763void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2764 const base::FilePath& path,
2765 bool is_hung) {
2766 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2767
2768 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2769 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2770}
2771
2772void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422773 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442774 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422775 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452776}
2777
[email protected]cfa856d62014-02-22 07:58:402778void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2779 int automation_id) {
2780 DomOperationNotificationDetails details(json_string, automation_id);
2781 NotificationService::current()->Notify(
2782 NOTIFICATION_DOM_OPERATION_RESPONSE,
2783 Source<WebContents>(this),
2784 Details<DomOperationNotificationDetails>(&details));
2785}
2786
[email protected]b172aee2012-04-10 17:05:262787void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2788 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102789 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252790 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102791 AppCacheAccessed(manifest_url, blocked_by_policy));
2792}
2793
[email protected]8bc5ff02013-11-29 06:34:032794void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482795 int color_chooser_id,
2796 SkColor color,
2797 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462798 ColorChooser* new_color_chooser = delegate_ ?
2799 delegate_->OpenColorChooser(this, color, suggestions) :
2800 NULL;
[email protected]820957a2014-01-14 14:56:302801 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212802 return;
[email protected]8ed16472014-04-11 19:02:482803 if (color_chooser_info_.get())
2804 color_chooser_info_->chooser->End();
2805
2806 color_chooser_info_.reset(new ColorChooserInfo(
2807 render_frame_message_source_->GetProcess()->GetID(),
2808 render_frame_message_source_->GetRoutingID(),
2809 new_color_chooser,
2810 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202811}
2812
[email protected]b172aee2012-04-10 17:05:262813void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482814 if (color_chooser_info_ &&
2815 color_chooser_id == color_chooser_info_->identifier)
2816 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202817}
2818
[email protected]b172aee2012-04-10 17:05:262819void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322820 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482821 if (color_chooser_info_ &&
2822 color_chooser_id == color_chooser_info_->identifier)
2823 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202824}
2825
[email protected]d0759f492012-04-19 22:50:502826// This exists for render views that don't have a WebUI, but do have WebUI
2827// bindings enabled.
2828void WebContentsImpl::OnWebUISend(const GURL& source_url,
2829 const std::string& name,
2830 const base::ListValue& args) {
2831 if (delegate_)
2832 delegate_->WebUISend(this, source_url, name, args);
2833}
2834
[email protected]d8415ad92012-08-23 14:40:502835void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442836 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502837 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342838 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162839 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442840 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162841 return;
[email protected]d8415ad92012-08-23 14:40:502842 }
2843
[email protected]8c8fc292012-11-23 18:57:162844 if (!delegate_->RequestPpapiBrokerPermission(
2845 this, url, plugin_path,
2846 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442847 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162848 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442849 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162850 }
[email protected]d8415ad92012-08-23 14:40:502851}
2852
[email protected]ea0309c2013-08-06 19:35:442853void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502854 bool result) {
[email protected]ea0309c2013-08-06 19:35:442855 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502856}
2857
[email protected]c4538072013-03-18 02:17:552858void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372859 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082860 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552861 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392862 // For more info, see comment above classes BrowserPluginEmbedder and
2863 // BrowserPluginGuest.
2864 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142865 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082866 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372867}
2868
[email protected]41225fe2013-03-29 05:32:022869void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392870 int id,
[email protected]749fadd2013-05-15 08:37:482871 int http_status_code,
[email protected]795c28972012-12-06 06:13:392872 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302873 const std::vector<SkBitmap>& bitmaps,
2874 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132875 if (bitmaps.size() != original_bitmap_sizes.size())
2876 return;
2877
[email protected]41225fe2013-03-29 05:32:022878 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2879 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392880 // Currently WebContents notifies us of ANY downloads so that it is
2881 // possible to get here.
2882 return;
2883 }
2884 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302885 iter->second.Run(
2886 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392887 }
[email protected]41225fe2013-03-29 05:32:022888 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392889}
2890
2891void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392892 const std::vector<FaviconURL>& candidates) {
2893 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292894 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392895}
2896
[email protected]1dd0bb752014-02-01 01:16:262897void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2898 bool has_video,
2899 bool has_audio) {
2900// Chrome OS does its own detection of audio and video.
2901#if !defined(OS_CHROMEOS)
2902 scoped_ptr<PowerSaveBlocker> blocker;
2903 if (has_video) {
2904 blocker = PowerSaveBlocker::Create(
2905 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2906#if defined(OS_ANDROID)
2907 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2908 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2909#endif
2910 } else if (has_audio) {
2911 blocker = PowerSaveBlocker::Create(
2912 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2913 }
2914
2915 if (blocker) {
[email protected]96307312014-05-04 01:00:192916 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262917 blocker.release();
2918 }
2919#endif // !defined(OS_CHROMEOS)
2920}
2921
2922void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062923 // Chrome OS does its own detection of audio and video.
2924#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192925 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2926 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062927#endif // !defined(OS_CHROMEOS)
2928}
2929
[email protected]50279492014-05-05 23:24:292930void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152931 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292932 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152933}
[email protected]d9030b82013-07-19 08:26:062934
[email protected]e67ebf32013-02-13 11:07:192935void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:072936 if (delegate_)
2937 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:192938}
2939
[email protected]17e286e2013-03-01 23:29:392940void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2941 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2942 BeforeFormRepostWarningShow());
2943}
2944
[email protected]ec6c05f2013-10-23 18:41:572945
2946void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2947 Activate();
2948 if (delegate_)
2949 delegate_->ShowRepostFormWarningDialog(this);
2950}
2951
[email protected]b4c84012014-04-28 19:51:102952bool WebContentsImpl::HasAccessedInitialDocument() {
2953 return has_accessed_initial_document_;
2954}
2955
[email protected]96d185d2009-04-24 03:28:542956// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592957// loading, or done loading.
2958void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2959 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092960 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262961 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542962 if (is_loading == is_loading_)
2963 return;
2964
2965 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262966 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2967 base::string16());
[email protected]96d185d2009-04-24 03:28:542968 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562969 upload_size_ = 0;
2970 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542971 }
2972
[email protected]fa944cb82013-11-15 17:51:212973 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542974
2975 is_loading_ = is_loading;
2976 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:032977 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:542978
[email protected]6ebdc9b2010-09-27 16:55:572979 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092980 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212981 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542982
[email protected]eab61442013-11-14 18:35:482983 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592984 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482985 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2986 "URL", url);
[email protected]91621872013-10-08 04:04:592987 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2988 DidStartLoading(render_view_host));
2989 } else {
[email protected]eab61442013-11-14 18:35:482990 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2991 "URL", url);
[email protected]91621872013-10-08 04:04:592992 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2993 DidStopLoading(render_view_host));
2994 }
[email protected]66798902013-10-01 18:40:162995
2996 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212997 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2998 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542999 if (details)
[email protected]8ff00d72012-10-23 19:12:213000 det = Details<LoadNotificationDetails>(details);
3001 NotificationService::current()->Notify(
3002 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543003}
3004
[email protected]959be4c2014-04-08 15:01:333005void WebContentsImpl::SelectRange(const gfx::Point& start,
3006 const gfx::Point& end) {
3007 RenderFrameHost* focused_frame = GetFocusedFrame();
3008 if (!focused_frame)
3009 return;
3010
3011 focused_frame->Send(
3012 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
3013}
3014
[email protected]b172aee2012-04-10 17:05:263015void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463016 // If we are creating a RVH for a restored controller, then we need to make
3017 // sure the RenderView starts with a next_page_id_ larger than the number
3018 // of restored entries. This must be called before the RenderView starts
3019 // navigating (to avoid a race between the browser updating max_page_id and
3020 // the renderer updating next_page_id_). Because of this, we only call this
3021 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563022 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583023 if (max_restored_page_id >
3024 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3025 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3026 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323027}
3028
[email protected]b172aee2012-04-10 17:05:263029bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263030 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323031 // For file URLs without a title, use the pathname instead. In the case of a
3032 // synthesized title, we don't want the update to count toward the "one set
3033 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263034 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323035 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513036 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243037 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323038 explicit_set = false; // Don't count synthetic titles toward the set limit.
3039 } else {
[email protected]8af69c6c2014-03-03 19:05:313040 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323041 explicit_set = true;
3042 }
3043
[email protected]987fc3a2011-05-26 14:18:093044 // If a page is created via window.open and never navigated,
3045 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553046 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093047 if (entry) {
[email protected]36fc0392011-12-25 03:59:513048 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093049 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323050
[email protected]36fc0392011-12-25 03:59:513051 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093052 } else {
3053 if (page_title_when_no_navigation_entry_ == final_title)
3054 return false; // Nothing changed, don't bother.
3055
3056 page_title_when_no_navigation_entry_ = final_title;
3057 }
[email protected]420ae012009-04-24 05:16:323058
[email protected]420ae012009-04-24 05:16:323059 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233060 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323061
[email protected]66798902013-10-01 18:40:163062 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533063 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163064
3065 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213066 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463067 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213068 NotificationService::current()->Notify(
3069 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3070 Source<WebContents>(this),
3071 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043072
[email protected]420ae012009-04-24 05:16:323073 return true;
3074}
3075
[email protected]960b0372014-05-19 18:01:003076void WebContentsImpl::SendLoadProgressChanged() {
3077 loading_last_progress_update_ = base::TimeTicks::Now();
3078 double progress = 0.0;
3079 int frame_count = 0;
3080
3081 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3082 it != loading_progresses_.end();
3083 ++it) {
3084 progress += it->second;
3085 ++frame_count;
3086 }
3087 if (frame_count == 0)
3088 return;
3089 progress /= frame_count;
3090 DCHECK(progress <= 1.0);
3091
3092 if (progress <= loading_total_progress_)
3093 return;
3094 loading_total_progress_ = progress;
3095
3096 if (delegate_)
3097 delegate_->LoadProgressChanged(this, progress);
3098}
3099
3100void WebContentsImpl::ResetLoadProgressState() {
3101 loading_progresses_.clear();
3102 loading_total_progress_ = 0.0;
3103 loading_weak_factory_.InvalidateWeakPtrs();
3104 loading_last_progress_update_ = base::TimeTicks();
3105}
3106
[email protected]7b712ee22013-10-03 00:57:283107void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
3108 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323109 // After sending out a swap notification, we need to send a disconnect
3110 // notification so that clients that pick up a pointer to |this| can NULL the
3111 // pointer. See Bug 1230284.
3112 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113113 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283114 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113115
3116 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283117 std::pair<RenderViewHost*, RenderViewHost*> details =
3118 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213119 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283120 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213121 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283122 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393123
3124 // Ensure that the associated embedder gets cleared after a RenderViewHost
3125 // gets swapped, so we don't reuse the same embedder next time a
3126 // RenderViewHost is attached to this WebContents.
3127 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323128}
3129
[email protected]da7a7182013-09-06 08:11:113130// TODO(avi): Remove this entire function because this notification is already
3131// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263132void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323133 if (!notify_disconnection_)
3134 return;
3135
3136 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213137 NotificationService::current()->Notify(
3138 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3139 Source<WebContents>(this),
3140 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323141}
3142
[email protected]cbb1ef592013-06-05 19:49:463143void WebContentsImpl::NotifyNavigationEntryCommitted(
3144 const LoadCommittedDetails& load_details) {
3145 FOR_EACH_OBSERVER(
3146 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3147}
3148
[email protected]f114fa42013-12-06 17:06:443149bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3150 const IPC::Message& message) {
3151 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313152}
3153
[email protected]c31a84802014-04-03 15:55:493154const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3155 return GetLastCommittedURL();
3156}
3157
[email protected]b849847b2013-12-10 21:57:583158void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3159 // Note this is only for subframes, the notification for the main frame
3160 // happens in RenderViewCreated.
3161 FOR_EACH_OBSERVER(WebContentsObserver,
3162 observers_,
3163 RenderFrameCreated(render_frame_host));
3164}
3165
3166void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193167 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583168 FOR_EACH_OBSERVER(WebContentsObserver,
3169 observers_,
3170 RenderFrameDeleted(render_frame_host));
3171}
3172
[email protected]a09d53ce2014-01-31 00:46:423173void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303174 if (delegate_)
3175 delegate_->WorkerCrashed(this);
3176}
3177
[email protected]a09d53ce2014-01-31 00:46:423178void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3179 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103180 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423181 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103182 if (GetBrowserPluginGuest()) {
3183 WebContentsViewGuest* view_guest =
3184 static_cast<WebContentsViewGuest*>(GetView());
3185 context_menu_params = view_guest->ConvertContextMenuParams(params);
3186 }
3187 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423188 return;
3189
[email protected]077e704b2014-05-23 19:24:103190 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3191 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423192}
3193
[email protected]87de04b02014-04-08 22:14:493194void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013195 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493196 const base::string16& message,
3197 const base::string16& default_prompt,
3198 const GURL& frame_url,
3199 JavaScriptMessageType javascript_message_type,
3200 IPC::Message* reply_msg) {
3201 // Suppress JavaScript dialogs when requested. Also suppress messages when
3202 // showing an interstitial as it's shown over the previous page and we don't
3203 // want the hidden page's dialogs to interfere with the interstitial.
3204 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013205 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493206 IsSwappedOut() ||
3207 ShowingInterstitialPage() ||
3208 !delegate_ ||
3209 delegate_->ShouldSuppressDialogs() ||
3210 !delegate_->GetJavaScriptDialogManager();
3211
3212 if (!suppress_this_message) {
3213 std::string accept_lang = GetContentClient()->browser()->
3214 GetAcceptLangs(GetBrowserContext());
3215 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3216 dialog_manager_->RunJavaScriptDialog(
3217 this,
3218 frame_url.GetOrigin(),
3219 accept_lang,
3220 javascript_message_type,
3221 message,
3222 default_prompt,
3223 base::Bind(&WebContentsImpl::OnDialogClosed,
3224 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013225 render_frame_host->GetProcess()->GetID(),
3226 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493227 reply_msg,
3228 false),
3229 &suppress_this_message);
3230 }
3231
3232 if (suppress_this_message) {
3233 // If we are suppressing messages, just reply as if the user immediately
3234 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013235 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3236 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283237 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493238 }
3239
3240 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3241 // http://crbug.com/288961 ). The only safe thing to do here is return.
3242}
3243
3244void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013245 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493246 const base::string16& message,
3247 bool is_reload,
3248 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013249 RenderFrameHostImpl* rfhi =
3250 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493251 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013252 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493253 if (delegate_)
3254 delegate_->WillRunBeforeUnloadConfirm();
3255
3256 bool suppress_this_message =
3257 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3258 !delegate_ ||
3259 delegate_->ShouldSuppressDialogs() ||
3260 !delegate_->GetJavaScriptDialogManager();
3261 if (suppress_this_message) {
3262 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3263 return;
3264 }
3265
3266 is_showing_before_unload_dialog_ = true;
3267 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3268 dialog_manager_->RunBeforeUnloadDialog(
3269 this, message, is_reload,
3270 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013271 render_frame_host->GetProcess()->GetID(),
3272 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283273 false));
[email protected]87de04b02014-04-08 22:14:493274}
3275
[email protected]a86c0e962013-12-17 17:10:393276WebContents* WebContentsImpl::GetAsWebContents() {
3277 return this;
3278}
3279
[email protected]7912e822014-04-16 02:37:033280bool WebContentsImpl::IsNeverVisible() {
3281 if (!delegate_)
3282 return false;
3283 return delegate_->IsNeverVisible(this);
3284}
3285
[email protected]5a3bdf52012-05-24 15:12:573286RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3287 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323288}
3289
[email protected]8ff00d72012-10-23 19:12:213290RendererPreferences WebContentsImpl::GetRendererPrefs(
3291 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463292 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513293}
3294
[email protected]b172aee2012-04-10 17:05:263295gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173296 if (delegate_)
3297 return delegate_->GetRootWindowResizerRect();
3298 return gfx::Rect();
3299}
3300
[email protected]7a846df2012-09-20 19:17:393301void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273302 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393303 browser_plugin_embedder_.reset();
3304}
3305
[email protected]b172aee2012-04-10 17:05:263306void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443307 // Don't send notifications if we are just creating a swapped-out RVH for
3308 // the opener chain. These won't be used for view-source or WebUI, so it's
3309 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243310 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443311 return;
3312
[email protected]86f98a22013-03-20 14:35:003313 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313314 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083315
[email protected]8ff00d72012-10-23 19:12:213316 NotificationService::current()->Notify(
3317 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3318 Source<WebContents>(this),
3319 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323320
3321 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353322 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213323 if (GetRenderManager()->pending_web_ui())
3324 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323325
[email protected]6286a372013-10-09 04:03:273326 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333327 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323328 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183329 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583330 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323331 }
[email protected]0666aef2009-05-13 19:48:083332
[email protected]60780f412013-02-25 16:34:103333 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263334
3335 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253336 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583337
3338 // We tell the observers now instead of when the main RenderFrameHostImpl is
3339 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3340 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363341 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583342 FOR_EACH_OBSERVER(
3343 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323344}
3345
[email protected]b172aee2012-04-10 17:05:263346void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523347 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323348 // Don't notify the world, since this came from a renderer in the
3349 // background.
3350 return;
3351 }
3352
[email protected]da7a7182013-09-06 08:11:113353 notify_disconnection_ = true;
3354 // TODO(avi): Remove. http://crbug.com/170921
3355 NotificationService::current()->Notify(
3356 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3357 Source<WebContents>(this),
3358 NotificationService::NoDetails());
3359
[email protected]be1f56ab2011-12-22 06:55:313360 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233361 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303362
3363 // Restore the focus to the tab (otherwise the focus will be on the top
3364 // window).
[email protected]484ae5912010-09-29 19:16:143365 if (was_crashed && !FocusLocationBarByDefault() &&
3366 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063367 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143368 }
[email protected]32ded2212011-11-10 18:51:433369
[email protected]d8c660432011-12-22 20:51:253370 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323371}
3372
[email protected]ec6a7eb2013-04-22 17:34:223373void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3374 base::TerminationStatus status,
3375 int error_code) {
[email protected]151a63d2011-12-20 22:32:523376 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323377 // The pending page's RenderViewHost is gone.
3378 return;
3379 }
3380
[email protected]2fcdcc32014-03-05 02:14:073381 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3382 // renderer may not have made a clean exit.
3383 if (IsFullscreenForCurrentTab())
3384 ToggleFullscreenMode(false);
3385
[email protected]698191dc2014-02-25 01:06:133386 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3387 if (dialog_manager_)
3388 dialog_manager_->CancelActiveAndPendingDialogs(this);
3389
[email protected]e3b10d12014-03-28 16:06:093390 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323391 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233392 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453393
[email protected]960b0372014-05-19 18:01:003394 // Reset the loading progress. TODO(avi): What does it mean to have a
3395 // "renderer crash" when there is more than one renderer process serving a
3396 // webpage? Once this function is called at a more granular frame level, we
3397 // probably will need to more granularly reset the state here.
3398 ResetLoadProgressState();
3399 loading_frames_in_progress_ = 0;
3400
[email protected]d8c660432011-12-22 20:51:253401 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273402 observers_,
[email protected]58d5cfe2013-07-10 02:40:523403 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323404}
3405
[email protected]b172aee2012-04-10 17:05:263406void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253407 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063408}
3409
[email protected]b172aee2012-04-10 17:05:263410void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3411 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043412 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153413 // Ensure that this state update comes from either the active RVH or one of
3414 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413415 // TODO(nasko): This should go through RenderFrameHost.
3416 // TODO(creis): We can't update state for cross-process subframes until we
3417 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3418 if (rvh != GetRenderViewHost() &&
3419 !GetRenderManager()->IsRVHOnSwappedOutList(
3420 static_cast<RenderViewHostImpl*>(rvh)))
3421 return;
[email protected]420ae012009-04-24 05:16:323422
3423 // We must be prepared to handle state updates for any page, these occur
3424 // when the user is scrolling and entering form data, as well as when we're
3425 // leaving a page, in which case our state may have already been moved to
3426 // the next page. The navigation controller will look up the appropriate
3427 // NavigationEntry and update it when it is notified via the delegate.
3428
3429 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583430 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323431 if (entry_index < 0)
3432 return;
[email protected]10f417c52011-12-28 21:04:233433 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323434
[email protected]691aa2f2013-05-28 22:52:043435 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323436 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043437 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323438 controller_.NotifyEntryChanged(entry, entry_index);
3439}
3440
[email protected]b172aee2012-04-10 17:05:263441void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513442 if (delegate_)
3443 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323444}
3445
[email protected]b172aee2012-04-10 17:05:263446void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103447#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293448 // The UI may be in an event-tracking loop, such as between the
3449 // mouse-down and mouse-up in text selection or a button click.
3450 // Defer the close until after tracking is complete, so that we
3451 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293452 // TODO(shess): This could get more fine-grained. For instance,
3453 // closing a tab in another window while selecting text in the
3454 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103455 if (view_->IsEventTracking()) {
3456 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293457 return;
3458 }
[email protected]60780f412013-02-25 16:34:103459#endif
[email protected]07707302009-11-06 00:50:293460
[email protected]420ae012009-04-24 05:16:323461 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523462 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513463 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323464}
3465
[email protected]66bbadaf2014-03-28 16:25:543466void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573467 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3468 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573469}
3470
[email protected]b172aee2012-04-10 17:05:263471void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513472 if (delegate_ && delegate_->IsPopupOrPanel(this))
3473 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323474}
3475
[email protected]e3b10d12014-03-28 16:06:093476void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3477 bool to_different_document) {
3478 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3479 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323480}
3481
[email protected]723971b2014-02-12 11:08:253482void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323483 scoped_ptr<LoadNotificationDetails> details;
3484
[email protected]9595fd82013-04-19 21:28:493485 // Use the last committed entry rather than the active one, in case a
3486 // pending entry has been created.
3487 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203488 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493489
[email protected]420ae012009-04-24 05:16:323490 // An entry may not exist for a stop when loading an initial blank page or
3491 // if an iframe injected by script into a blank page finishes loading.
3492 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203493 base::TimeDelta elapsed =
3494 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323495
3496 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513497 entry->GetVirtualURL(),
3498 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323499 elapsed,
3500 &controller_,
3501 controller_.GetCurrentEntryIndex()));
3502 }
3503
[email protected]e3b10d12014-03-28 16:06:093504 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3505 details.get());
[email protected]420ae012009-04-24 05:16:323506}
3507
[email protected]b172aee2012-04-10 17:05:263508void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163509 controller_.DiscardNonCommittedEntries();
3510
3511 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213512 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163513}
3514
[email protected]59167c22013-06-03 18:07:323515void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103516 has_accessed_initial_document_ = true;
3517
[email protected]d1371bf8e2014-04-19 03:26:243518 // We may have left a failed browser-initiated navigation in the address bar
3519 // to let the user edit it and try again. Clear it now that content might
3520 // show up underneath it.
3521 if (!IsLoading() && controller_.GetPendingEntry())
3522 controller_.DiscardPendingEntry();
3523
[email protected]59167c22013-06-03 18:07:323524 // Update the URL display.
3525 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3526}
3527
[email protected]3f19f1a2014-05-02 05:23:273528void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3529 if (opener_) {
3530 // Clear our opener so that future cross-process navigations don't have an
3531 // opener assigned.
3532 RemoveDestructionObserver(opener_);
3533 opener_ = NULL;
3534 }
3535
3536 // Notify all swapped out RenderViewHosts for this tab. This is important
3537 // in case we go back to them, or if another window in those processes tries
3538 // to access window.opener.
3539 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3540}
3541
[email protected]39f2f9252014-05-03 00:54:013542void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293543 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093544 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293545 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093546
3547 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213548 NotificationService::current()->Notify(
3549 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3550 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293551 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083552}
3553
[email protected]ef3adfc2014-05-11 00:04:543554void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3555 int32 page_id,
3556 const base::string16& title,
3557 base::i18n::TextDirection title_direction) {
3558 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3559
3560 // If we have a title, that's a pretty good indication that we've started
3561 // getting useful data.
3562 SetNotWaitingForResponse();
3563
3564 // Try to find the navigation entry, which might not be the current one.
3565 // For example, it might be from a pending RVH for the pending entry.
3566 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3567 rvh->GetSiteInstance(), page_id);
3568
3569 // We can handle title updates when we don't have an entry in
3570 // UpdateTitleForEntry, but only if the update is from the current RVH.
3571 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3572 if (!entry && rvh != GetRenderViewHost())
3573 return;
3574
3575 // TODO(evan): make use of title_direction.
3576 // http://code.google.com/p/chromium/issues/detail?id=27094
3577 if (!UpdateTitleForEntry(entry, title))
3578 return;
3579
3580 // Broadcast notifications when the UI should be updated.
3581 if (entry == controller_.GetEntryAtOffset(0))
3582 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3583}
3584
3585void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3586 const std::string& encoding) {
3587 SetEncoding(encoding);
3588}
3589
[email protected]39f2f9252014-05-03 00:54:013590void WebContentsImpl::DocumentAvailableInMainFrame(
3591 RenderViewHost* render_view_host) {
3592 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3593 DocumentAvailableInMainFrame());
3594}
[email protected]e1c3a552012-05-04 20:51:323595void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3596 // Tell the active RenderViewHost to run unload handlers and close, as long
3597 // as the request came from a RenderViewHost in the same BrowsingInstance.
3598 // In most cases, we receive this from a swapped out RenderViewHost.
3599 // It is possible to receive it from one that has just been swapped in,
3600 // in which case we might as well deliver the message anyway.
3601 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3602 GetRenderViewHost()->ClosePage();
3603}
3604
[email protected]f546640b2012-05-15 00:03:493605void WebContentsImpl::RouteMessageEvent(
3606 RenderViewHost* rvh,
3607 const ViewMsg_PostMessage_Params& params) {
3608 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363609 // came from a RenderViewHost in the same BrowsingInstance or if this
3610 // WebContents is dedicated to a browser plugin guest.
3611 // Note: This check means that an embedder could theoretically receive a
3612 // postMessage from anyone (not just its own guests). However, this is
3613 // probably not a risk for apps since other pages won't have references
3614 // to App windows.
3615 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3616 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493617 return;
3618
3619 ViewMsg_PostMessage_Params new_params(params);
3620
[email protected]0bc7f3542013-10-21 15:05:533621 if (!params.message_port_ids.empty()) {
3622 MessagePortMessageFilter* message_port_message_filter =
3623 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3624 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093625 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3626 params.message_port_ids,
3627 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533628 }
3629
[email protected]f546640b2012-05-15 00:03:493630 // If there is a source_routing_id, translate it to the routing ID for
3631 // the equivalent swapped out RVH in the target process. If we need
3632 // to create a swapped out RVH for the source tab, we create its opener
3633 // chain as well, since those will also be accessible to the target page.
3634 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3635 // Try to look up the WebContents for the source page.
3636 WebContentsImpl* source_contents = NULL;
3637 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3638 rvh->GetProcess()->GetID(), params.source_routing_id);
3639 if (source_rvh) {
3640 source_contents = static_cast<WebContentsImpl*>(
3641 source_rvh->GetDelegate()->GetAsWebContents());
3642 }
3643
3644 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363645 if (GetBrowserPluginGuest()) {
3646 // We create a swapped out RenderView for the embedder in the guest's
3647 // render process but we intentionally do not expose the embedder's
3648 // opener chain to it.
3649 new_params.source_routing_id =
3650 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3651 } else {
3652 new_params.source_routing_id =
3653 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3654 }
[email protected]f546640b2012-05-15 00:03:493655 } else {
3656 // We couldn't find it, so don't pass a source frame.
3657 new_params.source_routing_id = MSG_ROUTING_NONE;
3658 }
3659 }
3660
3661 // In most cases, we receive this from a swapped out RenderViewHost.
3662 // It is possible to receive it from one that has just been swapped in,
3663 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183664 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493665}
3666
[email protected]a796f202012-05-30 14:14:253667bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263668 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253669 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263670 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253671 if (!delegate_)
3672 return false;
3673 return delegate_->AddMessageToConsole(this, level, message, line_no,
3674 source_id);
3675}
3676
[email protected]b172aee2012-04-10 17:05:263677WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273678 // We want to base the page config off of the actual URL, rather than the
3679 // virtual URL.
3680 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3681 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003682 GURL url = controller_.GetActiveEntry()
3683 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153684
[email protected]fa944cb82013-11-15 17:51:213685 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323686}
3687
[email protected]0eba810b2012-10-18 03:19:363688int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213689 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413690 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3691 true, true);
[email protected]0eba810b2012-10-18 03:19:363692}
3693
[email protected]b172aee2012-04-10 17:05:263694void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273695 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253696 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223697
[email protected]ea114722012-03-12 01:11:253698 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173699 if (rdh) // NULL in unittests.
3700 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253701}
3702
[email protected]b172aee2012-04-10 17:05:263703void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443704 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253705 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443706}
3707
[email protected]b172aee2012-04-10 17:05:263708void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563709 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263710 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153711 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523712 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153713 return;
3714
[email protected]9f76c1e2012-03-05 15:15:583715 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3716
[email protected]e5fc1632011-08-08 07:51:533717 // Ignore renderer unresponsive event if debugger is attached to the tab
3718 // since the event may be a result of the renderer sitting on a breakpoint.
3719 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363720 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533721 return;
3722
[email protected]2e9d79f2013-08-16 05:45:563723 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323724 // Hang occurred while firing the beforeunload/unload handler.
3725 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583726 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323727
[email protected]fa944cb82013-11-15 17:51:213728 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323729 return;
3730
3731 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563732 // nothing we can do to recover. If the hang is in the beforeunload handler,
3733 // pretend the beforeunload listeners have all fired and allow the delegate
3734 // to continue closing; the user will not have the option of cancelling the
3735 // close. Otherwise, pretend the unload listeners have all fired and close
3736 // the tab.
3737 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463738 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563739 delegate_->BeforeUnloadFired(this, true, &close);
3740 }
3741 if (close)
3742 Close(rvh);
[email protected]420ae012009-04-24 05:16:323743 return;
3744 }
3745
[email protected]9f76c1e2012-03-05 15:15:583746 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473747 return;
3748
[email protected]6934a702011-12-20 00:04:513749 if (delegate_)
3750 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323751}
3752
[email protected]b172aee2012-04-10 17:05:263753void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513754 if (delegate_)
3755 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323756}
3757
[email protected]b172aee2012-04-10 17:05:263758void WebContentsImpl::LoadStateChanged(
3759 const GURL& url,
3760 const net::LoadStateWithParam& load_state,
3761 uint64 upload_position,
3762 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323763 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563764 upload_position_ = upload_position;
3765 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503766 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213767 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303768 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213769 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323770 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463771 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213772 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463773 }
[email protected]420ae012009-04-24 05:16:323774}
3775
[email protected]b172aee2012-04-10 17:05:263776void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553777 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323778 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123779 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3780 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513781 if (delegate_)
3782 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093783 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323784}
3785
[email protected]58d5cfe2013-07-10 02:40:523786void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543787 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233788 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223789 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543790}
3791
[email protected]b172aee2012-04-10 17:05:263792void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103793 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213794 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263795 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3796 // here during container initialization and normal window size will be set
3797 // later. In case of tab duplication this resizing to 0x0 prevents setting
3798 // normal size later so just ignore it.
3799 if (!size.IsEmpty())
3800 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323801}
3802
[email protected]af905902013-10-01 21:38:513803void WebContentsImpl::CancelModalDialogsForRenderManager() {
3804 // We need to cancel modal dialogs when doing a process swap, since the load
3805 // deferrer would prevent us from swapping out.
3806 if (dialog_manager_)
3807 dialog_manager_->CancelActiveAndPendingDialogs(this);
3808}
3809
[email protected]7b712ee22013-10-03 00:57:283810void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3811 RenderViewHost* new_host) {
3812 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083813
3814 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003815 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313816 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393817
[email protected]7b712ee22013-10-03 00:57:283818 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543819}
3820
[email protected]14392a52012-05-02 20:28:443821int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3822 SiteInstance* instance) {
3823 if (!opener_)
3824 return MSG_ROUTING_NONE;
3825
3826 // Recursively create RenderViews for anything else in the opener chain.
3827 return opener_->CreateOpenerRenderViews(instance);
3828}
3829
3830int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3831 int opener_route_id = MSG_ROUTING_NONE;
3832
3833 // If this tab has an opener, ensure it has a RenderView in the given
3834 // SiteInstance as well.
3835 if (opener_)
3836 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3837
[email protected]45a22ad2013-02-21 03:25:003838 // If any of the renderers (current, pending, or swapped out) for this
3839 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213840 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3841 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373842
[email protected]fa944cb82013-11-15 17:51:213843 if (GetRenderManager()->pending_render_view_host() &&
3844 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3845 instance)
3846 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003847
[email protected]fa944cb82013-11-15 17:51:213848 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373849 instance);
3850 if (rvh)
3851 return rvh->GetRoutingID();
3852
[email protected]14392a52012-05-02 20:28:443853 // Create a swapped out RenderView in the given SiteInstance if none exists,
3854 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413855 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3856 true, true);
[email protected]14392a52012-05-02 20:28:443857}
3858
[email protected]b172aee2012-04-10 17:05:263859NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193860 return GetController();
[email protected]3a3d47472010-07-15 21:03:543861}
3862
[email protected]b172aee2012-04-10 17:05:263863WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563864 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323865}
3866
[email protected]10f417c52011-12-28 21:04:233867NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263868 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323869 return controller_.GetLastCommittedEntry();
3870}
3871
[email protected]b172aee2012-04-10 17:05:263872bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163873 RenderViewHost* render_view_host,
3874 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043875 int proxy_routing_id,
[email protected]6ab9d682014-05-22 03:48:593876 bool for_main_frame) {
[email protected]e11f0e92013-06-12 15:12:033877 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443878 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483879 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163880 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3881 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3882 // case this because RWH is still a base class of RenderViewHost, and child
3883 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]6ab9d682014-05-22 03:48:593884 if (!for_main_frame) {
[email protected]bffc8302014-01-23 20:52:163885 RenderWidgetHostViewChildFrame* rwh_view_child =
3886 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:163887 rwh_view = rwh_view_child;
3888 } else {
3889 rwh_view = view_->CreateViewForWidget(render_view_host);
3890 }
[email protected]1a98a932009-11-17 00:12:523891
[email protected]420ae012009-04-24 05:16:323892 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443893 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213894 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323895
[email protected]74ce1ad2011-12-16 21:51:463896 // Make sure we use the correct starting page_id in the new RenderView.
3897 UpdateMaxPageIDIfNecessary(render_view_host);
3898 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583899 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463900
[email protected]9f76c1e2012-03-05 15:15:583901 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263902 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493903 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043904 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:493905 max_page_id,
3906 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523907 return false;
[email protected]14392a52012-05-02 20:28:443908 }
[email protected]a4127722011-04-27 23:13:523909
[email protected]a220b5932013-09-21 03:47:443910#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503911 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3912 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443913 if (rwh_view) {
3914 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3915 render_widget_host->WasResized();
3916 }
[email protected]f8233cc2011-05-31 20:24:503917#endif
3918
[email protected]420ae012009-04-24 05:16:323919 return true;
3920}
3921
[email protected]7d244f12013-08-22 21:41:513922#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453923
[email protected]155c7f22013-12-09 17:07:183924base::android::ScopedJavaLocalRef<jobject>
3925WebContentsImpl::GetJavaWebContents() {
3926 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3927
3928 WebContentsAndroid* web_contents_android =
3929 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3930 if (!web_contents_android) {
3931 web_contents_android = new WebContentsAndroid(this);
3932 SetUserData(kWebContentsAndroidKey, web_contents_android);
3933 }
3934 return web_contents_android->GetJavaObject();
3935}
3936
[email protected]7d244f12013-08-22 21:41:513937bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3938 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163939 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:043940 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:593941 true);
[email protected]7d244f12013-08-22 21:41:513942}
[email protected]fc2b46b2014-05-03 16:33:453943
3944#elif defined(OS_MACOSX)
3945
3946void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
3947 view_->SetAllowOverlappingViews(overlapping);
3948}
3949
3950bool WebContentsImpl::GetAllowOverlappingViews() {
3951 return view_->GetAllowOverlappingViews();
3952}
3953
3954void WebContentsImpl::SetOverlayView(WebContents* overlay,
3955 const gfx::Point& offset) {
3956 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
3957 offset);
3958}
3959
3960void WebContentsImpl::RemoveOverlayView() {
3961 view_->RemoveOverlayView();
3962}
3963
[email protected]7d244f12013-08-22 21:41:513964#endif
3965
[email protected]6fba26d2014-04-29 09:38:283966void WebContentsImpl::OnDialogClosed(int render_process_id,
3967 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:263968 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493969 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263970 bool success,
[email protected]fcf75d42013-12-03 20:11:263971 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:283972 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3973 render_frame_id);
[email protected]87de04b02014-04-08 22:14:493974 last_dialog_suppressed_ = dialog_was_suppressed;
3975
[email protected]beb440c2009-11-06 04:08:543976 if (is_showing_before_unload_dialog_ && !success) {
3977 // If a beforeunload dialog is canceled, we need to stop the throbber from
3978 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:283979 if (rfh)
3980 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353981 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103982
[email protected]6d65a462013-06-21 21:29:123983 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3984 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543985 }
[email protected]87de04b02014-04-08 22:14:493986
[email protected]beb440c2009-11-06 04:08:543987 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:283988 if (rfh) {
3989 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3990 dialog_was_suppressed);
3991 } else {
3992 // Don't leak the sync IPC reply if the RFH or process is gone.
3993 delete reply_msg;
3994 }
[email protected]beb440c2009-11-06 04:08:543995}
3996
[email protected]b172aee2012-04-10 17:05:263997void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:543998 if (encoding == last_reported_encoding_)
3999 return;
4000 last_reported_encoding_ = encoding;
4001
4002 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124003 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104004}
[email protected]f45d2a72010-03-08 23:28:354005
[email protected]b172aee2012-04-10 17:05:264006void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:484007 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:444008 // Can be NULL during tests.
4009 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:454010 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:364011}
[email protected]9f76c1e2012-03-05 15:15:584012
[email protected]1ac10dca2013-08-20 20:47:044013bool WebContentsImpl::IsHidden() {
4014 return capturer_count_ == 0 && !should_normally_be_visible_;
4015}
4016
[email protected]b0936d22013-11-28 06:47:364017RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214018 return frame_tree_.root()->render_manager();
4019}
4020
[email protected]b172aee2012-04-10 17:05:264021RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584022 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4023}
[email protected]7900bfdb2012-05-24 19:31:244024
[email protected]f8497342013-02-05 22:15:024025BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394026 return browser_plugin_guest_.get();
4027}
4028
[email protected]738f57a2013-06-29 21:06:544029void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4030 CHECK(!browser_plugin_guest_);
4031 browser_plugin_guest_.reset(guest);
4032}
4033
[email protected]f8497342013-02-05 22:15:024034BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394035 return browser_plugin_embedder_.get();
4036}
[email protected]8ff00d72012-10-23 19:12:214037
[email protected]d9030b82013-07-19 08:26:064038void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194039 RenderFrameHost* render_frame_host) {
4040 STLDeleteValues(&power_save_blockers_[render_frame_host]);
4041 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:064042}
4043
4044void WebContentsImpl::ClearAllPowerSaveBlockers() {
4045 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
4046 i != power_save_blockers_.end(); ++i)
4047 STLDeleteValues(&power_save_blockers_[i->first]);
4048 power_save_blockers_.clear();
4049}
4050
[email protected]fc2b46b2014-05-03 16:33:454051gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214052 gfx::Size size;
4053 if (delegate_)
4054 size = delegate_->GetSizeForNewRenderView(this);
4055 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454056 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214057 return size;
4058}
4059
[email protected]9b159a52013-10-03 17:24:554060void WebContentsImpl::OnFrameRemoved(
4061 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:584062 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:554063 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:584064 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:554065}
4066
[email protected]222f5822014-02-05 23:40:494067void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4068 if (!delegate_)
4069 return;
4070 const gfx::Size new_size = GetPreferredSize();
4071 if (new_size != old_size)
4072 delegate_->UpdatePreferredSize(this, new_size);
4073}
4074
[email protected]8ff00d72012-10-23 19:12:214075} // namespace content