blob: 763ede9079df8bde856a6de08306d3dca64ca968 [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]8eb04562013-03-06 03:41:1423#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
[email protected]b9535422012-02-09 01:47:5924#include "content/browser/child_process_security_policy_impl.h"
[email protected]49413ca52014-03-05 14:13:4325#include "content/browser/devtools/render_view_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4126#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0427#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4628#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1229#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1630#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1631#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4032#include "content/browser/frame_host/interstitial_page_impl.h"
33#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0134#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1835#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1636#include "content/browser/frame_host/render_widget_host_view_child_frame.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]b3c41c0b2012-03-06 15:48:3243#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5044#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]b6583592012-01-25 19:52:3345#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1146#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5847#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0348#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5649#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1450#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4251#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4452#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0253#include "content/common/image_messages.h"
[email protected]35be7ec2012-02-12 20:42:5154#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0255#include "content/common/view_messages.h"
[email protected]5a3bdf52012-05-24 15:12:5756#include "content/port/browser/render_view_host_delegate_view.h"
[email protected]5626b0892012-02-20 14:46:5857#include "content/port/browser/render_widget_host_view_port.h"
[email protected]ccb797302011-12-15 16:55:1158#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2059#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4460#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3661#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1762#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1463#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4664#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1565#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0066#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2767#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0068#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3769#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1470#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3271#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3472#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3873#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4274#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2575#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1076#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2177#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4878#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5479#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4980#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2081#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0382#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5783#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1684#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2985#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5386#include "net/http/http_cache.h"
87#include "net/http/http_transaction_factory.h"
88#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3489#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5690#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0191#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4192#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5293#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1894#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3195
[email protected]583418cc2013-01-17 14:01:1096#if defined(OS_ANDROID)
97#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3298#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]155c7f22013-12-09 17:07:1899#include "content/browser/web_contents/web_contents_android.h"
[email protected]a794f3a2013-10-30 17:00:32100#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:00101#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10102#endif
103
[email protected]f66df822012-05-18 16:52:17104#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50105#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27106#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57107#endif
[email protected]3e45ba92009-02-20 21:09:00108
[email protected]420ae012009-04-24 05:16:32109// Cross-Site Navigations
110//
[email protected]b172aee2012-04-10 17:05:26111// If a WebContentsImpl is told to navigate to a different web site (as
112// determined by SiteInstance), it will replace its current RenderViewHost with
113// a new RenderViewHost dedicated to the new SiteInstance. This works as
114// follows:
[email protected]420ae012009-04-24 05:16:32115//
[email protected]fc6c1872013-10-03 01:22:35116// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46117// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32118// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35119// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32120// run in the current RVH.
121// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35122// that it has a pending cross-site request. We will check this on the IO
123// thread when deciding how to handle the response.
124// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46125// cancel all the pending logic. Otherwise we allow the pending RVH to send
126// the navigation request to its renderer.
127// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35128// main resource load on the pending RVH. It creates a
129// CrossSiteResourceHandler to check whether a process swap is needed when
130// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46131// - When RDH receives a response, the BufferedResourceHandler determines
132// whether it is a download. If so, it sends a message to the new renderer
133// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26134// pending RVH remains until the next DidNavigate event for this
135// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32136// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35137// download, the CrossSiteResourceHandler checks whether a process swap is
138// needed (either because CrossSiteRequestManager has state for it or because
139// a transfer was needed for a redirect).
140// - If so, CrossSiteResourceHandler pauses the response to first run the old
141// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36142// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
143// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35144// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
145// to a new process is needed, based on the stored pending_nav_params_. (This
146// is independent of whether we started out with a cross-process navigation.)
147// - If not, it just tells the ResourceDispatcherHost to resume the response
148// to its current RenderViewHost.
149// - If so, it cancels the current pending RenderViewHost and sets up a new
150// navigation using RequestTransferURL. When the transferred request
151// arrives in the ResourceDispatcherHost, we transfer the response and
152// resume it.
[email protected]420ae012009-04-24 05:16:32153// - The pending renderer sends a FrameNavigate message that invokes the
154// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46155// pending RVH.
[email protected]b0936d22013-11-28 06:47:36156// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15157// the user goes back. The process only stays live if another tab is using
158// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32159
[email protected]8ff00d72012-10-23 19:12:21160namespace content {
[email protected]420ae012009-04-24 05:16:32161namespace {
162
[email protected]82114f52012-03-20 22:53:41163const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05164
[email protected]155c7f22013-12-09 17:07:18165#if defined(OS_ANDROID)
166const char kWebContentsAndroidKey[] = "web_contents_android";
167#endif // OS_ANDROID
168
[email protected]e4abd3b42013-11-12 18:28:47169base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46170g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
171
[email protected]795c28972012-12-06 06:13:39172static int StartDownload(content::RenderViewHost* rvh,
173 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29174 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30175 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02176 static int g_next_image_download_id = 0;
177 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
178 ++g_next_image_download_id,
179 url,
180 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30181 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02182 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39183}
184
[email protected]8bfc8272013-09-09 20:10:53185void NotifyCacheOnIO(
186 scoped_refptr<net::URLRequestContextGetter> request_context,
187 const GURL& url,
188 const std::string& http_method) {
189 request_context->GetURLRequestContext()->http_transaction_factory()->
190 GetCache()->OnExternalCacheHit(url, http_method);
191}
192
[email protected]9b159a52013-10-03 17:24:55193// Helper function for retrieving all the sites in a frame tree.
194bool CollectSites(BrowserContext* context,
195 std::set<GURL>* sites,
196 FrameTreeNode* node) {
197 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
198 return true;
199}
200
[email protected]a86c0e962013-12-17 17:10:39201bool ForEachFrameInternal(
202 const base::Callback<void(RenderFrameHost*)>& on_frame,
203 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41204 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39205 return true;
206}
207
[email protected]c06c58c2014-03-12 20:31:59208bool ForEachPendingFrameInternal(
209 const base::Callback<void(RenderFrameHost*)>& on_frame,
210 FrameTreeNode* node) {
211 RenderFrameHost* pending_frame_host =
212 node->render_manager()->pending_frame_host();
213 if (pending_frame_host)
214 on_frame.Run(pending_frame_host);
215 return true;
216}
217
[email protected]a86c0e962013-12-17 17:10:39218void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
219 IPC::Message* message_copy = new IPC::Message(*message);
220 message_copy->set_routing_id(rfh->GetRoutingID());
221 rfh->Send(message_copy);
222}
223
[email protected]c06c58c2014-03-12 20:31:59224void RunRenderFrameDeleted(
225 ObserverList<WebContentsObserver>* observer_list,
226 RenderFrameHost* render_frame_host) {
227 FOR_EACH_OBSERVER(WebContentsObserver,
228 *observer_list,
229 RenderFrameDeleted(render_frame_host));
230}
231
[email protected]420ae012009-04-24 05:16:32232} // namespace
233
[email protected]54944cde2012-12-09 09:24:59234WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15235 return WebContentsImpl::CreateWithOpener(
236 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19237}
238
239WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59240 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30241 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59242 WebContentsImpl* new_contents = new WebContentsImpl(
243 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30244
245 for (SessionStorageNamespaceMap::const_iterator it =
246 session_storage_namespace_map.begin();
247 it != session_storage_namespace_map.end();
248 ++it) {
249 new_contents->GetController()
250 .SetSessionStorageNamespace(it->first, it->second.get());
251 }
252
[email protected]54944cde2012-12-09 09:24:59253 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19254 return new_contents;
[email protected]a81343d232011-12-27 07:39:20255}
[email protected]746d3052012-05-22 15:15:47256
[email protected]e4abd3b42013-11-12 18:28:47257void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46258 g_created_callbacks.Get().push_back(callback);
259}
260
[email protected]e4abd3b42013-11-12 18:28:47261void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46262 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
263 if (g_created_callbacks.Get().at(i).Equals(callback)) {
264 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
265 return;
266 }
267 }
268}
269
[email protected]299d7f12012-05-23 05:31:15270WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47271 return rvh->GetDelegate()->GetAsWebContents();
272}
273
[email protected]a86c0e962013-12-17 17:10:39274WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
275 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
276 if (!rfh_impl)
277 return NULL;
278 return rfh_impl->delegate()->GetAsWebContents();
279}
280
[email protected]7fff43e2013-05-21 20:21:10281// WebContentsImpl::DestructionObserver ----------------------------------------
282
283class WebContentsImpl::DestructionObserver : public WebContentsObserver {
284 public:
285 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
286 : WebContentsObserver(watched_contents),
287 owner_(owner) {
288 }
289
290 // WebContentsObserver:
291 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
292 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
293 }
294
295 private:
296 WebContentsImpl* owner_;
297
298 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
299};
300
[email protected]b172aee2012-04-10 17:05:26301// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32302
[email protected]b172aee2012-04-10 17:05:26303WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21304 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19305 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42306 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22307 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57308 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44309 opener_(opener),
[email protected]2ceee8f2014-01-14 18:02:08310#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41311 accessible_parent_(NULL),
312#endif
[email protected]6ea6bdf2013-12-06 13:35:01313 frame_tree_(new NavigatorImpl(&controller_, this),
314 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34315 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23316 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
317 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34318 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26319 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56320 upload_size_(0),
321 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47322 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55323 capturer_count_(0),
324 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57325 is_being_destroyed_(false),
326 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15327 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01328 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02329 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38330 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21331 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
332 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00333 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21334 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44335 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42336 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
337 is_subframe_(false) {
[email protected]cbb1ef592013-06-05 19:49:46338 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
339 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55340 frame_tree_.SetFrameRemoveListener(
341 base::Bind(&WebContentsImpl::OnFrameRemoved,
342 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35343}
initial.commit09911bf2008-07-26 23:55:29344
[email protected]b172aee2012-04-10 17:05:26345WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32346 is_being_destroyed_ = true;
347
[email protected]21b41c7e892014-02-28 01:52:24348 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
349 // shutdown and be deleted as well.
350 frame_tree_.ForEach(
351 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
352
[email protected]d9030b82013-07-19 08:26:06353 ClearAllPowerSaveBlockers();
354
[email protected]b24b68a2012-09-24 21:57:26355 for (std::set<RenderWidgetHostImpl*>::iterator iter =
356 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
357 (*iter)->DetachDelegate();
358 }
359 created_widgets_.clear();
360
[email protected]3ab9cb82011-06-03 18:02:07361 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15362 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11363 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07364
[email protected]da8543762012-03-20 08:52:20365 if (color_chooser_)
366 color_chooser_->End();
367
[email protected]420ae012009-04-24 05:16:32368 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32369
[email protected]ca13a442012-04-17 14:00:12370 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21371 NotificationService::current()->Notify(
372 NOTIFICATION_WEB_CONTENTS_DESTROYED,
373 Source<WebContents>(this),
374 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32375
[email protected]c06c58c2014-03-12 20:31:59376 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
377 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
378 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
379 run_render_frame_deleted_callback));
380
[email protected]fa944cb82013-11-15 17:51:21381 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27382 if (pending_rvh) {
383 FOR_EACH_OBSERVER(WebContentsObserver,
384 observers_,
385 RenderViewDeleted(pending_rvh));
386 }
387
[email protected]c06c58c2014-03-12 20:31:59388 ForEachFrame(run_render_frame_deleted_callback);
389
[email protected]f273ee52013-10-18 16:05:27390 FOR_EACH_OBSERVER(WebContentsObserver,
391 observers_,
[email protected]fa944cb82013-11-15 17:51:21392 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27393
[email protected]2db9bd72012-04-13 20:20:56394 FOR_EACH_OBSERVER(WebContentsObserver,
395 observers_,
396 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08397
[email protected]6934a702011-12-20 00:04:51398 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10399
400 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
401 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42402}
403
[email protected]d1198fd2012-08-13 22:50:19404WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59405 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19406 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03407 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59408 WebContentsImpl* new_contents = new WebContentsImpl(
409 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19410
[email protected]54944cde2012-12-09 09:24:59411 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19412 return new_contents;
413}
414
[email protected]b371a5652013-02-20 11:25:51415// static
[email protected]8eb04562013-03-06 03:41:14416BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36417 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53418 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54419 int guest_instance_id,
420 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39421 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39422
423 // This makes |new_contents| act as a guest.
424 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54425 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19426 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11427
[email protected]3de10bb32013-01-08 21:57:33428 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33429 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11430
[email protected]216be772013-01-25 00:22:27431 // We are instantiating a WebContents for browser plugin. Set its subframe bit
432 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42433 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27434
[email protected]8eb04562013-03-06 03:41:14435 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39436}
437
[email protected]b0936d22013-11-28 06:47:36438RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21439 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28440}
441
[email protected]7bb761892012-07-20 09:32:47442bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
443 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44444 return OnMessageReceived(render_view_host, NULL, message);
445}
446
447bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
448 RenderFrameHost* render_frame_host,
449 const IPC::Message& message) {
450 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56451 if (GetWebUI() &&
452 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17453 return true;
[email protected]d2353452012-01-19 19:53:56454 }
[email protected]f82d57b52011-04-27 19:13:17455
[email protected]d8c660432011-12-22 20:51:25456 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
457 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10458 while ((observer = it.GetNext()) != NULL)
459 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53460 return true;
[email protected]403415a2011-01-10 18:57:53461
[email protected]1d62cf72014-02-07 21:31:57462 // Message handlers should be aware of which
463 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
464 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43465 if (render_frame_host) {
466 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
467 render_frame_host->GetRenderViewHost(), message))
468 return true;
[email protected]1d62cf72014-02-07 21:31:57469 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43470 } else {
471 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
472 render_view_host, message))
473 return true;
[email protected]1d62cf72014-02-07 21:31:57474 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43475 }
[email protected]1d62cf72014-02-07 21:31:57476
[email protected]724159a2010-12-30 01:11:18477 bool handled = true;
478 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26479 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44480 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
481 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40482 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
483 OnDomOperationResponse)
[email protected]724159a2010-12-30 01:11:18484 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
485 OnDidLoadResourceFromMemoryCache)
486 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
487 OnDidDisplayInsecureContent)
488 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
489 OnDidRunInsecureContent)
[email protected]1d62cf72014-02-07 21:31:57490 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
[email protected]724159a2010-12-30 01:11:18491 OnDocumentLoadedInFrame)
[email protected]028053d42014-03-05 22:20:37492 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]7d472472011-01-22 01:30:25493 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26494 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21495 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20496 IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory)
497 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
498 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16499 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10500 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]da8543762012-03-20 08:52:20501 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser)
502 IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser)
503 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser,
504 OnSetSelectedColorInColorChooser)
[email protected]d0759f492012-04-19 22:50:50505 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50506 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
507 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55508 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
509 OnBrowserPluginMessage(message))
510 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
511 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02512 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
513 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]583418cc2013-01-17 14:01:10514#if defined(OS_ANDROID)
515 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
516 OnFindMatchRectsReply)
517 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
518 OnOpenDateTimeDialog)
[email protected]a794f3a2013-10-30 17:00:32519 IPC_MESSAGE_HANDLER_DELAY_REPLY(JavaBridgeHostMsg_GetChannelHandle,
520 OnJavaBridgeGetChannelHandle)
[email protected]583418cc2013-01-17 14:01:10521#endif
[email protected]1dd0bb752014-02-01 01:16:26522 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPlayingNotification,
523 OnMediaPlayingNotification)
524 IPC_MESSAGE_HANDLER(ViewHostMsg_MediaPausedNotification,
525 OnMediaPausedNotification)
[email protected]9f268072013-11-07 00:02:15526 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
527 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07528 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
529 OnShowValidationMessage)
530 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
531 OnHideValidationMessage)
532 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
533 OnMoveValidationMessage)
[email protected]724159a2010-12-30 01:11:18534 IPC_MESSAGE_UNHANDLED(handled = false)
535 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44536 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57537 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18538
539 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39540 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18541 GetRenderProcessHost()->ReceivedBadMessage();
542 }
543
544 return handled;
545}
546
[email protected]b172aee2012-04-10 17:05:26547void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18548 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21549 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43550 if (delegate_)
551 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18552}
553
[email protected]d1198fd2012-08-13 22:50:19554NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56555 return controller_;
556}
557
[email protected]d1198fd2012-08-13 22:50:19558const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56559 return controller_;
560}
561
[email protected]8ff00d72012-10-23 19:12:21562BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55563 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30564}
565
[email protected]b172aee2012-04-10 17:05:26566const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24567 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32568 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51569 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31570}
571
[email protected]a093ce02013-07-22 20:53:14572const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24573 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32574 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24575 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
576}
577
578const GURL& WebContentsImpl::GetLastCommittedURL() const {
579 // We may not have a navigation entry yet.
580 NavigationEntry* entry = controller_.GetLastCommittedEntry();
581 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
582}
583
[email protected]8ff00d72012-10-23 19:12:21584WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31585 return delegate_;
586}
587
[email protected]8ff00d72012-10-23 19:12:21588void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31589 // TODO(cbentzel): remove this debugging code?
590 if (delegate == delegate_)
591 return;
592 if (delegate_)
593 delegate_->Detach(this);
594 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08595 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31596 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08597 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00598 if (view_)
599 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08600 }
[email protected]be1f56ab2011-12-22 06:55:31601}
602
[email protected]8ff00d72012-10-23 19:12:21603RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21604 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41605 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16606}
607
[email protected]60eca4eb2013-12-06 00:02:16608RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41609 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16610}
611
[email protected]9c9343b2014-03-08 02:56:07612RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
613 if (!frame_tree_.GetFocusedFrame())
614 return NULL;
615 return frame_tree_.GetFocusedFrame()->current_frame_host();
616}
617
[email protected]a86c0e962013-12-17 17:10:39618void WebContentsImpl::ForEachFrame(
619 const base::Callback<void(RenderFrameHost*)>& on_frame) {
620 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
621}
622
623void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
624 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
625 delete message;
626}
627
[email protected]b172aee2012-04-10 17:05:26628RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21629 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31630}
631
[email protected]bfcfa692013-02-07 06:17:02632WebContents* WebContentsImpl::GetEmbedderWebContents() const {
633 BrowserPluginGuest* guest = GetBrowserPluginGuest();
634 if (guest)
635 return guest->embedder_web_contents();
636 return NULL;
637}
638
639int WebContentsImpl::GetEmbeddedInstanceID() const {
640 BrowserPluginGuest* guest = GetBrowserPluginGuest();
641 if (guest)
642 return guest->instance_id();
643 return 0;
644}
645
[email protected]6b618e62012-08-16 12:59:18646int WebContentsImpl::GetRoutingID() const {
647 if (!GetRenderViewHost())
648 return MSG_ROUTING_NONE;
649
650 return GetRenderViewHost()->GetRoutingID();
651}
652
[email protected]44470a22013-01-24 01:21:54653int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
654 return fullscreen_widget_routing_id_;
655}
656
[email protected]b172aee2012-04-10 17:05:26657RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21658 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31659}
660
[email protected]f8497342013-02-05 22:15:02661RenderWidgetHostViewPort* WebContentsImpl::GetRenderWidgetHostViewPort() const {
662 BrowserPluginGuest* guest = GetBrowserPluginGuest();
663 if (guest && guest->embedder_web_contents()) {
664 return guest->embedder_web_contents()->GetRenderWidgetHostViewPort();
665 }
666 return RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
667}
668
[email protected]4aebbca2013-09-17 22:26:49669RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
670 const {
671 RenderWidgetHost* const widget_host =
672 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
673 GetFullscreenWidgetRoutingID());
674 return widget_host ? widget_host->GetView() : NULL;
675}
676
[email protected]8ff00d72012-10-23 19:12:21677WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31678 return view_.get();
679}
680
[email protected]8ff00d72012-10-23 19:12:21681WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56682 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03683 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
684 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22685 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58686 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22687 web_ui->SetController(controller);
688 return web_ui;
689 }
690
691 delete web_ui;
692 return NULL;
693}
694
[email protected]8ff00d72012-10-23 19:12:21695WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21696 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
697 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31698}
699
[email protected]8ff00d72012-10-23 19:12:21700WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21701 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34702}
703
[email protected]86ef6a392012-05-11 22:03:11704void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22705 if (GetUserAgentOverride() == override)
706 return;
707
708 renderer_preferences_.user_agent_override = override;
709
710 // Send the new override string to the renderer.
711 RenderViewHost* host = GetRenderViewHost();
712 if (host)
713 host->SyncRendererPrefs();
714
715 // Reload the page if a load is currently in progress to avoid having
716 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27717 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22718 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
719 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53720
721 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
722 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11723}
724
725const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22726 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11727}
728
[email protected]2ceee8f2014-01-14 18:02:08729#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41730void WebContentsImpl::SetParentNativeViewAccessible(
731gfx::NativeViewAccessible accessible_parent) {
732 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45733 if (GetRenderViewHost())
734 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41735}
736#endif
737
[email protected]fcf75d42013-12-03 20:11:26738const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55739 // Transient entries take precedence. They are used for interstitial pages
740 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23741 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08742 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21743 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30744 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23745 if (entry) {
[email protected]b5cca982011-05-26 04:42:08746 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23747 }
[email protected]fa944cb82013-11-15 17:51:21748 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
749 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58750 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54751 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32752 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54753 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35754 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26755 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54756 if (!title.empty())
757 return title;
758 }
759 }
760
761 // We use the title for the last committed entry rather than a pending
762 // navigation entry. For example, when the user types in a URL, we want to
763 // keep the old page's title until the new load has committed and we get a new
764 // title.
[email protected]96d185d2009-04-24 03:28:54765 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32766
[email protected]9eeafc012013-11-25 23:49:47767 // We make an exception for initial navigations.
768 if (controller_.IsInitialNavigation()) {
769 // We only want to use the title from the visible entry in one of two cases:
770 // 1. There's already a committed entry for an initial navigation, in which
771 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
772 // 2. The pending entry has been explicitly assigned a title to display.
773 //
774 // If there's no last committed entry and no assigned title, we should fall
775 // back to |page_title_when_no_navigation_entry_| rather than showing the
776 // URL.
777 if (entry ||
778 (controller_.GetVisibleEntry() &&
779 !controller_.GetVisibleEntry()->GetTitle().empty())) {
780 entry = controller_.GetVisibleEntry();
781 }
782 }
[email protected]59167c22013-06-03 18:07:32783
[email protected]45d0ef7f2011-01-05 13:46:23784 if (entry) {
[email protected]b5cca982011-05-26 04:42:08785 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23786 }
[email protected]987fc3a2011-05-26 14:18:09787
788 // |page_title_when_no_navigation_entry_| is finally used
789 // if no title cannot be retrieved.
790 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54791}
792
[email protected]b172aee2012-04-10 17:05:26793int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46794 return GetMaxPageIDForSiteInstance(GetSiteInstance());
795}
796
[email protected]b172aee2012-04-10 17:05:26797int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
798 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33799 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
800 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46801
[email protected]b6583592012-01-25 19:52:33802 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34803}
804
[email protected]b172aee2012-04-10 17:05:26805void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46806 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
807}
808
[email protected]b172aee2012-04-10 17:05:26809void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33810 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46811 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33812 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34813}
814
[email protected]ec6c05f2013-10-23 18:41:57815void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
816 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
817 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57818}
819
[email protected]b172aee2012-04-10 17:05:26820SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21821 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54822}
823
[email protected]b172aee2012-04-10 17:05:26824SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21825 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
826 GetRenderManager()->pending_render_view_host() :
827 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58828 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38829}
830
[email protected]b172aee2012-04-10 17:05:26831bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31832 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49833}
834
[email protected]b172aee2012-04-10 17:05:26835bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31836 return waiting_for_response_;
837}
838
[email protected]b172aee2012-04-10 17:05:26839const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31840 return load_state_;
841}
842
[email protected]fcf75d42013-12-03 20:11:26843const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31844 return load_state_host_;
845}
846
[email protected]b172aee2012-04-10 17:05:26847uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31848 return upload_size_;
849}
850
[email protected]b172aee2012-04-10 17:05:26851uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31852 return upload_position_;
853}
854
[email protected]1ae93fb2013-06-14 03:38:56855std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56856 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39857 frame_tree_.ForEach(base::Bind(&CollectSites,
858 base::Unretained(GetBrowserContext()),
859 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56860 return sites;
861}
862
[email protected]b172aee2012-04-10 17:05:26863const std::string& WebContentsImpl::GetEncoding() const {
[email protected]be1f56ab2011-12-22 06:55:31864 return encoding_;
865}
866
[email protected]b172aee2012-04-10 17:05:26867bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31868 return displayed_insecure_content_;
869}
870
[email protected]222f5822014-02-05 23:40:49871void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25872 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55873 ++capturer_count_;
874 DVLOG(1) << "There are now " << capturer_count_
875 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49876
877 // Note: This provides a hint to upstream code to size the views optimally
878 // for quality (e.g., to avoid scaling).
879 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
880 preferred_size_for_capture_ = capture_size;
881 OnPreferredSizeChanged(preferred_size_);
882 }
[email protected]54597982013-02-06 01:59:55883}
884
885void WebContentsImpl::DecrementCapturerCount() {
886 --capturer_count_;
887 DVLOG(1) << "There are now " << capturer_count_
888 << " capturing(s) of WebContentsImpl@" << this;
889 DCHECK_LE(0, capturer_count_);
890
[email protected]5a652232013-02-12 06:15:25891 if (is_being_destroyed_)
892 return;
893
[email protected]222f5822014-02-05 23:40:49894 if (capturer_count_ == 0) {
895 const gfx::Size old_size = preferred_size_for_capture_;
896 preferred_size_for_capture_ = gfx::Size();
897 OnPreferredSizeChanged(old_size);
898 }
899
[email protected]1ac10dca2013-08-20 20:47:04900 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55901 DVLOG(1) << "Executing delayed WasHidden().";
902 WasHidden();
903 }
[email protected]be1f56ab2011-12-22 06:55:31904}
905
[email protected]f2bd40812013-07-20 04:30:44906int WebContentsImpl::GetCapturerCount() const {
907 return capturer_count_;
908}
909
[email protected]b172aee2012-04-10 17:05:26910bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31911 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
912 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
913 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49914}
915
[email protected]b172aee2012-04-10 17:05:26916void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
917 int error_code) {
[email protected]443b80e2010-12-14 00:42:23918 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34919 return;
920
[email protected]443b80e2010-12-14 00:42:23921 crashed_status_ = status;
922 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21923 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34924}
925
[email protected]b172aee2012-04-10 17:05:26926base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31927 return crashed_status_;
928}
929
[email protected]b172aee2012-04-10 17:05:26930bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31931 return is_being_destroyed_;
932}
933
[email protected]b172aee2012-04-10 17:05:26934void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34935 if (delegate_)
936 delegate_->NavigationStateChanged(this, changed_flags);
937}
938
[email protected]9a890452014-02-13 22:21:02939base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
940 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33941}
942
[email protected]9e2e4632012-07-27 16:38:41943void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54944 controller_.SetActive(true);
[email protected]c30585c2012-02-16 15:02:04945 RenderWidgetHostViewPort* rwhv =
946 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16947 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29948 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43949#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16950 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43951#endif
952 }
[email protected]96d185d2009-04-24 03:28:54953
[email protected]9a890452014-02-13 22:21:02954 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38955
[email protected]b9769d82012-02-10 00:23:59956 // The resize rect might have changed while this was inactive -- send the new
957 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58958 RenderViewHostImpl* rvh =
959 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59960 if (rvh) {
961 rvh->ResizeRectChanged(GetRootWindowResizerRect());
962 }
[email protected]96d185d2009-04-24 03:28:54963
[email protected]c0d9d5672013-10-09 07:38:03964 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
965
[email protected]54597982013-02-06 01:59:55966 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31967}
968
[email protected]b172aee2012-04-10 17:05:26969void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55970 // If there are entities capturing screenshots or video (e.g., mirroring),
971 // don't activate the "disable rendering" optimization.
972 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52973 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55974 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26975 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52976 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33977 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52978 // calls us).
[email protected]c30585c2012-02-16 15:02:04979 RenderWidgetHostViewPort* rwhv =
980 RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView());
[email protected]8cb5d5b2010-02-09 11:36:16981 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29982 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54983 }
984
[email protected]c0d9d5672013-10-09 07:38:03985 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
986
[email protected]54597982013-02-06 01:59:55987 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37988}
989
[email protected]b172aee2012-04-10 17:05:26990bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31991 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27992 return WillNotifyDisconnection() &&
993 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58994 !static_cast<RenderViewHostImpl*>(
995 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:31996}
997
[email protected]b172aee2012-04-10 17:05:26998void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:21999 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401000 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271001}
1002
[email protected]b172aee2012-04-10 17:05:261003WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441004 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451005 // We pass our own opener so that the cloned page can access it if it was
1006 // before.
[email protected]54944cde2012-12-09 09:24:591007 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]ed245db2012-12-18 08:00:451008 create_params.initial_size = view_->GetContainerSize();
[email protected]54944cde2012-12-09 09:24:591009 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191010 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221011 FOR_EACH_OBSERVER(WebContentsObserver,
1012 observers_,
1013 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271014 return tc;
1015}
1016
[email protected]14392a52012-05-02 20:28:441017void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211018 const NotificationSource& source,
1019 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441020 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211021 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1022 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501023 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1024 i != pending_widget_views_.end(); ++i) {
1025 if (host->GetView() == i->second) {
1026 pending_widget_views_.erase(i);
1027 break;
1028 }
1029 }
1030 break;
1031 }
[email protected]14392a52012-05-02 20:28:441032 default:
1033 NOTREACHED();
1034 }
1035}
1036
[email protected]ec6c05f2013-10-23 18:41:571037WebContents* WebContentsImpl::GetWebContents() {
1038 return this;
1039}
1040
[email protected]54944cde2012-12-09 09:24:591041void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211042 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361043 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211044 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431045 should_normally_be_visible_ = !params.initially_hidden;
1046
[email protected]fa944cb82013-11-15 17:51:211047 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041048 params.browser_context, params.site_instance, params.routing_id,
1049 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191050
[email protected]8ff00d72012-10-23 19:12:211051 view_.reset(GetContentClient()->browser()->
[email protected]d1198fd2012-08-13 22:50:191052 OverrideCreateWebContentsView(this, &render_view_host_delegate_view_));
[email protected]59383c782013-04-17 16:43:271053 if (view_) {
[email protected]d1198fd2012-08-13 22:50:191054 CHECK(render_view_host_delegate_view_);
1055 } else {
[email protected]f8497342013-02-05 22:15:021056 WebContentsViewDelegate* delegate =
1057 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1058
[email protected]59383c782013-04-17 16:43:271059 if (browser_plugin_guest_) {
[email protected]6ac389a2013-07-09 01:32:381060 scoped_ptr<WebContentsViewPort> platform_view(CreateWebContentsView(
1061 this, delegate, &render_view_host_delegate_view_));
[email protected]f8497342013-02-05 22:15:021062
[email protected]b5a40842012-11-28 15:26:111063 WebContentsViewGuest* rv = new WebContentsViewGuest(
[email protected]6ac389a2013-07-09 01:32:381064 this, browser_plugin_guest_.get(), platform_view.Pass(),
[email protected]cb8d7cf22013-06-19 04:16:431065 render_view_host_delegate_view_);
[email protected]b5a40842012-11-28 15:26:111066 render_view_host_delegate_view_ = rv;
1067 view_.reset(rv);
1068 } else {
[email protected]f8497342013-02-05 22:15:021069 // Regular WebContentsView.
[email protected]b5a40842012-11-28 15:26:111070 view_.reset(CreateWebContentsView(
1071 this, delegate, &render_view_host_delegate_view_));
1072 }
[email protected]d1198fd2012-08-13 22:50:191073 CHECK(render_view_host_delegate_view_);
1074 }
1075 CHECK(view_.get());
1076
[email protected]ed245db2012-12-18 08:00:451077 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591078 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191079
1080 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101081 if (opener_)
1082 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191083
1084 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211085 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1086 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441087#if defined(OS_ANDROID)
[email protected]d1198fd2012-08-13 22:50:191088 java_bridge_dispatcher_host_manager_.reset(
1089 new JavaBridgeDispatcherHostManager(this));
[email protected]583418cc2013-01-17 14:01:101090 date_time_chooser_.reset(new DateTimeChooserAndroid());
1091#endif
[email protected]d1198fd2012-08-13 22:50:191092}
1093
[email protected]7fff43e2013-05-21 20:21:101094void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1095 RemoveDestructionObserver(web_contents);
1096
[email protected]14392a52012-05-02 20:28:441097 // Clear the opener if it has been closed.
1098 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441099 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511100 return;
[email protected]14392a52012-05-02 20:28:441101 }
[email protected]ceee8cd2013-03-08 04:59:511102 // Clear a pending contents that has been closed before being shown.
1103 for (PendingContents::iterator iter = pending_contents_.begin();
1104 iter != pending_contents_.end();
1105 ++iter) {
1106 if (iter->second != web_contents)
1107 continue;
1108 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511109 return;
1110 }
1111 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441112}
1113
[email protected]7fff43e2013-05-21 20:21:101114void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1115 if (!ContainsKey(destruction_observers_, web_contents)) {
1116 destruction_observers_[web_contents] =
1117 new DestructionObserver(this, web_contents);
1118 }
1119}
1120
1121void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1122 DestructionObservers::iterator iter =
1123 destruction_observers_.find(web_contents);
1124 if (iter != destruction_observers_.end()) {
1125 delete destruction_observers_[web_contents];
1126 destruction_observers_.erase(iter);
1127 }
1128}
1129
[email protected]b172aee2012-04-10 17:05:261130void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311131 observers_.AddObserver(observer);
1132}
1133
[email protected]b172aee2012-04-10 17:05:261134void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311135 observers_.RemoveObserver(observer);
1136}
1137
[email protected]b172aee2012-04-10 17:05:261138void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341139 if (delegate_)
1140 delegate_->ActivateContents(this);
1141}
1142
[email protected]b172aee2012-04-10 17:05:261143void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121144 if (delegate_)
1145 delegate_->DeactivateContents(this);
1146}
1147
[email protected]b172aee2012-04-10 17:05:261148void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481149 if (delegate_)
1150 delegate_->LostCapture();
1151}
1152
[email protected]b24b68a2012-09-24 21:57:261153void WebContentsImpl::RenderWidgetDeleted(
1154 RenderWidgetHostImpl* render_widget_host) {
1155 if (is_being_destroyed_) {
1156 // |created_widgets_| might have been destroyed.
1157 return;
1158 }
1159
1160 std::set<RenderWidgetHostImpl*>::iterator iter =
1161 created_widgets_.find(render_widget_host);
1162 if (iter != created_widgets_.end())
1163 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541164
1165 if (render_widget_host &&
1166 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491167 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1168 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541169 FOR_EACH_OBSERVER(WebContentsObserver,
1170 observers_,
1171 DidDestroyFullscreenWidget(
1172 fullscreen_widget_routing_id_));
1173 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1174 }
[email protected]b24b68a2012-09-24 21:57:261175}
1176
[email protected]b172aee2012-04-10 17:05:261177bool WebContentsImpl::PreHandleKeyboardEvent(
1178 const NativeWebKeyboardEvent& event,
1179 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481180 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131181 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481182}
1183
[email protected]b172aee2012-04-10 17:05:261184void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061185 if (browser_plugin_embedder_ &&
1186 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1187 return;
1188 }
1189
[email protected]63954792011-07-11 04:17:481190 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131191 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481192}
1193
[email protected]d92026ef2014-03-03 21:04:131194bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461195 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191196#if !defined(OS_MACOSX)
1197 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1198 // isn't done for two reasons:
1199 // -the OS already has a gesture to do this through pinch-zoom
1200 // -if a user starts an inertial scroll, let's go, and presses control
1201 // (i.e. control+tab) then the OS's buffered scroll events will come in
1202 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521203 if (delegate_ &&
1204 event.wheelTicksY &&
[email protected]180ef242013-11-07 06:50:461205 (event.modifiers & blink::WebInputEvent::ControlKey)) {
[email protected]fb3f066e2013-02-12 19:12:521206 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1207 return true;
1208 }
[email protected]bccc4472013-04-18 16:37:191209#endif
[email protected]fb3f066e2013-02-12 19:12:521210 return false;
1211}
1212
[email protected]04bce562014-01-30 05:34:541213bool WebContentsImpl::PreHandleGestureEvent(
1214 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031215 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541216}
1217
[email protected]2ceee8f2014-01-14 18:02:081218#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411219gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1220 return accessible_parent_;
1221}
1222#endif
1223
[email protected]b172aee2012-04-10 17:05:261224void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431225 if (delegate_)
1226 delegate_->HandleMouseDown();
1227}
1228
[email protected]b172aee2012-04-10 17:05:261229void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481230 if (delegate_)
1231 delegate_->HandleMouseUp();
1232}
1233
[email protected]590a634e2012-07-19 16:38:231234void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481235 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231236 delegate_->HandlePointerActivate();
1237}
1238
1239void WebContentsImpl::HandleGestureBegin() {
1240 if (delegate_)
1241 delegate_->HandleGestureBegin();
1242}
1243
1244void WebContentsImpl::HandleGestureEnd() {
1245 if (delegate_)
1246 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481247}
1248
[email protected]b172aee2012-04-10 17:05:261249void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491250 // This method is being called to enter or leave renderer-initiated fullscreen
1251 // mode. Either way, make sure any existing fullscreen widget is shut down
1252 // first.
1253 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1254 if (widget_view)
1255 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1256
[email protected]8a5e0ca2011-08-25 06:30:471257 if (delegate_)
1258 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
1259}
1260
[email protected]b172aee2012-04-10 17:05:261261bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381262 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121263}
1264
[email protected]a9c81f02012-06-01 00:15:441265void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1266 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371267 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441268 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371269 } else {
1270 GotResponseToLockMouseRequest(false);
1271 }
1272}
1273
[email protected]b172aee2012-04-10 17:05:261274void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371275 if (delegate_)
1276 delegate_->LostMouseLock();
1277}
1278
[email protected]bafe6cd2012-05-23 23:09:501279void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201280 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501281 int route_id,
[email protected]227692c52013-05-31 22:43:041282 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131283 const ViewHostMsg_CreateWindow_Params& params,
1284 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501285 // We usually create the new window in the same BrowsingInstance (group of
1286 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551287 // if the opener is being suppressed (in a non-guest), we create a new
1288 // SiteInstance in its own BrowsingInstance.
1289 bool is_guest = GetRenderProcessHost()->IsGuest();
1290
[email protected]04cbd3d2013-12-04 04:58:201291 // If the opener is to be suppressed, the new window can be in any process.
1292 // Since routing ids are process specific, we must not have one passed in
1293 // as argument here.
1294 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1295
[email protected]bafe6cd2012-05-23 23:09:501296 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551297 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571298 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501299 GetSiteInstance();
1300
[email protected]04cbd3d2013-12-04 04:58:201301 // A message to create a new window can only come from the active process for
1302 // this WebContentsImpl instance. If any other process sends the request,
1303 // it is invalid and the process must be terminated.
1304 if (GetRenderProcessHost()->GetID() != render_process_id) {
1305 base::ProcessHandle process_handle =
1306 RenderProcessHost::FromID(render_process_id)->GetHandle();
1307 if (process_handle != base::kNullProcessHandle) {
1308 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391309 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201310 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1311 }
1312 return;
1313 }
1314
[email protected]d1198fd2012-08-13 22:50:191315 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341316 //
1317 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301318 const std::string& partition_id =
1319 GetContentClient()->browser()->
1320 GetStoragePartitionIdForSite(GetBrowserContext(),
1321 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461322 StoragePartition* partition = BrowserContext::GetStoragePartition(
1323 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411324 DOMStorageContextWrapper* dom_storage_context =
1325 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191326 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1327 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1328 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371329
1330 if (delegate_ &&
1331 !delegate_->ShouldCreateWebContents(this,
1332 route_id,
1333 params.window_container_type,
1334 params.frame_name,
1335 params.target_url,
1336 partition_id,
1337 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011338 if (route_id != MSG_ROUTING_NONE &&
1339 !RenderViewHost::FromID(render_process_id, route_id)) {
1340 // If the embedder didn't create a WebContents for this route, we need to
1341 // delete the RenderView that had already been created.
1342 Send(new ViewMsg_Close(route_id));
1343 }
[email protected]dd6730412013-08-14 15:03:371344 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1345 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1346 main_frame_route_id);
1347 return;
1348 }
1349
1350 // Create the new web contents. This will automatically create the new
1351 // WebContentsView. In the future, we may want to create the view separately.
1352 WebContentsImpl* new_contents =
1353 new WebContentsImpl(GetBrowserContext(),
1354 params.opener_suppressed ? NULL : this);
1355
[email protected]d1198fd2012-08-13 22:50:191356 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301357 partition_id,
[email protected]d1198fd2012-08-13 22:50:191358 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461359 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591360 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041361 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551362 if (!is_guest) {
1363 create_params.context = view_->GetNativeView();
1364 create_params.initial_size = view_->GetContainerSize();
1365 } else {
1366 // This makes |new_contents| act as a guest.
1367 // For more info, see comment above class BrowserPluginGuest.
1368 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1369 WebContentsImpl* new_contents_impl =
1370 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461371 BrowserPluginGuest::CreateWithOpener(instance_id,
1372 new_contents_impl->opener() != NULL,
1373 new_contents_impl,
1374 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551375 }
[email protected]1ac10dca2013-08-20 20:47:041376 if (params.disposition == NEW_BACKGROUND_TAB)
1377 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591378 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191379
[email protected]c4538072013-03-18 02:17:551380 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341381 // will be shown immediately).
1382 if (!params.opener_suppressed) {
1383 if (!is_guest) {
1384 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501385
[email protected]d70bea92013-04-05 04:23:341386 // TODO(brettw): It seems bogus that we have to call this function on the
1387 // newly created object and give it one of its own member variables.
1388 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1389 }
[email protected]bafe6cd2012-05-23 23:09:501390 // Save the created window associated with the route so we can show it
1391 // later.
1392 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1393 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101394 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501395 }
1396
1397 if (delegate_) {
1398 delegate_->WebContentsCreated(
[email protected]50de3222013-03-20 15:36:131399 this, params.opener_frame_id, params.frame_name,
1400 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501401 }
1402
1403 if (params.opener_suppressed) {
1404 // When the opener is suppressed, the original renderer cannot access the
1405 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001406 bool was_blocked = false;
1407 if (delegate_) {
1408 gfx::Rect initial_pos;
1409 delegate_->AddNewContents(
1410 this, new_contents, params.disposition, initial_pos,
1411 params.user_gesture, &was_blocked);
1412 }
1413 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211414 OpenURLParams open_params(params.target_url,
1415 Referrer(),
1416 CURRENT_TAB,
1417 PAGE_TRANSITION_LINK,
1418 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301419 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001420 new_contents->OpenURL(open_params);
1421 }
[email protected]bafe6cd2012-05-23 23:09:501422 }
1423}
1424
[email protected]a8504022013-12-04 20:23:511425void WebContentsImpl::CreateNewWidget(int render_process_id,
1426 int route_id,
[email protected]180ef242013-11-07 06:50:461427 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511428 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501429}
1430
[email protected]a8504022013-12-04 20:23:511431void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1432 int route_id) {
1433 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501434}
1435
[email protected]a8504022013-12-04 20:23:511436void WebContentsImpl::CreateNewWidget(int render_process_id,
1437 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501438 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461439 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211440 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511441 // A message to create a new widget can only come from the active process for
1442 // this WebContentsImpl instance. If any other process sends the request,
1443 // it is invalid and the process must be terminated.
1444 if (process->GetID() != render_process_id) {
1445 base::ProcessHandle process_handle =
1446 RenderProcessHost::FromID(render_process_id)->GetHandle();
1447 if (process_handle != base::kNullProcessHandle) {
1448 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391449 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511450 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1451 }
1452 return;
1453 }
1454
[email protected]bafe6cd2012-05-23 23:09:501455 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041456 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261457 created_widgets_.insert(widget_host);
1458
[email protected]83918ec2013-01-10 15:37:191459 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1460 view_->CreateViewForPopupWidget(widget_host));
1461 if (!widget_view)
1462 return;
[email protected]bafe6cd2012-05-23 23:09:501463 if (!is_fullscreen) {
1464 // Popups should not get activated.
1465 widget_view->SetPopupType(popup_type);
1466 }
1467 // Save the created widget associated with the route so we can show it later.
1468 pending_widget_views_[route_id] = widget_view;
1469
1470#if defined(OS_MACOSX)
1471 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1472 // to allow it to survive the trip without being hosted.
1473 base::mac::NSObjectRetain(widget_view->GetNativeView());
1474#endif
1475}
1476
1477void WebContentsImpl::ShowCreatedWindow(int route_id,
1478 WindowOpenDisposition disposition,
1479 const gfx::Rect& initial_pos,
1480 bool user_gesture) {
1481 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001482 if (contents) {
1483 WebContentsDelegate* delegate = GetDelegate();
1484 if (delegate) {
1485 delegate->AddNewContents(
1486 this, contents, disposition, initial_pos, user_gesture, NULL);
1487 }
1488 }
[email protected]bafe6cd2012-05-23 23:09:501489}
1490
1491void WebContentsImpl::ShowCreatedWidget(int route_id,
1492 const gfx::Rect& initial_pos) {
1493 ShowCreatedWidget(route_id, false, initial_pos);
1494}
1495
1496void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1497 ShowCreatedWidget(route_id, true, gfx::Rect());
1498}
1499
1500void WebContentsImpl::ShowCreatedWidget(int route_id,
1501 bool is_fullscreen,
1502 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501503 RenderWidgetHostViewPort* widget_host_view =
1504 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1505 if (!widget_host_view)
1506 return;
[email protected]4aebbca2013-09-17 22:26:491507 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311508 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1509 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491510 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1511 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1512 delegate_->ToggleFullscreenModeForTab(this, true);
1513 } else {
1514 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491515 }
[email protected]4aebbca2013-09-17 22:26:491516 FOR_EACH_OBSERVER(WebContentsObserver,
1517 observers_,
1518 DidShowFullscreenWidget(route_id));
1519 if (!widget_host_view->HasFocus())
1520 widget_host_view->Focus();
1521 } else {
[email protected]f8497342013-02-05 22:15:021522 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491523 }
[email protected]89054502012-06-03 10:29:241524
1525 RenderWidgetHostImpl* render_widget_host_impl =
1526 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1527 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311528 // Only allow privileged mouse lock for fullscreen render widget, which is
1529 // used to implement Pepper Flash fullscreen.
1530 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501531
1532#if defined(OS_MACOSX)
1533 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1534 // properly embedded (or purposefully ignored) we can release the retain we
1535 // took in CreateNewWidget().
1536 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1537#endif
1538}
1539
1540WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1541 PendingContents::iterator iter = pending_contents_.find(route_id);
1542
1543 // Certain systems can block the creation of new windows. If we didn't succeed
1544 // in creating one, just return NULL.
1545 if (iter == pending_contents_.end()) {
1546 return NULL;
1547 }
1548
1549 WebContentsImpl* new_contents = iter->second;
1550 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101551 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501552
[email protected]d70bea92013-04-05 04:23:341553 // Don't initialize the guest WebContents immediately.
1554 if (new_contents->GetRenderProcessHost()->IsGuest())
1555 return new_contents;
1556
[email protected]bafe6cd2012-05-23 23:09:501557 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1558 !new_contents->GetRenderViewHost()->GetView())
1559 return NULL;
1560
1561 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1562 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1563 return new_contents;
1564}
1565
1566RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1567 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1568 if (iter == pending_widget_views_.end()) {
1569 DCHECK(false);
1570 return NULL;
1571 }
1572
1573 RenderWidgetHostView* widget_host_view = iter->second;
1574 pending_widget_views_.erase(route_id);
1575
1576 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1577 if (!widget_host->GetProcess()->HasConnection()) {
1578 // The view has gone away or the renderer crashed. Nothing to do.
1579 return NULL;
1580 }
1581
1582 return widget_host_view;
1583}
1584
[email protected]f13b4202012-06-12 23:53:231585void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091586 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211587 const MediaResponseCallback& callback) {
[email protected]f13b4202012-06-12 23:53:231588 if (delegate_)
1589 delegate_->RequestMediaAccessPermission(this, request, callback);
1590 else
[email protected]b5f76742013-04-29 15:05:591591 callback.Run(MediaStreamDevices(), scoped_ptr<MediaStreamUI>());
[email protected]f13b4202012-06-12 23:53:231592}
1593
[email protected]cc9200432013-07-23 23:02:401594SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1595 SiteInstance* instance) {
1596 return controller_.GetSessionStorageNamespace(instance);
1597}
1598
[email protected]9b159a52013-10-03 17:24:551599FrameTree* WebContentsImpl::GetFrameTree() {
1600 return &frame_tree_;
1601}
1602
[email protected]edc3af82013-12-12 21:24:071603void WebContentsImpl::OnShowValidationMessage(
1604 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291605 const base::string16& main_text,
1606 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071607 if (delegate_)
1608 delegate_->ShowValidationMessage(
1609 this, anchor_in_root_view, main_text, sub_text);
1610}
1611
1612void WebContentsImpl::OnHideValidationMessage() {
1613 if (delegate_)
1614 delegate_->HideValidationMessage(this);
1615}
1616
1617void WebContentsImpl::OnMoveValidationMessage(
1618 const gfx::Rect& anchor_in_root_view) {
1619 if (delegate_)
1620 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1621}
1622
[email protected]32deec62013-05-15 23:55:041623void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1624 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441625 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041626}
1627
[email protected]b172aee2012-04-10 17:05:261628void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491629 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231630 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491631 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331632}
1633
[email protected]b172aee2012-04-10 17:05:261634void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341635 if (delegate_)
1636 delegate_->ResizeDueToAutoResize(this, new_size);
1637}
1638
[email protected]b172aee2012-04-10 17:05:261639WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201640 if (!delegate_)
1641 return NULL;
[email protected]00c37fc2011-08-02 00:22:501642
[email protected]e5d549d2011-12-28 01:29:201643 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201644 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341645}
1646
[email protected]6b618e62012-08-16 12:59:181647bool WebContentsImpl::Send(IPC::Message* message) {
1648 if (!GetRenderViewHost()) {
1649 delete message;
1650 return false;
1651 }
1652
1653 return GetRenderViewHost()->Send(message);
1654}
1655
[email protected]b172aee2012-04-10 17:05:261656bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501657 NavigationController::ReloadType reload_type) {
[email protected]3691e5cf2014-01-22 10:16:201658 return frame_tree_.root()->navigator()->NavigateToPendingEntry(
1659 frame_tree_.GetMainFrame(), reload_type);
[email protected]876bc832010-09-07 16:29:541660}
[email protected]96d185d2009-04-24 03:28:541661
[email protected]a86c0e962013-12-17 17:10:391662void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1663 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441664 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391665 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441666}
1667
[email protected]20ca0382013-02-28 19:50:071668void WebContentsImpl::AttachInterstitialPage(
1669 InterstitialPageImpl* interstitial_page) {
1670 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211671 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291672
1673 // Cancel any visible dialogs so that they don't interfere with the
1674 // interstitial.
1675 if (dialog_manager_)
1676 dialog_manager_->CancelActiveAndPendingDialogs(this);
1677
[email protected]20ca0382013-02-28 19:50:071678 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1679 DidAttachInterstitialPage());
1680}
1681
1682void WebContentsImpl::DetachInterstitialPage() {
1683 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211684 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071685 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1686 DidDetachInterstitialPage());
1687}
1688
[email protected]b172aee2012-04-10 17:05:261689void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331690 const SiteInstance* site_instance,
1691 int history_length,
1692 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411693 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1694 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211695 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191696 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141697 return;
[email protected]9e1ad4b2011-08-14 16:49:191698 }
[email protected]9f76c1e2012-03-05 15:15:581699 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191700 if (!rvh) {
1701 NOTREACHED();
1702 return;
1703 }
[email protected]9f76c1e2012-03-05 15:15:581704 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191705 NOTREACHED();
1706 return;
1707 }
[email protected]6b618e62012-08-16 12:59:181708 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1709 history_length,
1710 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141711}
1712
[email protected]b172aee2012-04-10 17:05:261713void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271714 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211715 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541716 return;
1717 }
[email protected]9f76c1e2012-03-05 15:15:581718 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541719}
1720
[email protected]b172aee2012-04-10 17:05:261721bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211722 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541723}
1724
[email protected]b172aee2012-04-10 17:05:261725InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211726 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221727}
1728
[email protected]b172aee2012-04-10 17:05:261729bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161730 // WebKit creates Document object when MIME type is application/xhtml+xml,
1731 // so we also support this MIME type.
1732 return contents_mime_type_ == "text/html" ||
1733 contents_mime_type_ == "text/xml" ||
1734 contents_mime_type_ == "application/xhtml+xml" ||
1735 contents_mime_type_ == "text/plain" ||
1736 contents_mime_type_ == "text/css" ||
1737 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1738}
1739
[email protected]b172aee2012-04-10 17:05:261740void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591741 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161742 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551743 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011744 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141745 return;
[email protected]c7dd2f62011-07-18 15:57:591746 }
1747
1748 Stop();
1749
1750 // Create the save package and possibly prompt the user for the name to save
1751 // the page as. The user prompt is an asynchronous operation that runs on
1752 // another thread.
1753 save_package_ = new SavePackage(this);
1754 save_package_->GetSaveInfo();
1755}
1756
1757// Used in automated testing to bypass prompting the user for file names.
1758// Instead, the names and paths are hard coded rather than running them through
1759// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341760bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1761 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211762 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591763 // Stop the page from navigating.
1764 Stop();
1765
1766 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211767 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591768}
1769
[email protected]3c71576ce2013-07-23 02:00:011770void WebContentsImpl::SaveFrame(const GURL& url,
1771 const Referrer& referrer) {
1772 if (!GetURL().is_valid())
1773 return;
1774 bool is_main_frame = (url == GetURL());
1775
1776 DownloadManager* dlm =
1777 BrowserContext::GetDownloadManager(GetBrowserContext());
1778 if (!dlm)
1779 return;
1780 int64 post_id = -1;
1781 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271782 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011783 if (entry)
1784 post_id = entry->GetPostID();
1785 }
1786 scoped_ptr<DownloadUrlParameters> params(
1787 DownloadUrlParameters::FromWebContents(this, url));
1788 params->set_referrer(referrer);
1789 params->set_post_id(post_id);
1790 params->set_prefer_cache(true);
1791 if (post_id >= 0)
1792 params->set_method("POST");
1793 params->set_prompt(true);
1794 dlm->DownloadUrl(params.Pass());
1795}
1796
[email protected]b172aee2012-04-10 17:05:261797void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341798 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481799 const base::Callback<void(int64)>& callback) {
1800 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121801}
1802
[email protected]6286a372013-10-09 04:03:271803// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261804bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271805 NavigationEntryImpl* visible_entry =
1806 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1807 return (visible_entry != NULL &&
1808 visible_entry->site_instance() == GetSiteInstance() &&
1809 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321810}
1811
[email protected]b172aee2012-04-10 17:05:261812const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271813 return contents_mime_type_;
1814}
1815
[email protected]b172aee2012-04-10 17:05:261816bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271817 return notify_disconnection_;
1818}
1819
[email protected]b172aee2012-04-10 17:05:261820void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311821 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181822 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161823}
1824
[email protected]b172aee2012-04-10 17:05:261825void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311826 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181827 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161828}
1829
[email protected]8ff00d72012-10-23 19:12:211830RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271831 return &renderer_preferences_;
1832}
1833
[email protected]e35ccd52012-05-23 16:22:471834void WebContentsImpl::Close() {
1835 Close(GetRenderViewHost());
1836}
1837
[email protected]cf200a562013-05-03 16:24:291838void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461839 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291840 if (browser_plugin_embedder_.get())
1841 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1842 screen_x, screen_y, operation);
1843 if (GetRenderViewHost())
1844 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1845 screen_x, screen_y, operation);
1846}
1847
1848void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1849 int screen_x, int screen_y) {
1850 if (browser_plugin_embedder_.get())
1851 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1852 screen_x, screen_y);
1853 if (GetRenderViewHost())
1854 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1855 screen_x, screen_y);
1856}
1857
[email protected]d60f3702013-12-26 16:30:241858void WebContentsImpl::DidGetResourceResponseStart(
1859 const ResourceRequestDetails& details) {
1860 controller_.ssl_manager()->DidStartResourceResponse(details);
1861
1862 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1863 DidGetResourceResponseStart(details));
1864
1865 // TODO(avi): Remove. http://crbug.com/170921
1866 NotificationService::current()->Notify(
1867 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1868 Source<WebContents>(this),
1869 Details<const ResourceRequestDetails>(&details));
1870}
1871
1872void WebContentsImpl::DidGetRedirectForResourceRequest(
1873 RenderViewHost* render_view_host,
1874 const ResourceRedirectDetails& details) {
1875 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1876
1877 FOR_EACH_OBSERVER(
1878 WebContentsObserver,
1879 observers_,
1880 DidGetRedirectForResourceRequest(render_view_host, details));
1881
1882 // TODO(avi): Remove. http://crbug.com/170921
1883 NotificationService::current()->Notify(
1884 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1885 Source<WebContents>(this),
1886 Details<const ResourceRedirectDetails>(&details));
1887}
1888
[email protected]b172aee2012-04-10 17:05:261889void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521890 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581891 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511892 if (delegate_)
1893 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291894 if (browser_plugin_embedder_.get())
1895 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341896}
1897
[email protected]e35ccd52012-05-23 16:22:471898void WebContentsImpl::UserGestureDone() {
1899 OnUserGesture();
1900}
1901
[email protected]b172aee2012-04-10 17:05:261902void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271903 closed_by_user_gesture_ = value;
1904}
1905
[email protected]b172aee2012-04-10 17:05:261906bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271907 return closed_by_user_gesture_;
1908}
1909
[email protected]b172aee2012-04-10 17:05:261910double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051911 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561912 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251913 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171914 return 0;
[email protected]b75b8292010-10-01 07:28:251915
1916 double zoom_level;
1917 if (temporary_zoom_settings_) {
1918 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581919 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251920 } else {
[email protected]2ae88d12011-10-14 09:11:191921 GURL url;
[email protected]6286a372013-10-09 04:03:271922 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191923 // Since zoom map is updated using rewritten URL, use rewritten URL
1924 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271925 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021926 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1927 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251928 }
[email protected]d0b8d092010-10-25 04:05:171929 return zoom_level;
1930}
[email protected]b75b8292010-10-01 07:28:251931
[email protected]b172aee2012-04-10 17:05:261932int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591933 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171934 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011935 // Calculate the zoom percent from the factor. Round up to the nearest whole
1936 // number.
[email protected]b75b8292010-10-01 07:28:251937 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491938 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251939 *enable_decrement = percent > minimum_zoom_percent_;
1940 *enable_increment = percent < maximum_zoom_percent_;
1941 return percent;
1942}
1943
[email protected]b172aee2012-04-10 17:05:261944void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501945 if (!delegate_)
1946 return;
1947
[email protected]6286a372013-10-09 04:03:271948 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1949 if (!entry)
[email protected]1788e772010-12-15 16:40:501950 return;
1951
[email protected]6286a372013-10-09 04:03:271952 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121953}
1954
[email protected]b172aee2012-04-10 17:05:261955void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041956 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271957 if (!delegate_)
1958 return;
1959
[email protected]691aa2f2013-05-28 22:52:041960 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271961}
1962
[email protected]b172aee2012-04-10 17:05:261963int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271964 return minimum_zoom_percent_;
1965}
1966
[email protected]b172aee2012-04-10 17:05:261967int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271968 return maximum_zoom_percent_;
1969}
1970
[email protected]b172aee2012-04-10 17:05:261971gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:491972 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:231973}
1974
[email protected]b172aee2012-04-10 17:05:261975bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:271976 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:581977 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:271978}
1979
[email protected]b172aee2012-04-10 17:05:261980bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:441981 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:501982}
1983
[email protected]cb805452013-05-22 15:16:211984void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:181985 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:211986 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:201987}
1988
[email protected]cb805452013-05-22 15:16:211989void WebContentsImpl::DidEndColorChooser() {
1990 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
1991 color_chooser_identifier_));
1992 color_chooser_.reset();
1993 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:201994}
1995
[email protected]41225fe2013-03-29 05:32:021996int WebContentsImpl::DownloadImage(const GURL& url,
1997 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:301998 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:021999 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:392000 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:302001 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022002 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392003 return id;
2004}
2005
[email protected]5dcaf8e2013-12-28 01:31:422006bool WebContentsImpl::IsSubframe() const {
2007 return is_subframe_;
2008}
2009
[email protected]9649d492014-01-10 07:15:522010void WebContentsImpl::SetZoomLevel(double level) {
2011 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2012 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2013 if (embedder)
2014 embedder->SetZoomLevel(level);
2015}
2016
[email protected]36ec24f2014-01-09 00:32:082017void WebContentsImpl::Find(int request_id,
2018 const base::string16& search_text,
2019 const blink::WebFindOptions& options) {
2020 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2021}
2022
2023void WebContentsImpl::StopFinding(StopFindAction action) {
2024 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2025}
2026
[email protected]b172aee2012-04-10 17:05:262027bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272028 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202029 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332030 return true;
2031 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272032}
2033
[email protected]b172aee2012-04-10 17:05:262034void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272035 if (delegate_)
2036 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212037}
2038
[email protected]52913802013-12-10 05:52:182039void WebContentsImpl::DidStartProvisionalLoad(
2040 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072041 int parent_routing_id,
[email protected]54047eb52012-05-08 21:45:572042 bool is_main_frame,
[email protected]52913802013-12-10 05:52:182043 const GURL& validated_url,
2044 bool is_error_page,
2045 bool is_iframe_srcdoc) {
2046 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572047 DidChangeLoadProgress(0);
2048
[email protected]8cb834e2014-03-06 14:23:232049 // --site-per-process mode has a short-term hack allowing cross-process
2050 // subframe pages to commit thinking they are top-level. Correct it here to
2051 // avoid confusing the observers.
2052 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
2053 render_frame_host != GetMainFrame()) {
2054 is_main_frame = false;
2055 }
2056
[email protected]0d60f0192011-04-14 12:40:102057 // Notify observers about the start of the provisional load.
[email protected]d8c660432011-12-22 20:51:252058 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072059 DidStartProvisionalLoadForFrame(
2060 render_frame_host->GetRoutingID(), parent_routing_id,
2061 is_main_frame, validated_url, is_error_page,
2062 is_iframe_srcdoc,
2063 render_frame_host->render_view_host()));
[email protected]400992b2012-06-14 00:03:542064
2065 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182066 FOR_EACH_OBSERVER(
2067 WebContentsObserver,
2068 observers_,
2069 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582070 render_frame_host));
[email protected]400992b2012-06-14 00:03:542071 }
2072}
2073
[email protected]3109fbb72014-01-06 23:57:152074void WebContentsImpl::DidFailProvisionalLoadWithError(
2075 RenderFrameHostImpl* render_frame_host,
2076 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2077 GURL validated_url(params.url);
2078 FOR_EACH_OBSERVER(
2079 WebContentsObserver,
2080 observers_,
[email protected]501052ff2014-02-21 22:19:072081 DidFailProvisionalLoad(render_frame_host->GetRoutingID(),
[email protected]3109fbb72014-01-06 23:57:152082 params.frame_unique_name,
2083 params.is_main_frame,
2084 validated_url,
2085 params.error_code,
2086 params.error_description,
2087 render_frame_host->render_view_host()));
2088}
2089
[email protected]b80624c2014-02-09 02:46:552090void WebContentsImpl::DidFailLoadWithError(
2091 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552092 const GURL& url,
2093 bool is_main_frame,
2094 int error_code,
2095 const base::string16& error_description) {
2096 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072097 DidFailLoad(render_frame_host->GetRoutingID(),
2098 url, is_main_frame,
[email protected]b80624c2014-02-09 02:46:552099 error_code, error_description,
2100 render_frame_host->render_view_host()));
2101}
2102
[email protected]52913802013-12-10 05:52:182103void WebContentsImpl::NotifyChangedNavigationState(
2104 InvalidateTypes changed_flags) {
2105 NotifyNavigationStateChanged(changed_flags);
2106}
2107
[email protected]3691e5cf2014-01-22 10:16:202108void WebContentsImpl::AboutToNavigateRenderFrame(
2109 RenderFrameHostImpl* render_frame_host) {
2110 // Notify observers that we will navigate in this RenderView.
2111 FOR_EACH_OBSERVER(
2112 WebContentsObserver,
2113 observers_,
2114 AboutToNavigateRenderView(render_frame_host->render_view_host()));
2115}
2116
2117void WebContentsImpl::DidStartNavigationToPendingEntry(
2118 RenderFrameHostImpl* render_frame_host,
2119 const GURL& url,
2120 NavigationController::ReloadType reload_type) {
2121 // Notify observers about navigation.
2122 FOR_EACH_OBSERVER(
2123 WebContentsObserver,
2124 observers_,
2125 DidStartNavigationToPendingEntry(url, reload_type));
2126}
2127
[email protected]8cb834e2014-03-06 14:23:232128void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2129 const OpenURLParams& params) {
2130 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182131 WebContents* new_contents = OpenURL(params);
2132
2133 if (new_contents) {
2134 // Notify observers.
2135 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2136 DidOpenRequestedURL(new_contents,
2137 params.url,
2138 params.referrer,
2139 params.disposition,
2140 params.transition,
[email protected]8cb834e2014-03-06 14:23:232141 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182142 }
2143}
2144
[email protected]400992b2012-06-14 00:03:542145void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582146 RenderFrameHostImpl* render_frame_host,
2147 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542148 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582149 FOR_EACH_OBSERVER(
2150 WebContentsObserver,
2151 observers_,
2152 ProvisionalChangeToMainFrameUrl(validated_target_url,
2153 render_frame_host));
[email protected]724159a2010-12-30 01:11:182154}
2155
[email protected]37567b432014-02-12 01:12:222156void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432157 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222158 const base::string16& frame_unique_name,
2159 bool is_main_frame,
2160 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432161 PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222162 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]27dd82fd2014-03-03 22:11:432163 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]37567b432014-02-12 01:12:222164 // Notify observers about the commit of the provisional load.
2165 FOR_EACH_OBSERVER(
2166 WebContentsObserver,
2167 observers_,
[email protected]27dd82fd2014-03-03 22:11:432168 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222169 frame_unique_name,
2170 is_main_frame,
2171 url,
2172 transition_type,
2173 render_view_host));
2174}
2175
2176void WebContentsImpl::DidNavigateMainFramePostCommit(
2177 const LoadCommittedDetails& details,
2178 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2179 if (details.is_navigation_to_different_page()) {
2180 // Clear the status bubble. This is a workaround for a bug where WebKit
2181 // doesn't let us know that the cursor left an element during a
2182 // transition (this is also why the mouse cursor remains as a hand after
2183 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2184 // clear the bubble when a user navigates to a named anchor in the same
2185 // page.
2186 UpdateTargetURL(details.entry->GetPageID(), GURL());
2187 }
2188
2189 if (!details.is_in_page) {
2190 // Once the main frame is navigated, we're no longer considered to have
2191 // displayed insecure content.
2192 displayed_insecure_content_ = false;
2193 SSLManager::NotifySSLInternalStateChanged(
2194 GetController().GetBrowserContext());
2195 }
2196
2197 // Notify observers about navigation.
2198 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2199 DidNavigateMainFrame(details, params));
2200
2201 if (delegate_) {
2202 delegate_->DidNavigateMainFramePostCommit(this);
2203 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2204 }
2205}
2206
2207void WebContentsImpl::DidNavigateAnyFramePostCommit(
2208 RenderFrameHostImpl* render_frame_host,
2209 const LoadCommittedDetails& details,
2210 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2211 // If we navigate off the page, close all JavaScript dialogs.
2212 if (dialog_manager_ && !details.is_in_page)
2213 dialog_manager_->CancelActiveAndPendingDialogs(this);
2214
2215 // Notify observers about navigation.
2216 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2217 DidNavigateAnyFrame(details, params));
2218}
2219
2220void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2221 contents_mime_type_ = mime_type;
2222}
2223
2224bool WebContentsImpl::CanOverscrollContent() {
2225 if (delegate_)
2226 return delegate_->CanOverscrollContent();
2227
2228 return false;
2229}
2230
[email protected]b172aee2012-04-10 17:05:262231void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182232 const GURL& url,
[email protected]70435962011-08-02 20:13:282233 const std::string& security_info,
2234 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182235 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282236 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192237 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182238 cache.Increment();
2239
2240 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082241 int cert_id = 0;
2242 net::CertStatus cert_status = 0;
2243 int security_bits = -1;
2244 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122245 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212246 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122247 &security_bits, &connection_status,
2248 &signed_certificate_timestamp_ids);
2249 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212250 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002251 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2252 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182253
[email protected]b0f724c2013-09-05 04:21:132254 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2255
2256 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2257 DidLoadResourceFromMemoryCache(details));
2258
[email protected]8bfc8272013-09-09 20:10:532259 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2260 scoped_refptr<net::URLRequestContextGetter> request_context(
2261 resource_type == ResourceType::MEDIA ?
2262 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2263 GetRenderProcessHost()->GetID()) :
2264 GetBrowserContext()->GetRequestContextForRenderProcess(
2265 GetRenderProcessHost()->GetID()));
2266 BrowserThread::PostTask(
2267 BrowserThread::IO,
2268 FROM_HERE,
2269 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2270 }
[email protected]724159a2010-12-30 01:11:182271}
2272
[email protected]b172aee2012-04-10 17:05:262273void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392274 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182275 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192276 SSLManager::NotifySSLInternalStateChanged(
2277 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182278}
2279
[email protected]b172aee2012-04-10 17:05:262280void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022281 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582282 LOG(WARNING) << security_origin << " ran insecure content from "
2283 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392284 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412285 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392286 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182287 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412288 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192289 SSLManager::NotifySSLInternalStateChanged(
2290 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182291}
2292
[email protected]501052ff2014-02-21 22:19:072293void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572294 CHECK(render_frame_message_source_);
2295 CHECK(!render_view_message_source_);
2296 RenderFrameHostImpl* rfh =
2297 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2298
2299 FOR_EACH_OBSERVER(WebContentsObserver,
2300 observers_,
[email protected]501052ff2014-02-21 22:19:072301 DocumentLoadedInFrame(rfh->GetRoutingID(),
2302 rfh->render_view_host()));
[email protected]724159a2010-12-30 01:11:182303}
2304
[email protected]b172aee2012-04-10 17:05:262305void WebContentsImpl::OnDidFinishLoad(
[email protected]b502ed462013-01-08 08:20:062306 const GURL& url,
[email protected]1a55c5be2011-11-29 11:36:312307 bool is_main_frame) {
[email protected]028053d42014-03-05 22:20:372308 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122309 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2310 GetRenderProcessHost()->ReceivedBadMessage();
2311 return;
2312 }
[email protected]a1b99262013-12-27 21:56:222313
[email protected]028053d42014-03-05 22:20:372314 RenderFrameHostImpl* rfh =
2315 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2316
[email protected]a1b99262013-12-27 21:56:222317 // --site-per-process mode has a short-term hack allowing cross-process
2318 // subframe pages to commit thinking they are top-level. Correct it here to
2319 // avoid confusing the observers.
2320 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
[email protected]028053d42014-03-05 22:20:372321 rfh != GetMainFrame()) {
[email protected]a1b99262013-12-27 21:56:222322 is_main_frame = false;
[email protected]028053d42014-03-05 22:20:372323 }
[email protected]a1b99262013-12-27 21:56:222324
[email protected]8b3af1e2014-01-24 13:29:122325 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442326 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372327 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422328 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372329
[email protected]d8c660432011-12-22 20:51:252330 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]028053d42014-03-05 22:20:372331 DidFinishLoad(rfh->GetRoutingID(), validated_url,
2332 is_main_frame, rfh->render_view_host()));
[email protected]1a55c5be2011-11-29 11:36:312333}
2334
[email protected]b172aee2012-04-10 17:05:262335void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222336 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2337 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262338}
2339
[email protected]b172aee2012-04-10 17:05:262340void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2341 int maximum_percent,
2342 bool remember) {
[email protected]216813952011-05-19 22:21:262343 minimum_zoom_percent_ = minimum_percent;
2344 maximum_zoom_percent_ = maximum_percent;
2345 temporary_zoom_settings_ = !remember;
2346}
2347
[email protected]b172aee2012-04-10 17:05:262348void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342349 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432350 if (!delegate_)
2351 return;
2352
[email protected]b9535422012-02-09 01:47:592353 ChildProcessSecurityPolicyImpl* policy =
2354 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222355 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592356 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212357}
2358
[email protected]b172aee2012-04-10 17:05:262359void WebContentsImpl::OnJSOutOfMemory() {
[email protected]e5f2de02012-07-20 22:15:432360 if (delegate_)
2361 delegate_->JSOutOfMemory(this);
[email protected]7d189022011-08-25 22:54:202362}
2363
[email protected]b172aee2012-04-10 17:05:262364void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2365 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262366 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362367 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432368 if (!delegate_)
2369 return;
2370
[email protected]b9535422012-02-09 01:47:592371 ChildProcessSecurityPolicyImpl* policy =
2372 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322373 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592374 return;
[email protected]8f810632013-06-06 22:33:322375
[email protected]3a3b75a2012-06-01 08:38:362376 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202377}
2378
[email protected]b172aee2012-04-10 17:05:262379void WebContentsImpl::OnFindReply(int request_id,
2380 int number_of_matches,
2381 const gfx::Rect& selection_rect,
2382 int active_match_ordinal,
2383 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432384 if (delegate_) {
2385 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2386 active_match_ordinal, final_update);
2387 }
[email protected]b888919c2011-09-02 00:32:162388}
2389
[email protected]59363fc92012-09-05 03:46:312390#if defined(OS_ANDROID)
2391void WebContentsImpl::OnFindMatchRectsReply(
2392 int version,
2393 const std::vector<gfx::RectF>& rects,
2394 const gfx::RectF& active_rect) {
2395 if (delegate_)
2396 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2397}
[email protected]583418cc2013-01-17 14:01:102398
[email protected]1ff427972013-02-07 21:14:072399void WebContentsImpl::OnOpenDateTimeDialog(
2400 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092401 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2402 GetRenderViewHost(),
2403 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132404 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092405 value.minimum,
2406 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172407 value.step,
2408 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102409}
2410
[email protected]a794f3a2013-10-30 17:00:322411void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2412 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]c06c58c2014-03-12 20:31:592413 render_frame_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322414}
2415
[email protected]59363fc92012-09-05 03:46:312416#endif
2417
[email protected]f114fa42013-12-06 17:06:442418void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2419 const base::FilePath& path,
2420 bool is_hung) {
2421 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2422
2423 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2424 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2425}
2426
2427void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422428 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442429 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422430 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452431}
2432
[email protected]cfa856d62014-02-22 07:58:402433void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2434 int automation_id) {
2435 DomOperationNotificationDetails details(json_string, automation_id);
2436 NotificationService::current()->Notify(
2437 NOTIFICATION_DOM_OPERATION_RESPONSE,
2438 Source<WebContents>(this),
2439 Details<DomOperationNotificationDetails>(&details));
2440}
2441
[email protected]b172aee2012-04-10 17:05:262442void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2443 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102444 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252445 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102446 AppCacheAccessed(manifest_url, blocked_by_policy));
2447}
2448
[email protected]8bc5ff02013-11-29 06:34:032449void WebContentsImpl::OnOpenColorChooser(
2450 int color_chooser_id,
2451 SkColor color,
2452 const std::vector<ColorSuggestion>& suggestions) {
2453 ColorChooser* new_color_chooser =
2454 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302455 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212456 return;
[email protected]820957a2014-01-14 14:56:302457 if (color_chooser_)
2458 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212459 color_chooser_.reset(new_color_chooser);
2460 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202461}
2462
[email protected]b172aee2012-04-10 17:05:262463void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202464 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212465 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202466 color_chooser_->End();
2467}
2468
[email protected]b172aee2012-04-10 17:05:262469void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322470 SkColor color) {
[email protected]da8543762012-03-20 08:52:202471 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212472 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202473 color_chooser_->SetSelectedColor(color);
2474}
2475
[email protected]d0759f492012-04-19 22:50:502476// This exists for render views that don't have a WebUI, but do have WebUI
2477// bindings enabled.
2478void WebContentsImpl::OnWebUISend(const GURL& source_url,
2479 const std::string& name,
2480 const base::ListValue& args) {
2481 if (delegate_)
2482 delegate_->WebUISend(this, source_url, name, args);
2483}
2484
[email protected]d8415ad92012-08-23 14:40:502485void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442486 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502487 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342488 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162489 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442490 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162491 return;
[email protected]d8415ad92012-08-23 14:40:502492 }
2493
[email protected]8c8fc292012-11-23 18:57:162494 if (!delegate_->RequestPpapiBrokerPermission(
2495 this, url, plugin_path,
2496 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442497 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162498 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442499 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162500 }
[email protected]d8415ad92012-08-23 14:40:502501}
2502
[email protected]ea0309c2013-08-06 19:35:442503void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502504 bool result) {
[email protected]ea0309c2013-08-06 19:35:442505 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502506}
2507
[email protected]c4538072013-03-18 02:17:552508void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372509 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082510 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552511 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392512 // For more info, see comment above classes BrowserPluginEmbedder and
2513 // BrowserPluginGuest.
2514 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142515 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082516 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372517}
2518
[email protected]41225fe2013-03-29 05:32:022519void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392520 int id,
[email protected]749fadd2013-05-15 08:37:482521 int http_status_code,
[email protected]795c28972012-12-06 06:13:392522 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302523 const std::vector<SkBitmap>& bitmaps,
2524 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132525 if (bitmaps.size() != original_bitmap_sizes.size())
2526 return;
2527
[email protected]41225fe2013-03-29 05:32:022528 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2529 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392530 // Currently WebContents notifies us of ANY downloads so that it is
2531 // possible to get here.
2532 return;
2533 }
2534 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302535 iter->second.Run(
2536 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392537 }
[email protected]41225fe2013-03-29 05:32:022538 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392539}
2540
2541void WebContentsImpl::OnUpdateFaviconURL(
2542 int32 page_id,
2543 const std::vector<FaviconURL>& candidates) {
2544 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2545 DidUpdateFaviconURL(page_id, candidates));
2546}
2547
[email protected]1dd0bb752014-02-01 01:16:262548void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2549 bool has_video,
2550 bool has_audio) {
2551// Chrome OS does its own detection of audio and video.
2552#if !defined(OS_CHROMEOS)
2553 scoped_ptr<PowerSaveBlocker> blocker;
2554 if (has_video) {
2555 blocker = PowerSaveBlocker::Create(
2556 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2557#if defined(OS_ANDROID)
2558 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2559 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2560#endif
2561 } else if (has_audio) {
2562 blocker = PowerSaveBlocker::Create(
2563 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2564 }
2565
2566 if (blocker) {
2567 power_save_blockers_[render_view_message_source_][player_cookie] =
2568 blocker.release();
2569 }
2570#endif // !defined(OS_CHROMEOS)
2571}
2572
2573void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062574 // Chrome OS does its own detection of audio and video.
2575#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262576 delete power_save_blockers_[render_view_message_source_][player_cookie];
2577 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062578#endif // !defined(OS_CHROMEOS)
2579}
2580
[email protected]9f268072013-11-07 00:02:152581void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2582 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2583 DidFirstVisuallyNonEmptyPaint(page_id));
2584}
[email protected]d9030b82013-07-19 08:26:062585
[email protected]e67ebf32013-02-13 11:07:192586void WebContentsImpl::DidChangeVisibleSSLState() {
2587 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2588 DidChangeVisibleSSLState());
2589}
2590
[email protected]17e286e2013-03-01 23:29:392591void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2592 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2593 BeforeFormRepostWarningShow());
2594}
2595
[email protected]ec6c05f2013-10-23 18:41:572596
2597void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2598 Activate();
2599 if (delegate_)
2600 delegate_->ShowRepostFormWarningDialog(this);
2601}
2602
[email protected]96d185d2009-04-24 03:28:542603// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592604// loading, or done loading.
2605void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2606 bool is_loading,
[email protected]b172aee2012-04-10 17:05:262607 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542608 if (is_loading == is_loading_)
2609 return;
2610
2611 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262612 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2613 base::string16());
[email protected]96d185d2009-04-24 03:28:542614 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562615 upload_size_ = 0;
2616 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542617 }
2618
[email protected]fa944cb82013-11-15 17:51:212619 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542620
2621 is_loading_ = is_loading;
2622 waiting_for_response_ = is_loading;
2623
[email protected]6ebdc9b2010-09-27 16:55:572624 if (delegate_)
2625 delegate_->LoadingStateChanged(this);
[email protected]8ff00d72012-10-23 19:12:212626 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542627
[email protected]eab61442013-11-14 18:35:482628 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592629 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482630 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2631 "URL", url);
[email protected]91621872013-10-08 04:04:592632 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2633 DidStartLoading(render_view_host));
2634 } else {
[email protected]eab61442013-11-14 18:35:482635 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2636 "URL", url);
[email protected]91621872013-10-08 04:04:592637 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2638 DidStopLoading(render_view_host));
2639 }
[email protected]66798902013-10-01 18:40:162640
2641 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212642 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2643 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542644 if (details)
[email protected]8ff00d72012-10-23 19:12:212645 det = Details<LoadNotificationDetails>(details);
2646 NotificationService::current()->Notify(
2647 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542648}
2649
[email protected]b172aee2012-04-10 17:05:262650void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462651 // If we are creating a RVH for a restored controller, then we need to make
2652 // sure the RenderView starts with a next_page_id_ larger than the number
2653 // of restored entries. This must be called before the RenderView starts
2654 // navigating (to avoid a race between the browser updating max_page_id and
2655 // the renderer updating next_page_id_). Because of this, we only call this
2656 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562657 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582658 if (max_restored_page_id >
2659 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2660 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2661 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322662}
2663
[email protected]b172aee2012-04-10 17:05:262664bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262665 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322666 // For file URLs without a title, use the pathname instead. In the case of a
2667 // synthesized title, we don't want the update to count toward the "one set
2668 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262669 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322670 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512671 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242672 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322673 explicit_set = false; // Don't count synthetic titles toward the set limit.
2674 } else {
[email protected]8af69c6c2014-03-03 19:05:312675 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322676 explicit_set = true;
2677 }
2678
[email protected]987fc3a2011-05-26 14:18:092679 // If a page is created via window.open and never navigated,
2680 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552681 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092682 if (entry) {
[email protected]36fc0392011-12-25 03:59:512683 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092684 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322685
[email protected]36fc0392011-12-25 03:59:512686 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092687 } else {
2688 if (page_title_when_no_navigation_entry_ == final_title)
2689 return false; // Nothing changed, don't bother.
2690
2691 page_title_when_no_navigation_entry_ = final_title;
2692 }
[email protected]420ae012009-04-24 05:16:322693
[email protected]420ae012009-04-24 05:16:322694 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232695 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322696
[email protected]66798902013-10-01 18:40:162697 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532698 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162699
2700 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212701 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462702 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212703 NotificationService::current()->Notify(
2704 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2705 Source<WebContents>(this),
2706 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042707
[email protected]420ae012009-04-24 05:16:322708 return true;
2709}
2710
[email protected]7b712ee22013-10-03 00:57:282711void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2712 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322713 // After sending out a swap notification, we need to send a disconnect
2714 // notification so that clients that pick up a pointer to |this| can NULL the
2715 // pointer. See Bug 1230284.
2716 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112717 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282718 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112719
2720 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282721 std::pair<RenderViewHost*, RenderViewHost*> details =
2722 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212723 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282724 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212725 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282726 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392727
2728 // Ensure that the associated embedder gets cleared after a RenderViewHost
2729 // gets swapped, so we don't reuse the same embedder next time a
2730 // RenderViewHost is attached to this WebContents.
2731 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322732}
2733
[email protected]da7a7182013-09-06 08:11:112734// TODO(avi): Remove this entire function because this notification is already
2735// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262736void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322737 if (!notify_disconnection_)
2738 return;
2739
2740 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212741 NotificationService::current()->Notify(
2742 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2743 Source<WebContents>(this),
2744 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322745}
2746
[email protected]cbb1ef592013-06-05 19:49:462747void WebContentsImpl::NotifyNavigationEntryCommitted(
2748 const LoadCommittedDetails& load_details) {
2749 FOR_EACH_OBSERVER(
2750 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2751}
2752
[email protected]f114fa42013-12-06 17:06:442753bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2754 const IPC::Message& message) {
2755 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312756}
2757
[email protected]b849847b2013-12-10 21:57:582758void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2759 // Note this is only for subframes, the notification for the main frame
2760 // happens in RenderViewCreated.
2761 FOR_EACH_OBSERVER(WebContentsObserver,
2762 observers_,
2763 RenderFrameCreated(render_frame_host));
2764}
2765
2766void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2767 FOR_EACH_OBSERVER(WebContentsObserver,
2768 observers_,
2769 RenderFrameDeleted(render_frame_host));
2770}
2771
[email protected]a09d53ce2014-01-31 00:46:422772void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302773 if (delegate_)
2774 delegate_->WorkerCrashed(this);
2775}
2776
[email protected]a09d53ce2014-01-31 00:46:422777void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2778 const ContextMenuParams& params) {
2779 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:402780 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:422781 return;
2782
2783 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2784}
2785
[email protected]a86c0e962013-12-17 17:10:392786WebContents* WebContentsImpl::GetAsWebContents() {
2787 return this;
2788}
2789
[email protected]5a3bdf52012-05-24 15:12:572790RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2791 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322792}
2793
[email protected]8ff00d72012-10-23 19:12:212794RendererPreferences WebContentsImpl::GetRendererPrefs(
2795 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462796 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512797}
2798
[email protected]b172aee2012-04-10 17:05:262799gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172800 if (delegate_)
2801 return delegate_->GetRootWindowResizerRect();
2802 return gfx::Rect();
2803}
2804
[email protected]7a846df2012-09-20 19:17:392805void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272806 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392807 browser_plugin_embedder_.reset();
2808}
2809
[email protected]b172aee2012-04-10 17:05:262810void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442811 // Don't send notifications if we are just creating a swapped-out RVH for
2812 // the opener chain. These won't be used for view-source or WebUI, so it's
2813 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:242814 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:442815 return;
2816
[email protected]86f98a22013-03-20 14:35:002817 if (delegate_)
2818 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082819
[email protected]8ff00d72012-10-23 19:12:212820 NotificationService::current()->Notify(
2821 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2822 Source<WebContents>(this),
2823 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322824
2825 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352826 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212827 if (GetRenderManager()->pending_web_ui())
2828 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322829
[email protected]6286a372013-10-09 04:03:272830 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332831 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322832 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182833 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582834 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322835 }
[email protected]0666aef2009-05-13 19:48:082836
[email protected]60780f412013-02-25 16:34:102837 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262838
2839 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252840 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582841
2842 // We tell the observers now instead of when the main RenderFrameHostImpl is
2843 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2844 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:362845 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:582846 FOR_EACH_OBSERVER(
2847 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322848}
2849
[email protected]b172aee2012-04-10 17:05:262850void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522851 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322852 // Don't notify the world, since this came from a renderer in the
2853 // background.
2854 return;
2855 }
2856
[email protected]da7a7182013-09-06 08:11:112857 notify_disconnection_ = true;
2858 // TODO(avi): Remove. http://crbug.com/170921
2859 NotificationService::current()->Notify(
2860 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2861 Source<WebContents>(this),
2862 NotificationService::NoDetails());
2863
[email protected]be1f56ab2011-12-22 06:55:312864 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232865 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302866
2867 // Restore the focus to the tab (otherwise the focus will be on the top
2868 // window).
[email protected]484ae5912010-09-29 19:16:142869 if (was_crashed && !FocusLocationBarByDefault() &&
2870 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062871 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142872 }
[email protected]32ded2212011-11-10 18:51:432873
[email protected]d8c660432011-12-22 20:51:252874 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322875}
2876
[email protected]ec6a7eb2013-04-22 17:34:222877void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2878 base::TerminationStatus status,
2879 int error_code) {
[email protected]151a63d2011-12-20 22:32:522880 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322881 // The pending page's RenderViewHost is gone.
2882 return;
2883 }
2884
[email protected]2fcdcc32014-03-05 02:14:072885 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
2886 // renderer may not have made a clean exit.
2887 if (IsFullscreenForCurrentTab())
2888 ToggleFullscreenMode(false);
2889
[email protected]698191dc2014-02-25 01:06:132890 // Cancel any visible dialogs so they are not left dangling over the sad tab.
2891 if (dialog_manager_)
2892 dialog_manager_->CancelActiveAndPendingDialogs(this);
2893
[email protected]d9030b82013-07-19 08:26:062894 ClearPowerSaveBlockers(rvh);
[email protected]91621872013-10-08 04:04:592895 SetIsLoading(rvh, false, NULL);
[email protected]420ae012009-04-24 05:16:322896 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232897 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312898 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322899
[email protected]d8c660432011-12-22 20:51:252900 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272901 observers_,
[email protected]58d5cfe2013-07-10 02:40:522902 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322903}
2904
[email protected]b172aee2012-04-10 17:05:262905void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062906 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212907 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252908 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062909}
2910
[email protected]b172aee2012-04-10 17:05:262911void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2912 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042913 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152914 // Ensure that this state update comes from either the active RVH or one of
2915 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412916 // TODO(nasko): This should go through RenderFrameHost.
2917 // TODO(creis): We can't update state for cross-process subframes until we
2918 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2919 if (rvh != GetRenderViewHost() &&
2920 !GetRenderManager()->IsRVHOnSwappedOutList(
2921 static_cast<RenderViewHostImpl*>(rvh)))
2922 return;
[email protected]420ae012009-04-24 05:16:322923
2924 // We must be prepared to handle state updates for any page, these occur
2925 // when the user is scrolling and entering form data, as well as when we're
2926 // leaving a page, in which case our state may have already been moved to
2927 // the next page. The navigation controller will look up the appropriate
2928 // NavigationEntry and update it when it is notified via the delegate.
2929
2930 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582931 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322932 if (entry_index < 0)
2933 return;
[email protected]10f417c52011-12-28 21:04:232934 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322935
[email protected]691aa2f2013-05-28 22:52:042936 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322937 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042938 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322939 controller_.NotifyEntryChanged(entry, entry_index);
2940}
2941
[email protected]b172aee2012-04-10 17:05:262942void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2943 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262944 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262945 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322946 // If we have a title, that's a pretty good indication that we've started
2947 // getting useful data.
2948 SetNotWaitingForResponse();
2949
[email protected]73eb2602012-02-09 19:50:552950 // Try to find the navigation entry, which might not be the current one.
2951 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232952 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582953 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092954
[email protected]73eb2602012-02-09 19:50:552955 // We can handle title updates when we don't have an entry in
2956 // UpdateTitleForEntry, but only if the update is from the current RVH.
2957 if (!entry && rvh != GetRenderViewHost())
2958 return;
2959
[email protected]a49e10b2011-08-01 23:57:462960 // TODO(evan): make use of title_direction.
2961 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092962 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322963 return;
2964
2965 // Broadcast notifications when the UI should be updated.
2966 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212967 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322968}
2969
[email protected]b172aee2012-04-10 17:05:262970void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2971 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312972 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322973}
2974
[email protected]b172aee2012-04-10 17:05:262975void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512976 if (delegate_)
2977 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322978}
2979
[email protected]b172aee2012-04-10 17:05:262980void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:102981#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:292982 // The UI may be in an event-tracking loop, such as between the
2983 // mouse-down and mouse-up in text selection or a button click.
2984 // Defer the close until after tracking is complete, so that we
2985 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292986 // TODO(shess): This could get more fine-grained. For instance,
2987 // closing a tab in another window while selecting text in the
2988 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:102989 if (view_->IsEventTracking()) {
2990 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:292991 return;
2992 }
[email protected]60780f412013-02-25 16:34:102993#endif
[email protected]07707302009-11-06 00:50:292994
[email protected]420ae012009-04-24 05:16:322995 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:522996 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:512997 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:322998}
2999
[email protected]b172aee2012-04-10 17:05:263000void WebContentsImpl::SwappedOut(RenderViewHost* rvh) {
[email protected]2fcdcc32014-03-05 02:14:073001 if (rvh == GetRenderViewHost()) {
3002 // Exit fullscreen mode before the current RVH is swapped out. For numerous
3003 // cases, there is no guarantee the renderer would/could initiate an exit.
3004 // Example: http://crbug.com/347232
3005 if (IsFullscreenForCurrentTab()) {
3006 if (rvh)
3007 rvh->ExitFullscreen();
3008 DCHECK(!IsFullscreenForCurrentTab());
3009 }
3010
3011 if (delegate_)
3012 delegate_->SwappedOut(this);
3013 }
[email protected]e1986832013-06-14 07:27:283014
3015 // Allow the navigation to proceed.
[email protected]fa944cb82013-11-15 17:51:213016 GetRenderManager()->SwappedOut(rvh);
[email protected]cd9ed79d2011-11-15 19:22:573017}
3018
[email protected]b172aee2012-04-10 17:05:263019void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513020 if (delegate_ && delegate_->IsPopupOrPanel(this))
3021 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323022}
3023
[email protected]723971b2014-02-12 11:08:253024void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host) {
3025 SetIsLoading(render_frame_host->GetRenderViewHost(), true, NULL);
[email protected]420ae012009-04-24 05:16:323026}
3027
[email protected]723971b2014-02-12 11:08:253028void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323029 scoped_ptr<LoadNotificationDetails> details;
3030
[email protected]9595fd82013-04-19 21:28:493031 // Use the last committed entry rather than the active one, in case a
3032 // pending entry has been created.
3033 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203034 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493035
[email protected]420ae012009-04-24 05:16:323036 // An entry may not exist for a stop when loading an initial blank page or
3037 // if an iframe injected by script into a blank page finishes loading.
3038 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203039 base::TimeDelta elapsed =
3040 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323041
3042 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513043 entry->GetVirtualURL(),
3044 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323045 elapsed,
3046 &controller_,
3047 controller_.GetCurrentEntryIndex()));
3048 }
3049
[email protected]723971b2014-02-12 11:08:253050 SetIsLoading(render_frame_host->GetRenderViewHost(), false, details.get());
[email protected]420ae012009-04-24 05:16:323051}
3052
[email protected]b172aee2012-04-10 17:05:263053void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163054 controller_.DiscardNonCommittedEntries();
3055
3056 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213057 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163058}
3059
[email protected]b172aee2012-04-10 17:05:263060void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513061 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133062 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403063}
3064
[email protected]7cc78902012-12-06 02:32:263065void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393066 if (opener_) {
3067 // Clear our opener so that future cross-process navigations don't have an
3068 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103069 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393070 opener_ = NULL;
3071 }
[email protected]7cc78902012-12-06 02:32:263072
3073 // Notify all swapped out RenderViewHosts for this tab. This is important
3074 // in case we go back to them, or if another window in those processes tries
3075 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213076 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263077}
3078
[email protected]59167c22013-06-03 18:07:323079void WebContentsImpl::DidAccessInitialDocument() {
3080 // Update the URL display.
3081 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3082}
3083
[email protected]87717d0e2012-04-26 02:58:433084void WebContentsImpl::DocumentAvailableInMainFrame(
3085 RenderViewHost* render_view_host) {
3086 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3087 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103088}
3089
[email protected]b172aee2012-04-10 17:05:263090void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083091 RenderViewHost* render_view_host,
3092 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093093 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3094 DocumentOnLoadCompletedInMainFrame(page_id));
3095
3096 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213097 NotificationService::current()->Notify(
3098 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3099 Source<WebContents>(this),
3100 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083101}
3102
[email protected]e1c3a552012-05-04 20:51:323103void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3104 // Tell the active RenderViewHost to run unload handlers and close, as long
3105 // as the request came from a RenderViewHost in the same BrowsingInstance.
3106 // In most cases, we receive this from a swapped out RenderViewHost.
3107 // It is possible to receive it from one that has just been swapped in,
3108 // in which case we might as well deliver the message anyway.
3109 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3110 GetRenderViewHost()->ClosePage();
3111}
3112
[email protected]f546640b2012-05-15 00:03:493113void WebContentsImpl::RouteMessageEvent(
3114 RenderViewHost* rvh,
3115 const ViewMsg_PostMessage_Params& params) {
3116 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363117 // came from a RenderViewHost in the same BrowsingInstance or if this
3118 // WebContents is dedicated to a browser plugin guest.
3119 // Note: This check means that an embedder could theoretically receive a
3120 // postMessage from anyone (not just its own guests). However, this is
3121 // probably not a risk for apps since other pages won't have references
3122 // to App windows.
3123 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3124 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493125 return;
3126
3127 ViewMsg_PostMessage_Params new_params(params);
3128
[email protected]0bc7f3542013-10-21 15:05:533129 if (!params.message_port_ids.empty()) {
3130 MessagePortMessageFilter* message_port_message_filter =
3131 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3132 ->message_port_message_filter();
3133 std::vector<int> new_routing_ids(params.message_port_ids.size());
3134 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3135 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3136 MessagePortService::GetInstance()->UpdateMessagePort(
3137 params.message_port_ids[i],
3138 message_port_message_filter,
3139 new_routing_ids[i]);
3140 }
3141 new_params.new_routing_ids = new_routing_ids;
3142 }
3143
[email protected]f546640b2012-05-15 00:03:493144 // If there is a source_routing_id, translate it to the routing ID for
3145 // the equivalent swapped out RVH in the target process. If we need
3146 // to create a swapped out RVH for the source tab, we create its opener
3147 // chain as well, since those will also be accessible to the target page.
3148 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3149 // Try to look up the WebContents for the source page.
3150 WebContentsImpl* source_contents = NULL;
3151 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3152 rvh->GetProcess()->GetID(), params.source_routing_id);
3153 if (source_rvh) {
3154 source_contents = static_cast<WebContentsImpl*>(
3155 source_rvh->GetDelegate()->GetAsWebContents());
3156 }
3157
3158 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363159 if (GetBrowserPluginGuest()) {
3160 // We create a swapped out RenderView for the embedder in the guest's
3161 // render process but we intentionally do not expose the embedder's
3162 // opener chain to it.
3163 new_params.source_routing_id =
3164 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3165 } else {
3166 new_params.source_routing_id =
3167 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3168 }
[email protected]f546640b2012-05-15 00:03:493169 } else {
3170 // We couldn't find it, so don't pass a source frame.
3171 new_params.source_routing_id = MSG_ROUTING_NONE;
3172 }
3173 }
3174
3175 // In most cases, we receive this from a swapped out RenderViewHost.
3176 // It is possible to receive it from one that has just been swapped in,
3177 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183178 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493179}
3180
[email protected]b172aee2012-04-10 17:05:263181void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343182 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263183 const base::string16& message,
3184 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323185 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213186 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323187 IPC::Message* reply_msg,
3188 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073189 // Suppress JavaScript dialogs when requested. Also suppress messages when
3190 // showing an interstitial as it's shown over the previous page and we don't
3191 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503192 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243193 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() ||
[email protected]0bfbf882011-12-22 18:19:273194 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073195 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523196 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153197 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323198
3199 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213200 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433201 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153202 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3203 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433204 this,
3205 frame_url.GetOrigin(),
3206 accept_lang,
3207 javascript_message_type,
3208 message,
[email protected]51da7e32012-01-30 19:24:523209 default_prompt,
[email protected]b172aee2012-04-10 17:05:263210 base::Bind(&WebContentsImpl::OnDialogClosed,
3211 base::Unretained(this),
3212 rvh,
3213 reply_msg),
[email protected]51da7e32012-01-30 19:24:523214 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323215 }
[email protected]3ab9cb82011-06-03 18:02:073216
[email protected]6dd2f1e2013-09-11 15:06:013217 *did_suppress_message = suppress_this_message;
3218
[email protected]3ab9cb82011-06-03 18:02:073219 if (suppress_this_message) {
3220 // If we are suppressing messages, just reply as if the user immediately
3221 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263222 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073223 }
3224
[email protected]6dd2f1e2013-09-11 15:06:013225 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3226 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323227}
3228
[email protected]b172aee2012-04-10 17:05:263229void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263230 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263231 bool is_reload,
3232 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583233 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513234 if (delegate_)
3235 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073236
3237 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243238 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
[email protected]3ab9cb82011-06-03 18:02:073239 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523240 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153241 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153242 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343243 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263244 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503245 return;
3246 }
[email protected]3ab9cb82011-06-03 18:02:073247
[email protected]7ab1e7d62009-10-14 23:32:013248 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153249 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3250 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323251 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263252 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523253 reply_msg));
[email protected]420ae012009-04-24 05:16:323254}
3255
[email protected]a796f202012-05-30 14:14:253256bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263257 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253258 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263259 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253260 if (!delegate_)
3261 return false;
3262 return delegate_->AddMessageToConsole(this, level, message, line_no,
3263 source_id);
3264}
3265
[email protected]b172aee2012-04-10 17:05:263266WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273267 // We want to base the page config off of the actual URL, rather than the
3268 // virtual URL.
3269 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3270 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003271 GURL url = controller_.GetActiveEntry()
3272 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153273
[email protected]fa944cb82013-11-15 17:51:213274 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323275}
3276
[email protected]0eba810b2012-10-18 03:19:363277int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213278 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413279 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3280 true, true);
[email protected]0eba810b2012-10-18 03:19:363281}
3282
[email protected]b172aee2012-04-10 17:05:263283void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273284 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253285 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223286
[email protected]ea114722012-03-12 01:11:253287 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173288 if (rdh) // NULL in unittests.
3289 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253290}
3291
[email protected]b172aee2012-04-10 17:05:263292void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443293 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253294 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443295}
3296
[email protected]b172aee2012-04-10 17:05:263297void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563298 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263299 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153300 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523301 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153302 return;
3303
[email protected]9f76c1e2012-03-05 15:15:583304 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3305
[email protected]e5fc1632011-08-08 07:51:533306 // Ignore renderer unresponsive event if debugger is attached to the tab
3307 // since the event may be a result of the renderer sitting on a breakpoint.
3308 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363309 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533310 return;
3311
[email protected]2e9d79f2013-08-16 05:45:563312 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323313 // Hang occurred while firing the beforeunload/unload handler.
3314 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583315 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323316
[email protected]fa944cb82013-11-15 17:51:213317 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323318 return;
3319
3320 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563321 // nothing we can do to recover. If the hang is in the beforeunload handler,
3322 // pretend the beforeunload listeners have all fired and allow the delegate
3323 // to continue closing; the user will not have the option of cancelling the
3324 // close. Otherwise, pretend the unload listeners have all fired and close
3325 // the tab.
3326 bool close = true;
3327 if (is_during_beforeunload) {
3328 delegate_->BeforeUnloadFired(this, true, &close);
3329 }
3330 if (close)
3331 Close(rvh);
[email protected]420ae012009-04-24 05:16:323332 return;
3333 }
3334
[email protected]9f76c1e2012-03-05 15:15:583335 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473336 return;
3337
[email protected]6934a702011-12-20 00:04:513338 if (delegate_)
3339 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323340}
3341
[email protected]b172aee2012-04-10 17:05:263342void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513343 if (delegate_)
3344 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323345}
3346
[email protected]b172aee2012-04-10 17:05:263347void WebContentsImpl::LoadStateChanged(
3348 const GURL& url,
3349 const net::LoadStateWithParam& load_state,
3350 uint64 upload_position,
3351 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323352 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563353 upload_position_ = upload_position;
3354 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503355 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213356 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303357 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213358 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323359 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463360 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213361 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463362 }
[email protected]420ae012009-04-24 05:16:323363}
3364
[email protected]b172aee2012-04-10 17:05:263365void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553366 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323367 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123368 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3369 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513370 if (delegate_)
3371 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093372 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323373}
3374
[email protected]58d5cfe2013-07-10 02:40:523375void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543376 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233377 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223378 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543379}
3380
[email protected]b172aee2012-04-10 17:05:263381void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103382 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213383 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263384 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3385 // here during container initialization and normal window size will be set
3386 // later. In case of tab duplication this resizing to 0x0 prevents setting
3387 // normal size later so just ignore it.
3388 if (!size.IsEmpty())
3389 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323390}
3391
[email protected]af905902013-10-01 21:38:513392void WebContentsImpl::CancelModalDialogsForRenderManager() {
3393 // We need to cancel modal dialogs when doing a process swap, since the load
3394 // deferrer would prevent us from swapping out.
3395 if (dialog_manager_)
3396 dialog_manager_->CancelActiveAndPendingDialogs(this);
3397}
3398
[email protected]7b712ee22013-10-03 00:57:283399void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3400 RenderViewHost* new_host) {
3401 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083402
3403 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003404 if (delegate_)
3405 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393406
[email protected]7b712ee22013-10-03 00:57:283407 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543408}
3409
[email protected]14392a52012-05-02 20:28:443410int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3411 SiteInstance* instance) {
3412 if (!opener_)
3413 return MSG_ROUTING_NONE;
3414
3415 // Recursively create RenderViews for anything else in the opener chain.
3416 return opener_->CreateOpenerRenderViews(instance);
3417}
3418
3419int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3420 int opener_route_id = MSG_ROUTING_NONE;
3421
3422 // If this tab has an opener, ensure it has a RenderView in the given
3423 // SiteInstance as well.
3424 if (opener_)
3425 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3426
[email protected]45a22ad2013-02-21 03:25:003427 // If any of the renderers (current, pending, or swapped out) for this
3428 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213429 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3430 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373431
[email protected]fa944cb82013-11-15 17:51:213432 if (GetRenderManager()->pending_render_view_host() &&
3433 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3434 instance)
3435 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003436
[email protected]fa944cb82013-11-15 17:51:213437 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373438 instance);
3439 if (rvh)
3440 return rvh->GetRoutingID();
3441
[email protected]14392a52012-05-02 20:28:443442 // Create a swapped out RenderView in the given SiteInstance if none exists,
3443 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413444 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3445 true, true);
[email protected]14392a52012-05-02 20:28:443446}
3447
[email protected]b172aee2012-04-10 17:05:263448NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193449 return GetController();
[email protected]3a3d47472010-07-15 21:03:543450}
3451
[email protected]b172aee2012-04-10 17:05:263452WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563453 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323454}
3455
[email protected]10f417c52011-12-28 21:04:233456NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263457 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323458 return controller_.GetLastCommittedEntry();
3459}
3460
[email protected]b172aee2012-04-10 17:05:263461bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163462 RenderViewHost* render_view_host,
3463 int opener_route_id,
3464 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033465 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443466 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163467 RenderWidgetHostView* rwh_view;
3468 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3469 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3470 // case this because RWH is still a base class of RenderViewHost, and child
3471 // frame RWHVs are unique in that they do not have their own WebContents.
3472 if (frame_connector) {
3473 RenderWidgetHostViewChildFrame* rwh_view_child =
3474 new RenderWidgetHostViewChildFrame(render_view_host);
3475 frame_connector->set_view(rwh_view_child);
3476 rwh_view = rwh_view_child;
3477 } else {
3478 rwh_view = view_->CreateViewForWidget(render_view_host);
3479 }
[email protected]1a98a932009-11-17 00:12:523480
[email protected]420ae012009-04-24 05:16:323481 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443482 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213483 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323484
[email protected]74ce1ad2011-12-16 21:51:463485 // Make sure we use the correct starting page_id in the new RenderView.
3486 UpdateMaxPageIDIfNecessary(render_view_host);
3487 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583488 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463489
[email protected]9f76c1e2012-03-05 15:15:583490 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263491 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493492 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133493 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523494 return false;
[email protected]14392a52012-05-02 20:28:443495 }
[email protected]a4127722011-04-27 23:13:523496
[email protected]a220b5932013-09-21 03:47:443497#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503498 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3499 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443500 if (rwh_view) {
3501 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3502 render_widget_host->WasResized();
3503 }
[email protected]f8233cc2011-05-31 20:24:503504#endif
3505
[email protected]420ae012009-04-24 05:16:323506 return true;
3507}
3508
[email protected]7d244f12013-08-22 21:41:513509#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183510base::android::ScopedJavaLocalRef<jobject>
3511WebContentsImpl::GetJavaWebContents() {
3512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3513
3514 WebContentsAndroid* web_contents_android =
3515 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3516 if (!web_contents_android) {
3517 web_contents_android = new WebContentsAndroid(this);
3518 SetUserData(kWebContentsAndroidKey, web_contents_android);
3519 }
3520 return web_contents_android->GetJavaObject();
3521}
3522
[email protected]7d244f12013-08-22 21:41:513523bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3524 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163525 MSG_ROUTING_NONE,
3526 NULL);
[email protected]7d244f12013-08-22 21:41:513527}
3528#endif
3529
[email protected]b172aee2012-04-10 17:05:263530void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3531 IPC::Message* reply_msg,
3532 bool success,
[email protected]fcf75d42013-12-03 20:11:263533 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543534 if (is_showing_before_unload_dialog_ && !success) {
3535 // If a beforeunload dialog is canceled, we need to stop the throbber from
3536 // spinning, since we forced it to start spinning in Navigate.
[email protected]723971b2014-02-12 11:08:253537 DidStopLoading(rvh->GetMainFrame());
[email protected]15d160c02012-07-04 10:52:353538 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103539
[email protected]6d65a462013-06-21 21:29:123540 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3541 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543542 }
3543 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583544 static_cast<RenderViewHostImpl*>(
3545 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543546}
3547
[email protected]b172aee2012-04-10 17:05:263548void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213549 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123550 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103551}
[email protected]f45d2a72010-03-08 23:28:353552
[email protected]b172aee2012-04-10 17:05:263553void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103554 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443555 // Can be NULL during tests.
3556 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213557 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363558}
[email protected]9f76c1e2012-03-05 15:15:583559
[email protected]1ac10dca2013-08-20 20:47:043560bool WebContentsImpl::IsHidden() {
3561 return capturer_count_ == 0 && !should_normally_be_visible_;
3562}
3563
[email protected]b0936d22013-11-28 06:47:363564RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213565 return frame_tree_.root()->render_manager();
3566}
3567
[email protected]b172aee2012-04-10 17:05:263568RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583569 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3570}
[email protected]7900bfdb2012-05-24 19:31:243571
[email protected]f8497342013-02-05 22:15:023572BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393573 return browser_plugin_guest_.get();
3574}
3575
[email protected]738f57a2013-06-29 21:06:543576void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3577 CHECK(!browser_plugin_guest_);
3578 browser_plugin_guest_.reset(guest);
3579}
3580
[email protected]f8497342013-02-05 22:15:023581BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393582 return browser_plugin_embedder_.get();
3583}
[email protected]8ff00d72012-10-23 19:12:213584
[email protected]8eb04562013-03-06 03:41:143585BrowserPluginGuestManager*
3586 WebContentsImpl::GetBrowserPluginGuestManager() const {
3587 return static_cast<BrowserPluginGuestManager*>(
3588 GetBrowserContext()->GetUserData(
3589 browser_plugin::kBrowserPluginGuestManagerKeyName));
3590}
3591
[email protected]d9030b82013-07-19 08:26:063592void WebContentsImpl::ClearPowerSaveBlockers(
3593 RenderViewHost* render_view_host) {
3594 STLDeleteValues(&power_save_blockers_[render_view_host]);
3595 power_save_blockers_.erase(render_view_host);
3596}
3597
3598void WebContentsImpl::ClearAllPowerSaveBlockers() {
3599 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3600 i != power_save_blockers_.end(); ++i)
3601 STLDeleteValues(&power_save_blockers_[i->first]);
3602 power_save_blockers_.clear();
3603}
3604
[email protected]dc0fd432013-08-27 15:29:213605gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3606 gfx::Size size;
3607 if (delegate_)
3608 size = delegate_->GetSizeForNewRenderView(this);
3609 if (size.IsEmpty())
3610 size = view_->GetContainerSize();
3611 return size;
3612}
3613
[email protected]9b159a52013-10-03 17:24:553614void WebContentsImpl::OnFrameRemoved(
3615 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583616 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553617 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583618 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553619}
3620
[email protected]222f5822014-02-05 23:40:493621void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3622 if (!delegate_)
3623 return;
3624 const gfx::Size new_size = GetPreferredSize();
3625 if (new_size != old_size)
3626 delegate_->UpdatePreferredSize(this, new_size);
3627}
3628
[email protected]8ff00d72012-10-23 19:12:213629} // namespace content