blob: 79cfa068f8de4d739eb4cd6c4dfa32f67af50daf [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]31a71eaf2014-03-13 01:47:3658#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1159#include "content/public/browser/browser_context.h"
[email protected]da8543762012-03-20 08:52:2060#include "content/public/browser/color_chooser.h"
[email protected]87f3c082011-10-19 18:07:4461#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3662#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1763#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1464#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4665#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1566#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0067#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2768#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0069#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3770#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1471#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3272#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3473#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3874#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4275#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2576#include "content/public/browser/web_contents_observer.h"
[email protected]8643e6d2012-01-18 20:26:1077#include "content/public/browser/web_contents_view.h"
[email protected]e091df82011-10-11 18:13:2178#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4879#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5480#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4981#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2082#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0383#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5784#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1685#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2986#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5387#include "net/http/http_cache.h"
88#include "net/http/http_transaction_factory.h"
89#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3490#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5691#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0192#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4193#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5294#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1895#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3196
[email protected]583418cc2013-01-17 14:01:1097#if defined(OS_ANDROID)
98#include "content/browser/android/date_time_chooser_android.h"
[email protected]a794f3a2013-10-30 17:00:3299#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h"
[email protected]155c7f22013-12-09 17:07:18100#include "content/browser/web_contents/web_contents_android.h"
[email protected]a794f3a2013-10-30 17:00:32101#include "content/common/java_bridge_messages.h"
[email protected]74ebfb12013-06-07 20:48:00102#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10103#endif
104
[email protected]f66df822012-05-18 16:52:17105#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50106#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27107#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57108#endif
[email protected]3e45ba92009-02-20 21:09:00109
[email protected]420ae012009-04-24 05:16:32110// Cross-Site Navigations
111//
[email protected]b172aee2012-04-10 17:05:26112// If a WebContentsImpl is told to navigate to a different web site (as
113// determined by SiteInstance), it will replace its current RenderViewHost with
114// a new RenderViewHost dedicated to the new SiteInstance. This works as
115// follows:
[email protected]420ae012009-04-24 05:16:32116//
[email protected]fc6c1872013-10-03 01:22:35117// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46118// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32119// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35120// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32121// run in the current RVH.
122// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35123// that it has a pending cross-site request. We will check this on the IO
124// thread when deciding how to handle the response.
125// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46126// cancel all the pending logic. Otherwise we allow the pending RVH to send
127// the navigation request to its renderer.
128// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35129// main resource load on the pending RVH. It creates a
130// CrossSiteResourceHandler to check whether a process swap is needed when
131// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46132// - When RDH receives a response, the BufferedResourceHandler determines
133// whether it is a download. If so, it sends a message to the new renderer
134// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26135// pending RVH remains until the next DidNavigate event for this
136// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32137// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35138// download, the CrossSiteResourceHandler checks whether a process swap is
139// needed (either because CrossSiteRequestManager has state for it or because
140// a transfer was needed for a redirect).
141// - If so, CrossSiteResourceHandler pauses the response to first run the old
142// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36143// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
144// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35145// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
146// to a new process is needed, based on the stored pending_nav_params_. (This
147// is independent of whether we started out with a cross-process navigation.)
148// - If not, it just tells the ResourceDispatcherHost to resume the response
149// to its current RenderViewHost.
150// - If so, it cancels the current pending RenderViewHost and sets up a new
151// navigation using RequestTransferURL. When the transferred request
152// arrives in the ResourceDispatcherHost, we transfer the response and
153// resume it.
[email protected]420ae012009-04-24 05:16:32154// - The pending renderer sends a FrameNavigate message that invokes the
155// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46156// pending RVH.
[email protected]b0936d22013-11-28 06:47:36157// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15158// the user goes back. The process only stays live if another tab is using
159// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32160
[email protected]8ff00d72012-10-23 19:12:21161namespace content {
[email protected]420ae012009-04-24 05:16:32162namespace {
163
[email protected]82114f52012-03-20 22:53:41164const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05165
[email protected]155c7f22013-12-09 17:07:18166#if defined(OS_ANDROID)
167const char kWebContentsAndroidKey[] = "web_contents_android";
168#endif // OS_ANDROID
169
[email protected]e4abd3b42013-11-12 18:28:47170base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46171g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
172
[email protected]795c28972012-12-06 06:13:39173static int StartDownload(content::RenderViewHost* rvh,
174 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29175 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30176 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02177 static int g_next_image_download_id = 0;
178 rvh->Send(new ImageMsg_DownloadImage(rvh->GetRoutingID(),
179 ++g_next_image_download_id,
180 url,
181 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30182 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02183 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39184}
185
[email protected]8bfc8272013-09-09 20:10:53186void NotifyCacheOnIO(
187 scoped_refptr<net::URLRequestContextGetter> request_context,
188 const GURL& url,
189 const std::string& http_method) {
190 request_context->GetURLRequestContext()->http_transaction_factory()->
191 GetCache()->OnExternalCacheHit(url, http_method);
192}
193
[email protected]9b159a52013-10-03 17:24:55194// Helper function for retrieving all the sites in a frame tree.
195bool CollectSites(BrowserContext* context,
196 std::set<GURL>* sites,
197 FrameTreeNode* node) {
198 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
199 return true;
200}
201
[email protected]a86c0e962013-12-17 17:10:39202bool ForEachFrameInternal(
203 const base::Callback<void(RenderFrameHost*)>& on_frame,
204 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41205 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39206 return true;
207}
208
[email protected]c06c58c2014-03-12 20:31:59209bool ForEachPendingFrameInternal(
210 const base::Callback<void(RenderFrameHost*)>& on_frame,
211 FrameTreeNode* node) {
212 RenderFrameHost* pending_frame_host =
213 node->render_manager()->pending_frame_host();
214 if (pending_frame_host)
215 on_frame.Run(pending_frame_host);
216 return true;
217}
218
[email protected]a86c0e962013-12-17 17:10:39219void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
220 IPC::Message* message_copy = new IPC::Message(*message);
221 message_copy->set_routing_id(rfh->GetRoutingID());
222 rfh->Send(message_copy);
223}
224
[email protected]c06c58c2014-03-12 20:31:59225void RunRenderFrameDeleted(
226 ObserverList<WebContentsObserver>* observer_list,
227 RenderFrameHost* render_frame_host) {
228 FOR_EACH_OBSERVER(WebContentsObserver,
229 *observer_list,
230 RenderFrameDeleted(render_frame_host));
231}
232
[email protected]420ae012009-04-24 05:16:32233} // namespace
234
[email protected]54944cde2012-12-09 09:24:59235WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15236 return WebContentsImpl::CreateWithOpener(
237 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19238}
239
240WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59241 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30242 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59243 WebContentsImpl* new_contents = new WebContentsImpl(
244 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30245
246 for (SessionStorageNamespaceMap::const_iterator it =
247 session_storage_namespace_map.begin();
248 it != session_storage_namespace_map.end();
249 ++it) {
250 new_contents->GetController()
251 .SetSessionStorageNamespace(it->first, it->second.get());
252 }
253
[email protected]54944cde2012-12-09 09:24:59254 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19255 return new_contents;
[email protected]a81343d232011-12-27 07:39:20256}
[email protected]746d3052012-05-22 15:15:47257
[email protected]e4abd3b42013-11-12 18:28:47258void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46259 g_created_callbacks.Get().push_back(callback);
260}
261
[email protected]e4abd3b42013-11-12 18:28:47262void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46263 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
264 if (g_created_callbacks.Get().at(i).Equals(callback)) {
265 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
266 return;
267 }
268 }
269}
270
[email protected]299d7f12012-05-23 05:31:15271WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47272 return rvh->GetDelegate()->GetAsWebContents();
273}
274
[email protected]a86c0e962013-12-17 17:10:39275WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
276 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
277 if (!rfh_impl)
278 return NULL;
279 return rfh_impl->delegate()->GetAsWebContents();
280}
281
[email protected]7fff43e2013-05-21 20:21:10282// WebContentsImpl::DestructionObserver ----------------------------------------
283
284class WebContentsImpl::DestructionObserver : public WebContentsObserver {
285 public:
286 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
287 : WebContentsObserver(watched_contents),
288 owner_(owner) {
289 }
290
291 // WebContentsObserver:
292 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
293 owner_->OnWebContentsDestroyed(static_cast<WebContentsImpl*>(web_contents));
294 }
295
296 private:
297 WebContentsImpl* owner_;
298
299 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
300};
301
[email protected]b172aee2012-04-10 17:05:26302// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32303
[email protected]b172aee2012-04-10 17:05:26304WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21305 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19306 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42307 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22308 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57309 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44310 opener_(opener),
[email protected]2ceee8f2014-01-14 18:02:08311#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41312 accessible_parent_(NULL),
313#endif
[email protected]6ea6bdf2013-12-06 13:35:01314 frame_tree_(new NavigatorImpl(&controller_, this),
315 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34316 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23317 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
318 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34319 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26320 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56321 upload_size_(0),
322 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47323 displayed_insecure_content_(false),
[email protected]54597982013-02-06 01:59:55324 capturer_count_(0),
325 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57326 is_being_destroyed_(false),
327 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15328 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01329 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02330 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38331 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21332 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
333 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00334 temporary_zoom_settings_(false),
[email protected]cb805452013-05-22 15:16:21335 color_chooser_identifier_(0),
[email protected]f114fa42013-12-06 17:06:44336 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42337 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
338 is_subframe_(false) {
[email protected]cbb1ef592013-06-05 19:49:46339 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
340 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55341 frame_tree_.SetFrameRemoveListener(
342 base::Bind(&WebContentsImpl::OnFrameRemoved,
343 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35344}
initial.commit09911bf2008-07-26 23:55:29345
[email protected]b172aee2012-04-10 17:05:26346WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32347 is_being_destroyed_ = true;
348
[email protected]21b41c7e892014-02-28 01:52:24349 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
350 // shutdown and be deleted as well.
351 frame_tree_.ForEach(
352 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
353
[email protected]d9030b82013-07-19 08:26:06354 ClearAllPowerSaveBlockers();
355
[email protected]b24b68a2012-09-24 21:57:26356 for (std::set<RenderWidgetHostImpl*>::iterator iter =
357 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
358 (*iter)->DetachDelegate();
359 }
360 created_widgets_.clear();
361
[email protected]3ab9cb82011-06-03 18:02:07362 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15363 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11364 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07365
[email protected]da8543762012-03-20 08:52:20366 if (color_chooser_)
367 color_chooser_->End();
368
[email protected]420ae012009-04-24 05:16:32369 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32370
[email protected]ca13a442012-04-17 14:00:12371 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21372 NotificationService::current()->Notify(
373 NOTIFICATION_WEB_CONTENTS_DESTROYED,
374 Source<WebContents>(this),
375 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32376
[email protected]c06c58c2014-03-12 20:31:59377 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
378 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
379 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
380 run_render_frame_deleted_callback));
381
[email protected]fa944cb82013-11-15 17:51:21382 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27383 if (pending_rvh) {
384 FOR_EACH_OBSERVER(WebContentsObserver,
385 observers_,
386 RenderViewDeleted(pending_rvh));
387 }
388
[email protected]c06c58c2014-03-12 20:31:59389 ForEachFrame(run_render_frame_deleted_callback);
390
[email protected]f273ee52013-10-18 16:05:27391 FOR_EACH_OBSERVER(WebContentsObserver,
392 observers_,
[email protected]fa944cb82013-11-15 17:51:21393 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27394
[email protected]2db9bd72012-04-13 20:20:56395 FOR_EACH_OBSERVER(WebContentsObserver,
396 observers_,
397 WebContentsImplDestroyed());
[email protected]232a5812011-03-04 22:42:08398
[email protected]6934a702011-12-20 00:04:51399 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10400
401 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
402 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42403}
404
[email protected]d1198fd2012-08-13 22:50:19405WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59406 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19407 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03408 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59409 WebContentsImpl* new_contents = new WebContentsImpl(
410 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19411
[email protected]54944cde2012-12-09 09:24:59412 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19413 return new_contents;
414}
415
[email protected]b371a5652013-02-20 11:25:51416// static
[email protected]8eb04562013-03-06 03:41:14417BrowserPluginGuest* WebContentsImpl::CreateGuest(
[email protected]dd8c8232012-11-03 00:49:36418 BrowserContext* browser_context,
[email protected]1bc28312012-11-08 08:31:53419 SiteInstance* site_instance,
[email protected]738f57a2013-06-29 21:06:54420 int guest_instance_id,
421 scoped_ptr<base::DictionaryValue> extra_params) {
[email protected]6706b8da2013-03-19 13:20:39422 WebContentsImpl* new_contents = new WebContentsImpl(browser_context, NULL);
[email protected]7a846df2012-09-20 19:17:39423
424 // This makes |new_contents| act as a guest.
425 // For more info, see comment above class BrowserPluginGuest.
[email protected]738f57a2013-06-29 21:06:54426 BrowserPluginGuest::Create(
[email protected]dbbce92c2013-10-31 16:51:19427 guest_instance_id, site_instance, new_contents, extra_params.Pass());
[email protected]b5a40842012-11-28 15:26:11428
[email protected]3de10bb32013-01-08 21:57:33429 WebContents::CreateParams create_params(browser_context, site_instance);
[email protected]3de10bb32013-01-08 21:57:33430 new_contents->Init(create_params);
[email protected]b5a40842012-11-28 15:26:11431
[email protected]216be772013-01-25 00:22:27432 // We are instantiating a WebContents for browser plugin. Set its subframe bit
433 // to true.
[email protected]5dcaf8e2013-12-28 01:31:42434 new_contents->is_subframe_ = true;
[email protected]216be772013-01-25 00:22:27435
[email protected]8eb04562013-03-06 03:41:14436 return new_contents->browser_plugin_guest_.get();
[email protected]7a846df2012-09-20 19:17:39437}
438
[email protected]b0936d22013-11-28 06:47:36439RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21440 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28441}
442
[email protected]7bb761892012-07-20 09:32:47443bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
444 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44445 return OnMessageReceived(render_view_host, NULL, message);
446}
447
448bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
449 RenderFrameHost* render_frame_host,
450 const IPC::Message& message) {
451 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56452 if (GetWebUI() &&
453 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17454 return true;
[email protected]d2353452012-01-19 19:53:56455 }
[email protected]f82d57b52011-04-27 19:13:17456
[email protected]d8c660432011-12-22 20:51:25457 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
458 WebContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10459 while ((observer = it.GetNext()) != NULL)
460 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53461 return true;
[email protected]403415a2011-01-10 18:57:53462
[email protected]1d62cf72014-02-07 21:31:57463 // Message handlers should be aware of which
464 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
465 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43466 if (render_frame_host) {
467 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
468 render_frame_host->GetRenderViewHost(), message))
469 return true;
[email protected]1d62cf72014-02-07 21:31:57470 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43471 } else {
472 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
473 render_view_host, message))
474 return true;
[email protected]1d62cf72014-02-07 21:31:57475 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43476 }
[email protected]1d62cf72014-02-07 21:31:57477
[email protected]724159a2010-12-30 01:11:18478 bool handled = true;
479 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26480 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44481 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
482 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40483 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
484 OnDomOperationResponse)
[email protected]724159a2010-12-30 01:11:18485 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
486 OnDidLoadResourceFromMemoryCache)
487 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
488 OnDidDisplayInsecureContent)
489 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
490 OnDidRunInsecureContent)
[email protected]1d62cf72014-02-07 21:31:57491 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
[email protected]724159a2010-12-30 01:11:18492 OnDocumentLoadedInFrame)
[email protected]028053d42014-03-05 22:20:37493 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]7d472472011-01-22 01:30:25494 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26495 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21496 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20497 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);
[email protected]657c8e02014-03-19 19:18:371259
1260 FOR_EACH_OBSERVER(WebContentsObserver,
1261 observers_,
1262 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471263}
1264
[email protected]b172aee2012-04-10 17:05:261265bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381266 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121267}
1268
[email protected]a9c81f02012-06-01 00:15:441269void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1270 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371271 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441272 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371273 } else {
1274 GotResponseToLockMouseRequest(false);
1275 }
1276}
1277
[email protected]b172aee2012-04-10 17:05:261278void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371279 if (delegate_)
1280 delegate_->LostMouseLock();
1281}
1282
[email protected]bafe6cd2012-05-23 23:09:501283void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201284 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501285 int route_id,
[email protected]227692c52013-05-31 22:43:041286 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131287 const ViewHostMsg_CreateWindow_Params& params,
1288 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501289 // We usually create the new window in the same BrowsingInstance (group of
1290 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551291 // if the opener is being suppressed (in a non-guest), we create a new
1292 // SiteInstance in its own BrowsingInstance.
1293 bool is_guest = GetRenderProcessHost()->IsGuest();
1294
[email protected]04cbd3d2013-12-04 04:58:201295 // If the opener is to be suppressed, the new window can be in any process.
1296 // Since routing ids are process specific, we must not have one passed in
1297 // as argument here.
1298 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1299
[email protected]bafe6cd2012-05-23 23:09:501300 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551301 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571302 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501303 GetSiteInstance();
1304
[email protected]04cbd3d2013-12-04 04:58:201305 // A message to create a new window can only come from the active process for
1306 // this WebContentsImpl instance. If any other process sends the request,
1307 // it is invalid and the process must be terminated.
1308 if (GetRenderProcessHost()->GetID() != render_process_id) {
1309 base::ProcessHandle process_handle =
1310 RenderProcessHost::FromID(render_process_id)->GetHandle();
1311 if (process_handle != base::kNullProcessHandle) {
1312 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391313 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201314 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1315 }
1316 return;
1317 }
1318
[email protected]d1198fd2012-08-13 22:50:191319 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341320 //
1321 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301322 const std::string& partition_id =
1323 GetContentClient()->browser()->
1324 GetStoragePartitionIdForSite(GetBrowserContext(),
1325 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461326 StoragePartition* partition = BrowserContext::GetStoragePartition(
1327 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411328 DOMStorageContextWrapper* dom_storage_context =
1329 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191330 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1331 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1332 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371333
1334 if (delegate_ &&
1335 !delegate_->ShouldCreateWebContents(this,
1336 route_id,
1337 params.window_container_type,
1338 params.frame_name,
1339 params.target_url,
1340 partition_id,
1341 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011342 if (route_id != MSG_ROUTING_NONE &&
1343 !RenderViewHost::FromID(render_process_id, route_id)) {
1344 // If the embedder didn't create a WebContents for this route, we need to
1345 // delete the RenderView that had already been created.
1346 Send(new ViewMsg_Close(route_id));
1347 }
[email protected]dd6730412013-08-14 15:03:371348 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1349 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1350 main_frame_route_id);
1351 return;
1352 }
1353
1354 // Create the new web contents. This will automatically create the new
1355 // WebContentsView. In the future, we may want to create the view separately.
1356 WebContentsImpl* new_contents =
1357 new WebContentsImpl(GetBrowserContext(),
1358 params.opener_suppressed ? NULL : this);
1359
[email protected]d1198fd2012-08-13 22:50:191360 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301361 partition_id,
[email protected]d1198fd2012-08-13 22:50:191362 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461363 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591364 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041365 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551366 if (!is_guest) {
1367 create_params.context = view_->GetNativeView();
1368 create_params.initial_size = view_->GetContainerSize();
1369 } else {
1370 // This makes |new_contents| act as a guest.
1371 // For more info, see comment above class BrowserPluginGuest.
1372 int instance_id = GetBrowserPluginGuestManager()->get_next_instance_id();
1373 WebContentsImpl* new_contents_impl =
1374 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461375 BrowserPluginGuest::CreateWithOpener(instance_id,
1376 new_contents_impl->opener() != NULL,
1377 new_contents_impl,
1378 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551379 }
[email protected]1ac10dca2013-08-20 20:47:041380 if (params.disposition == NEW_BACKGROUND_TAB)
1381 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591382 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191383
[email protected]c4538072013-03-18 02:17:551384 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341385 // will be shown immediately).
1386 if (!params.opener_suppressed) {
1387 if (!is_guest) {
1388 WebContentsViewPort* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501389
[email protected]d70bea92013-04-05 04:23:341390 // TODO(brettw): It seems bogus that we have to call this function on the
1391 // newly created object and give it one of its own member variables.
1392 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1393 }
[email protected]bafe6cd2012-05-23 23:09:501394 // Save the created window associated with the route so we can show it
1395 // later.
1396 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1397 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101398 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501399 }
1400
1401 if (delegate_) {
1402 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071403 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131404 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501405 }
1406
1407 if (params.opener_suppressed) {
1408 // When the opener is suppressed, the original renderer cannot access the
1409 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001410 bool was_blocked = false;
1411 if (delegate_) {
1412 gfx::Rect initial_pos;
1413 delegate_->AddNewContents(
1414 this, new_contents, params.disposition, initial_pos,
1415 params.user_gesture, &was_blocked);
1416 }
1417 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211418 OpenURLParams open_params(params.target_url,
1419 Referrer(),
1420 CURRENT_TAB,
1421 PAGE_TRANSITION_LINK,
1422 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301423 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001424 new_contents->OpenURL(open_params);
1425 }
[email protected]bafe6cd2012-05-23 23:09:501426 }
1427}
1428
[email protected]a8504022013-12-04 20:23:511429void WebContentsImpl::CreateNewWidget(int render_process_id,
1430 int route_id,
[email protected]180ef242013-11-07 06:50:461431 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511432 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501433}
1434
[email protected]a8504022013-12-04 20:23:511435void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1436 int route_id) {
1437 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501438}
1439
[email protected]a8504022013-12-04 20:23:511440void WebContentsImpl::CreateNewWidget(int render_process_id,
1441 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501442 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461443 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211444 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511445 // A message to create a new widget can only come from the active process for
1446 // this WebContentsImpl instance. If any other process sends the request,
1447 // it is invalid and the process must be terminated.
1448 if (process->GetID() != render_process_id) {
1449 base::ProcessHandle process_handle =
1450 RenderProcessHost::FromID(render_process_id)->GetHandle();
1451 if (process_handle != base::kNullProcessHandle) {
1452 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391453 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511454 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1455 }
1456 return;
1457 }
1458
[email protected]bafe6cd2012-05-23 23:09:501459 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041460 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261461 created_widgets_.insert(widget_host);
1462
[email protected]83918ec2013-01-10 15:37:191463 RenderWidgetHostViewPort* widget_view = RenderWidgetHostViewPort::FromRWHV(
1464 view_->CreateViewForPopupWidget(widget_host));
1465 if (!widget_view)
1466 return;
[email protected]bafe6cd2012-05-23 23:09:501467 if (!is_fullscreen) {
1468 // Popups should not get activated.
1469 widget_view->SetPopupType(popup_type);
1470 }
1471 // Save the created widget associated with the route so we can show it later.
1472 pending_widget_views_[route_id] = widget_view;
1473
1474#if defined(OS_MACOSX)
1475 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1476 // to allow it to survive the trip without being hosted.
1477 base::mac::NSObjectRetain(widget_view->GetNativeView());
1478#endif
1479}
1480
1481void WebContentsImpl::ShowCreatedWindow(int route_id,
1482 WindowOpenDisposition disposition,
1483 const gfx::Rect& initial_pos,
1484 bool user_gesture) {
1485 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001486 if (contents) {
1487 WebContentsDelegate* delegate = GetDelegate();
1488 if (delegate) {
1489 delegate->AddNewContents(
1490 this, contents, disposition, initial_pos, user_gesture, NULL);
1491 }
1492 }
[email protected]bafe6cd2012-05-23 23:09:501493}
1494
1495void WebContentsImpl::ShowCreatedWidget(int route_id,
1496 const gfx::Rect& initial_pos) {
1497 ShowCreatedWidget(route_id, false, initial_pos);
1498}
1499
1500void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1501 ShowCreatedWidget(route_id, true, gfx::Rect());
1502}
1503
1504void WebContentsImpl::ShowCreatedWidget(int route_id,
1505 bool is_fullscreen,
1506 const gfx::Rect& initial_pos) {
[email protected]bafe6cd2012-05-23 23:09:501507 RenderWidgetHostViewPort* widget_host_view =
1508 RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id));
1509 if (!widget_host_view)
1510 return;
[email protected]4aebbca2013-09-17 22:26:491511 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311512 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1513 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491514 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1515 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1516 delegate_->ToggleFullscreenModeForTab(this, true);
1517 } else {
1518 widget_host_view->InitAsFullscreen(GetRenderWidgetHostViewPort());
[email protected]4aebbca2013-09-17 22:26:491519 }
[email protected]4aebbca2013-09-17 22:26:491520 FOR_EACH_OBSERVER(WebContentsObserver,
1521 observers_,
1522 DidShowFullscreenWidget(route_id));
1523 if (!widget_host_view->HasFocus())
1524 widget_host_view->Focus();
1525 } else {
[email protected]f8497342013-02-05 22:15:021526 widget_host_view->InitAsPopup(GetRenderWidgetHostViewPort(), initial_pos);
[email protected]4aebbca2013-09-17 22:26:491527 }
[email protected]89054502012-06-03 10:29:241528
1529 RenderWidgetHostImpl* render_widget_host_impl =
1530 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1531 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311532 // Only allow privileged mouse lock for fullscreen render widget, which is
1533 // used to implement Pepper Flash fullscreen.
1534 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501535
1536#if defined(OS_MACOSX)
1537 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1538 // properly embedded (or purposefully ignored) we can release the retain we
1539 // took in CreateNewWidget().
1540 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1541#endif
1542}
1543
1544WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1545 PendingContents::iterator iter = pending_contents_.find(route_id);
1546
1547 // Certain systems can block the creation of new windows. If we didn't succeed
1548 // in creating one, just return NULL.
1549 if (iter == pending_contents_.end()) {
1550 return NULL;
1551 }
1552
1553 WebContentsImpl* new_contents = iter->second;
1554 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101555 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501556
[email protected]d70bea92013-04-05 04:23:341557 // Don't initialize the guest WebContents immediately.
1558 if (new_contents->GetRenderProcessHost()->IsGuest())
1559 return new_contents;
1560
[email protected]bafe6cd2012-05-23 23:09:501561 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1562 !new_contents->GetRenderViewHost()->GetView())
1563 return NULL;
1564
1565 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1566 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1567 return new_contents;
1568}
1569
1570RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1571 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1572 if (iter == pending_widget_views_.end()) {
1573 DCHECK(false);
1574 return NULL;
1575 }
1576
1577 RenderWidgetHostView* widget_host_view = iter->second;
1578 pending_widget_views_.erase(route_id);
1579
1580 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1581 if (!widget_host->GetProcess()->HasConnection()) {
1582 // The view has gone away or the renderer crashed. Nothing to do.
1583 return NULL;
1584 }
1585
1586 return widget_host_view;
1587}
1588
[email protected]f13b4202012-06-12 23:53:231589void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091590 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211591 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371592 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231593 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371594 } else {
1595 callback.Run(MediaStreamDevices(),
1596 MEDIA_DEVICE_INVALID_STATE,
1597 scoped_ptr<MediaStreamUI>());
1598 }
[email protected]f13b4202012-06-12 23:53:231599}
1600
[email protected]cc9200432013-07-23 23:02:401601SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1602 SiteInstance* instance) {
1603 return controller_.GetSessionStorageNamespace(instance);
1604}
1605
[email protected]9b159a52013-10-03 17:24:551606FrameTree* WebContentsImpl::GetFrameTree() {
1607 return &frame_tree_;
1608}
1609
[email protected]31a71eaf2014-03-13 01:47:361610void WebContentsImpl::AccessibilityEventReceived(
1611 const std::vector<AXEventNotificationDetails>& details) {
1612 FOR_EACH_OBSERVER(
1613 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1614}
1615
[email protected]edc3af82013-12-12 21:24:071616void WebContentsImpl::OnShowValidationMessage(
1617 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291618 const base::string16& main_text,
1619 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071620 if (delegate_)
1621 delegate_->ShowValidationMessage(
1622 this, anchor_in_root_view, main_text, sub_text);
1623}
1624
1625void WebContentsImpl::OnHideValidationMessage() {
1626 if (delegate_)
1627 delegate_->HideValidationMessage(this);
1628}
1629
1630void WebContentsImpl::OnMoveValidationMessage(
1631 const gfx::Rect& anchor_in_root_view) {
1632 if (delegate_)
1633 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1634}
1635
[email protected]32deec62013-05-15 23:55:041636void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1637 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441638 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041639}
1640
[email protected]b172aee2012-04-10 17:05:261641void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491642 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231643 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491644 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331645}
1646
[email protected]b172aee2012-04-10 17:05:261647void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341648 if (delegate_)
1649 delegate_->ResizeDueToAutoResize(this, new_size);
1650}
1651
[email protected]b172aee2012-04-10 17:05:261652WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201653 if (!delegate_)
1654 return NULL;
[email protected]00c37fc2011-08-02 00:22:501655
[email protected]e5d549d2011-12-28 01:29:201656 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201657 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341658}
1659
[email protected]6b618e62012-08-16 12:59:181660bool WebContentsImpl::Send(IPC::Message* message) {
1661 if (!GetRenderViewHost()) {
1662 delete message;
1663 return false;
1664 }
1665
1666 return GetRenderViewHost()->Send(message);
1667}
1668
[email protected]b172aee2012-04-10 17:05:261669bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501670 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261671 FrameTreeNode* node = frame_tree_.root();
1672
1673 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1674 // specified in the pending entry.
1675 NavigationEntryImpl* pending_entry =
1676 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1677 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1678 pending_entry->frame_tree_node_id() != -1) {
1679 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1680 }
1681
1682 return node->navigator()->NavigateToPendingEntry(
1683 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541684}
[email protected]96d185d2009-04-24 03:28:541685
[email protected]a86c0e962013-12-17 17:10:391686void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1687 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441688 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391689 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441690}
1691
[email protected]20ca0382013-02-28 19:50:071692void WebContentsImpl::AttachInterstitialPage(
1693 InterstitialPageImpl* interstitial_page) {
1694 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211695 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291696
1697 // Cancel any visible dialogs so that they don't interfere with the
1698 // interstitial.
1699 if (dialog_manager_)
1700 dialog_manager_->CancelActiveAndPendingDialogs(this);
1701
[email protected]20ca0382013-02-28 19:50:071702 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1703 DidAttachInterstitialPage());
1704}
1705
1706void WebContentsImpl::DetachInterstitialPage() {
1707 if (GetInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211708 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071709 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1710 DidDetachInterstitialPage());
1711}
1712
[email protected]b172aee2012-04-10 17:05:261713void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331714 const SiteInstance* site_instance,
1715 int history_length,
1716 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411717 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1718 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211719 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191720 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141721 return;
[email protected]9e1ad4b2011-08-14 16:49:191722 }
[email protected]9f76c1e2012-03-05 15:15:581723 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191724 if (!rvh) {
1725 NOTREACHED();
1726 return;
1727 }
[email protected]9f76c1e2012-03-05 15:15:581728 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191729 NOTREACHED();
1730 return;
1731 }
[email protected]6b618e62012-08-16 12:59:181732 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1733 history_length,
1734 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141735}
1736
[email protected]b172aee2012-04-10 17:05:261737void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271738 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211739 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541740 return;
1741 }
[email protected]9f76c1e2012-03-05 15:15:581742 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541743}
1744
[email protected]b172aee2012-04-10 17:05:261745bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211746 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541747}
1748
[email protected]b172aee2012-04-10 17:05:261749InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211750 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221751}
1752
[email protected]b172aee2012-04-10 17:05:261753bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161754 // WebKit creates Document object when MIME type is application/xhtml+xml,
1755 // so we also support this MIME type.
1756 return contents_mime_type_ == "text/html" ||
1757 contents_mime_type_ == "text/xml" ||
1758 contents_mime_type_ == "application/xhtml+xml" ||
1759 contents_mime_type_ == "text/plain" ||
1760 contents_mime_type_ == "text/css" ||
1761 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
1762}
1763
[email protected]b172aee2012-04-10 17:05:261764void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:591765 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:161766 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:551767 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:011768 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:141769 return;
[email protected]c7dd2f62011-07-18 15:57:591770 }
1771
1772 Stop();
1773
1774 // Create the save package and possibly prompt the user for the name to save
1775 // the page as. The user prompt is an asynchronous operation that runs on
1776 // another thread.
1777 save_package_ = new SavePackage(this);
1778 save_package_->GetSaveInfo();
1779}
1780
1781// Used in automated testing to bypass prompting the user for file names.
1782// Instead, the names and paths are hard coded rather than running them through
1783// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:341784bool WebContentsImpl::SavePage(const base::FilePath& main_file,
1785 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:211786 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:591787 // Stop the page from navigating.
1788 Stop();
1789
1790 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:211791 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:591792}
1793
[email protected]3c71576ce2013-07-23 02:00:011794void WebContentsImpl::SaveFrame(const GURL& url,
1795 const Referrer& referrer) {
1796 if (!GetURL().is_valid())
1797 return;
1798 bool is_main_frame = (url == GetURL());
1799
1800 DownloadManager* dlm =
1801 BrowserContext::GetDownloadManager(GetBrowserContext());
1802 if (!dlm)
1803 return;
1804 int64 post_id = -1;
1805 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:271806 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:011807 if (entry)
1808 post_id = entry->GetPostID();
1809 }
1810 scoped_ptr<DownloadUrlParameters> params(
1811 DownloadUrlParameters::FromWebContents(this, url));
1812 params->set_referrer(referrer);
1813 params->set_post_id(post_id);
1814 params->set_prefer_cache(true);
1815 if (post_id >= 0)
1816 params->set_method("POST");
1817 params->set_prompt(true);
1818 dlm->DownloadUrl(params.Pass());
1819}
1820
[email protected]b172aee2012-04-10 17:05:261821void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:341822 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:481823 const base::Callback<void(int64)>& callback) {
1824 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:121825}
1826
[email protected]6286a372013-10-09 04:03:271827// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:261828bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:271829 NavigationEntryImpl* visible_entry =
1830 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
1831 return (visible_entry != NULL &&
1832 visible_entry->site_instance() == GetSiteInstance() &&
1833 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:321834}
1835
[email protected]b172aee2012-04-10 17:05:261836const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:271837 return contents_mime_type_;
1838}
1839
[email protected]b172aee2012-04-10 17:05:261840bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:271841 return notify_disconnection_;
1842}
1843
[email protected]b172aee2012-04-10 17:05:261844void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:311845 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:181846 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:161847}
1848
[email protected]b172aee2012-04-10 17:05:261849void WebContentsImpl::ResetOverrideEncoding() {
[email protected]be1f56ab2011-12-22 06:55:311850 encoding_.clear();
[email protected]6b618e62012-08-16 12:59:181851 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:161852}
1853
[email protected]8ff00d72012-10-23 19:12:211854RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:271855 return &renderer_preferences_;
1856}
1857
[email protected]e35ccd52012-05-23 16:22:471858void WebContentsImpl::Close() {
1859 Close(GetRenderViewHost());
1860}
1861
[email protected]cf200a562013-05-03 16:24:291862void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:461863 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:291864 if (browser_plugin_embedder_.get())
1865 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
1866 screen_x, screen_y, operation);
1867 if (GetRenderViewHost())
1868 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
1869 screen_x, screen_y, operation);
1870}
1871
1872void WebContentsImpl::DragSourceMovedTo(int client_x, int client_y,
1873 int screen_x, int screen_y) {
1874 if (browser_plugin_embedder_.get())
1875 browser_plugin_embedder_->DragSourceMovedTo(client_x, client_y,
1876 screen_x, screen_y);
1877 if (GetRenderViewHost())
1878 GetRenderViewHostImpl()->DragSourceMovedTo(client_x, client_y,
1879 screen_x, screen_y);
1880}
1881
[email protected]d60f3702013-12-26 16:30:241882void WebContentsImpl::DidGetResourceResponseStart(
1883 const ResourceRequestDetails& details) {
1884 controller_.ssl_manager()->DidStartResourceResponse(details);
1885
1886 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1887 DidGetResourceResponseStart(details));
1888
1889 // TODO(avi): Remove. http://crbug.com/170921
1890 NotificationService::current()->Notify(
1891 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
1892 Source<WebContents>(this),
1893 Details<const ResourceRequestDetails>(&details));
1894}
1895
1896void WebContentsImpl::DidGetRedirectForResourceRequest(
1897 RenderViewHost* render_view_host,
1898 const ResourceRedirectDetails& details) {
1899 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
1900
1901 FOR_EACH_OBSERVER(
1902 WebContentsObserver,
1903 observers_,
1904 DidGetRedirectForResourceRequest(render_view_host, details));
1905
1906 // TODO(avi): Remove. http://crbug.com/170921
1907 NotificationService::current()->Notify(
1908 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
1909 Source<WebContents>(this),
1910 Details<const ResourceRedirectDetails>(&details));
1911}
1912
[email protected]b172aee2012-04-10 17:05:261913void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:521914 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:581915 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:511916 if (delegate_)
1917 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:291918 if (browser_plugin_embedder_.get())
1919 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:341920}
1921
[email protected]e35ccd52012-05-23 16:22:471922void WebContentsImpl::UserGestureDone() {
1923 OnUserGesture();
1924}
1925
[email protected]b172aee2012-04-10 17:05:261926void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:271927 closed_by_user_gesture_ = value;
1928}
1929
[email protected]b172aee2012-04-10 17:05:261930bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:271931 return closed_by_user_gesture_;
1932}
1933
[email protected]b172aee2012-04-10 17:05:261934double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:051935 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:561936 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:251937 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171938 return 0;
[email protected]b75b8292010-10-01 07:28:251939
1940 double zoom_level;
1941 if (temporary_zoom_settings_) {
1942 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:581943 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:251944 } else {
[email protected]2ae88d12011-10-14 09:11:191945 GURL url;
[email protected]6286a372013-10-09 04:03:271946 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:191947 // Since zoom map is updated using rewritten URL, use rewritten URL
1948 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:271949 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:021950 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
1951 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:251952 }
[email protected]d0b8d092010-10-25 04:05:171953 return zoom_level;
1954}
[email protected]b75b8292010-10-01 07:28:251955
[email protected]b172aee2012-04-10 17:05:261956int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:591957 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:171958 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:011959 // Calculate the zoom percent from the factor. Round up to the nearest whole
1960 // number.
[email protected]b75b8292010-10-01 07:28:251961 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:491962 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:251963 *enable_decrement = percent > minimum_zoom_percent_;
1964 *enable_increment = percent < maximum_zoom_percent_;
1965 return percent;
1966}
1967
[email protected]b172aee2012-04-10 17:05:261968void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:501969 if (!delegate_)
1970 return;
1971
[email protected]6286a372013-10-09 04:03:271972 NavigationEntry* entry = GetController().GetLastCommittedEntry();
1973 if (!entry)
[email protected]1788e772010-12-15 16:40:501974 return;
1975
[email protected]6286a372013-10-09 04:03:271976 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:121977}
1978
[email protected]b172aee2012-04-10 17:05:261979void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:041980 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:271981 if (!delegate_)
1982 return;
1983
[email protected]691aa2f2013-05-28 22:52:041984 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:271985}
1986
[email protected]b172aee2012-04-10 17:05:261987int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271988 return minimum_zoom_percent_;
1989}
1990
[email protected]b172aee2012-04-10 17:05:261991int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:271992 return maximum_zoom_percent_;
1993}
1994
[email protected]b172aee2012-04-10 17:05:261995gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:491996 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:231997}
1998
[email protected]b172aee2012-04-10 17:05:261999bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272000 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582001 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272002}
2003
[email protected]b172aee2012-04-10 17:05:262004bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442005 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502006}
2007
[email protected]cb805452013-05-22 15:16:212008void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]6b618e62012-08-16 12:59:182009 Send(new ViewMsg_DidChooseColorResponse(
[email protected]cb805452013-05-22 15:16:212010 GetRoutingID(), color_chooser_identifier_, color));
[email protected]da8543762012-03-20 08:52:202011}
2012
[email protected]cb805452013-05-22 15:16:212013void WebContentsImpl::DidEndColorChooser() {
2014 Send(new ViewMsg_DidEndColorChooser(GetRoutingID(),
2015 color_chooser_identifier_));
2016 color_chooser_.reset();
2017 color_chooser_identifier_ = 0;
[email protected]da8543762012-03-20 08:52:202018}
2019
[email protected]41225fe2013-03-29 05:32:022020int WebContentsImpl::DownloadImage(const GURL& url,
2021 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302022 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022023 const ImageDownloadCallback& callback) {
[email protected]795c28972012-12-06 06:13:392024 RenderViewHost* host = GetRenderViewHost();
[email protected]263cb08f2013-09-18 00:26:302025 int id = StartDownload(host, url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022026 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392027 return id;
2028}
2029
[email protected]5dcaf8e2013-12-28 01:31:422030bool WebContentsImpl::IsSubframe() const {
2031 return is_subframe_;
2032}
2033
[email protected]9649d492014-01-10 07:15:522034void WebContentsImpl::SetZoomLevel(double level) {
2035 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2036 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2037 if (embedder)
2038 embedder->SetZoomLevel(level);
2039}
2040
[email protected]36ec24f2014-01-09 00:32:082041void WebContentsImpl::Find(int request_id,
2042 const base::string16& search_text,
2043 const blink::WebFindOptions& options) {
2044 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2045}
2046
2047void WebContentsImpl::StopFinding(StopFindAction action) {
2048 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2049}
2050
[email protected]b172aee2012-04-10 17:05:262051bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272052 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202053 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332054 return true;
2055 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272056}
2057
[email protected]b172aee2012-04-10 17:05:262058void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272059 if (delegate_)
2060 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212061}
2062
[email protected]52913802013-12-10 05:52:182063void WebContentsImpl::DidStartProvisionalLoad(
2064 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072065 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182066 const GURL& validated_url,
2067 bool is_error_page,
2068 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262069 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182070 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572071 DidChangeLoadProgress(0);
2072
[email protected]0d60f0192011-04-14 12:40:102073 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272074 int render_frame_id = render_frame_host->GetRoutingID();
2075 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252076 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072077 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272078 render_frame_id, parent_routing_id, is_main_frame,
2079 validated_url, is_error_page, is_iframe_srcdoc,
2080 render_view_host));
[email protected]400992b2012-06-14 00:03:542081
2082 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182083 FOR_EACH_OBSERVER(
2084 WebContentsObserver,
2085 observers_,
2086 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582087 render_frame_host));
[email protected]400992b2012-06-14 00:03:542088 }
2089}
2090
[email protected]3109fbb72014-01-06 23:57:152091void WebContentsImpl::DidFailProvisionalLoadWithError(
2092 RenderFrameHostImpl* render_frame_host,
2093 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2094 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272095 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262096 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272097 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152098 FOR_EACH_OBSERVER(
2099 WebContentsObserver,
2100 observers_,
[email protected]161eabd2014-03-19 19:47:272101 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152102 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262103 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152104 validated_url,
2105 params.error_code,
2106 params.error_description,
[email protected]161eabd2014-03-19 19:47:272107 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152108}
2109
[email protected]b80624c2014-02-09 02:46:552110void WebContentsImpl::DidFailLoadWithError(
2111 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552112 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552113 int error_code,
2114 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272115 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262116 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272117 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552118 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272119 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262120 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552121}
2122
[email protected]52913802013-12-10 05:52:182123void WebContentsImpl::NotifyChangedNavigationState(
2124 InvalidateTypes changed_flags) {
2125 NotifyNavigationStateChanged(changed_flags);
2126}
2127
[email protected]3691e5cf2014-01-22 10:16:202128void WebContentsImpl::AboutToNavigateRenderFrame(
2129 RenderFrameHostImpl* render_frame_host) {
2130 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272131 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202132 FOR_EACH_OBSERVER(
2133 WebContentsObserver,
2134 observers_,
[email protected]161eabd2014-03-19 19:47:272135 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202136}
2137
2138void WebContentsImpl::DidStartNavigationToPendingEntry(
2139 RenderFrameHostImpl* render_frame_host,
2140 const GURL& url,
2141 NavigationController::ReloadType reload_type) {
2142 // Notify observers about navigation.
2143 FOR_EACH_OBSERVER(
2144 WebContentsObserver,
2145 observers_,
2146 DidStartNavigationToPendingEntry(url, reload_type));
2147}
2148
[email protected]8cb834e2014-03-06 14:23:232149void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2150 const OpenURLParams& params) {
2151 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182152 WebContents* new_contents = OpenURL(params);
2153
2154 if (new_contents) {
2155 // Notify observers.
2156 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2157 DidOpenRequestedURL(new_contents,
2158 params.url,
2159 params.referrer,
2160 params.disposition,
2161 params.transition,
[email protected]8cb834e2014-03-06 14:23:232162 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182163 }
2164}
2165
[email protected]400992b2012-06-14 00:03:542166void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582167 RenderFrameHostImpl* render_frame_host,
2168 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542169 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582170 FOR_EACH_OBSERVER(
2171 WebContentsObserver,
2172 observers_,
2173 ProvisionalChangeToMainFrameUrl(validated_target_url,
2174 render_frame_host));
[email protected]724159a2010-12-30 01:11:182175}
2176
[email protected]37567b432014-02-12 01:12:222177void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432178 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222179 const base::string16& frame_unique_name,
2180 bool is_main_frame,
2181 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432182 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432183 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272184 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222185 // Notify observers about the commit of the provisional load.
2186 FOR_EACH_OBSERVER(
2187 WebContentsObserver,
2188 observers_,
[email protected]27dd82fd2014-03-03 22:11:432189 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222190 frame_unique_name,
2191 is_main_frame,
2192 url,
2193 transition_type,
2194 render_view_host));
2195}
2196
2197void WebContentsImpl::DidNavigateMainFramePostCommit(
2198 const LoadCommittedDetails& details,
2199 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2200 if (details.is_navigation_to_different_page()) {
2201 // Clear the status bubble. This is a workaround for a bug where WebKit
2202 // doesn't let us know that the cursor left an element during a
2203 // transition (this is also why the mouse cursor remains as a hand after
2204 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2205 // clear the bubble when a user navigates to a named anchor in the same
2206 // page.
2207 UpdateTargetURL(details.entry->GetPageID(), GURL());
2208 }
2209
2210 if (!details.is_in_page) {
2211 // Once the main frame is navigated, we're no longer considered to have
2212 // displayed insecure content.
2213 displayed_insecure_content_ = false;
2214 SSLManager::NotifySSLInternalStateChanged(
2215 GetController().GetBrowserContext());
2216 }
2217
2218 // Notify observers about navigation.
2219 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2220 DidNavigateMainFrame(details, params));
2221
2222 if (delegate_) {
2223 delegate_->DidNavigateMainFramePostCommit(this);
2224 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2225 }
2226}
2227
2228void WebContentsImpl::DidNavigateAnyFramePostCommit(
2229 RenderFrameHostImpl* render_frame_host,
2230 const LoadCommittedDetails& details,
2231 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2232 // If we navigate off the page, close all JavaScript dialogs.
2233 if (dialog_manager_ && !details.is_in_page)
2234 dialog_manager_->CancelActiveAndPendingDialogs(this);
2235
2236 // Notify observers about navigation.
2237 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2238 DidNavigateAnyFrame(details, params));
2239}
2240
2241void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2242 contents_mime_type_ = mime_type;
2243}
2244
2245bool WebContentsImpl::CanOverscrollContent() {
2246 if (delegate_)
2247 return delegate_->CanOverscrollContent();
2248
2249 return false;
2250}
2251
[email protected]b172aee2012-04-10 17:05:262252void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182253 const GURL& url,
[email protected]70435962011-08-02 20:13:282254 const std::string& security_info,
2255 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182256 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282257 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192258 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182259 cache.Increment();
2260
2261 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082262 int cert_id = 0;
2263 net::CertStatus cert_status = 0;
2264 int security_bits = -1;
2265 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122266 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212267 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122268 &security_bits, &connection_status,
2269 &signed_certificate_timestamp_ids);
2270 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212271 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002272 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2273 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182274
[email protected]b0f724c2013-09-05 04:21:132275 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2276
2277 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2278 DidLoadResourceFromMemoryCache(details));
2279
[email protected]8bfc8272013-09-09 20:10:532280 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2281 scoped_refptr<net::URLRequestContextGetter> request_context(
2282 resource_type == ResourceType::MEDIA ?
2283 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2284 GetRenderProcessHost()->GetID()) :
2285 GetBrowserContext()->GetRequestContextForRenderProcess(
2286 GetRenderProcessHost()->GetID()));
2287 BrowserThread::PostTask(
2288 BrowserThread::IO,
2289 FROM_HERE,
2290 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2291 }
[email protected]724159a2010-12-30 01:11:182292}
2293
[email protected]b172aee2012-04-10 17:05:262294void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392295 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182296 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192297 SSLManager::NotifySSLInternalStateChanged(
2298 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182299}
2300
[email protected]b172aee2012-04-10 17:05:262301void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022302 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582303 LOG(WARNING) << security_origin << " ran insecure content from "
2304 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392305 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412306 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392307 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182308 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412309 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192310 SSLManager::NotifySSLInternalStateChanged(
2311 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182312}
2313
[email protected]501052ff2014-02-21 22:19:072314void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572315 CHECK(render_frame_message_source_);
2316 CHECK(!render_view_message_source_);
2317 RenderFrameHostImpl* rfh =
2318 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2319
[email protected]161eabd2014-03-19 19:47:272320 int render_frame_id = rfh->GetRoutingID();
2321 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572322 FOR_EACH_OBSERVER(WebContentsObserver,
2323 observers_,
[email protected]161eabd2014-03-19 19:47:272324 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182325}
2326
[email protected]b172aee2012-04-10 17:05:262327void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262328 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372329 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122330 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2331 GetRenderProcessHost()->ReceivedBadMessage();
2332 return;
2333 }
[email protected]a1b99262013-12-27 21:56:222334
[email protected]8b3af1e2014-01-24 13:29:122335 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442336 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372337 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422338 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372339
[email protected]61ac9e242014-03-21 20:55:262340 RenderFrameHostImpl* rfh =
2341 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272342 int render_frame_id = rfh->GetRoutingID();
2343 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262344 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252345 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272346 DidFinishLoad(render_frame_id, validated_url,
2347 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312348}
2349
[email protected]b172aee2012-04-10 17:05:262350void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222351 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2352 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262353}
2354
[email protected]b172aee2012-04-10 17:05:262355void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2356 int maximum_percent,
2357 bool remember) {
[email protected]216813952011-05-19 22:21:262358 minimum_zoom_percent_ = minimum_percent;
2359 maximum_zoom_percent_ = maximum_percent;
2360 temporary_zoom_settings_ = !remember;
2361}
2362
[email protected]b172aee2012-04-10 17:05:262363void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342364 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432365 if (!delegate_)
2366 return;
2367
[email protected]b9535422012-02-09 01:47:592368 ChildProcessSecurityPolicyImpl* policy =
2369 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222370 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592371 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212372}
2373
[email protected]b172aee2012-04-10 17:05:262374void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2375 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262376 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362377 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432378 if (!delegate_)
2379 return;
2380
[email protected]b9535422012-02-09 01:47:592381 ChildProcessSecurityPolicyImpl* policy =
2382 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322383 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592384 return;
[email protected]8f810632013-06-06 22:33:322385
[email protected]3a3b75a2012-06-01 08:38:362386 delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture);
[email protected]7d189022011-08-25 22:54:202387}
2388
[email protected]b172aee2012-04-10 17:05:262389void WebContentsImpl::OnFindReply(int request_id,
2390 int number_of_matches,
2391 const gfx::Rect& selection_rect,
2392 int active_match_ordinal,
2393 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432394 if (delegate_) {
2395 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2396 active_match_ordinal, final_update);
2397 }
[email protected]b888919c2011-09-02 00:32:162398}
2399
[email protected]59363fc92012-09-05 03:46:312400#if defined(OS_ANDROID)
2401void WebContentsImpl::OnFindMatchRectsReply(
2402 int version,
2403 const std::vector<gfx::RectF>& rects,
2404 const gfx::RectF& active_rect) {
2405 if (delegate_)
2406 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2407}
[email protected]583418cc2013-01-17 14:01:102408
[email protected]1ff427972013-02-07 21:14:072409void WebContentsImpl::OnOpenDateTimeDialog(
2410 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092411 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2412 GetRenderViewHost(),
2413 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132414 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092415 value.minimum,
2416 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172417 value.step,
2418 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102419}
2420
[email protected]a794f3a2013-10-30 17:00:322421void WebContentsImpl::OnJavaBridgeGetChannelHandle(IPC::Message* reply_msg) {
2422 java_bridge_dispatcher_host_manager_->OnGetChannelHandle(
[email protected]c06c58c2014-03-12 20:31:592423 render_frame_message_source_, reply_msg);
[email protected]a794f3a2013-10-30 17:00:322424}
2425
[email protected]59363fc92012-09-05 03:46:312426#endif
2427
[email protected]f114fa42013-12-06 17:06:442428void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2429 const base::FilePath& path,
2430 bool is_hung) {
2431 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2432
2433 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2434 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2435}
2436
2437void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422438 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442439 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422440 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452441}
2442
[email protected]cfa856d62014-02-22 07:58:402443void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2444 int automation_id) {
2445 DomOperationNotificationDetails details(json_string, automation_id);
2446 NotificationService::current()->Notify(
2447 NOTIFICATION_DOM_OPERATION_RESPONSE,
2448 Source<WebContents>(this),
2449 Details<DomOperationNotificationDetails>(&details));
2450}
2451
[email protected]b172aee2012-04-10 17:05:262452void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2453 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102454 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252455 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102456 AppCacheAccessed(manifest_url, blocked_by_policy));
2457}
2458
[email protected]8bc5ff02013-11-29 06:34:032459void WebContentsImpl::OnOpenColorChooser(
2460 int color_chooser_id,
2461 SkColor color,
2462 const std::vector<ColorSuggestion>& suggestions) {
2463 ColorChooser* new_color_chooser =
2464 delegate_->OpenColorChooser(this, color, suggestions);
[email protected]820957a2014-01-14 14:56:302465 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212466 return;
[email protected]820957a2014-01-14 14:56:302467 if (color_chooser_)
2468 color_chooser_->End();
[email protected]cb805452013-05-22 15:16:212469 color_chooser_.reset(new_color_chooser);
2470 color_chooser_identifier_ = color_chooser_id;
[email protected]da8543762012-03-20 08:52:202471}
2472
[email protected]b172aee2012-04-10 17:05:262473void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]da8543762012-03-20 08:52:202474 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212475 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202476 color_chooser_->End();
2477}
2478
[email protected]b172aee2012-04-10 17:05:262479void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322480 SkColor color) {
[email protected]da8543762012-03-20 08:52:202481 if (color_chooser_ &&
[email protected]cb805452013-05-22 15:16:212482 color_chooser_id == color_chooser_identifier_)
[email protected]da8543762012-03-20 08:52:202483 color_chooser_->SetSelectedColor(color);
2484}
2485
[email protected]d0759f492012-04-19 22:50:502486// This exists for render views that don't have a WebUI, but do have WebUI
2487// bindings enabled.
2488void WebContentsImpl::OnWebUISend(const GURL& source_url,
2489 const std::string& name,
2490 const base::ListValue& args) {
2491 if (delegate_)
2492 delegate_->WebUISend(this, source_url, name, args);
2493}
2494
[email protected]d8415ad92012-08-23 14:40:502495void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442496 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502497 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342498 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162499 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442500 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162501 return;
[email protected]d8415ad92012-08-23 14:40:502502 }
2503
[email protected]8c8fc292012-11-23 18:57:162504 if (!delegate_->RequestPpapiBrokerPermission(
2505 this, url, plugin_path,
2506 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442507 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162508 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442509 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162510 }
[email protected]d8415ad92012-08-23 14:40:502511}
2512
[email protected]ea0309c2013-08-06 19:35:442513void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502514 bool result) {
[email protected]ea0309c2013-08-06 19:35:442515 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502516}
2517
[email protected]c4538072013-03-18 02:17:552518void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372519 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082520 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552521 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392522 // For more info, see comment above classes BrowserPluginEmbedder and
2523 // BrowserPluginGuest.
2524 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142525 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082526 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372527}
2528
[email protected]41225fe2013-03-29 05:32:022529void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392530 int id,
[email protected]749fadd2013-05-15 08:37:482531 int http_status_code,
[email protected]795c28972012-12-06 06:13:392532 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302533 const std::vector<SkBitmap>& bitmaps,
2534 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132535 if (bitmaps.size() != original_bitmap_sizes.size())
2536 return;
2537
[email protected]41225fe2013-03-29 05:32:022538 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2539 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392540 // Currently WebContents notifies us of ANY downloads so that it is
2541 // possible to get here.
2542 return;
2543 }
2544 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302545 iter->second.Run(
2546 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392547 }
[email protected]41225fe2013-03-29 05:32:022548 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392549}
2550
2551void WebContentsImpl::OnUpdateFaviconURL(
2552 int32 page_id,
2553 const std::vector<FaviconURL>& candidates) {
2554 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2555 DidUpdateFaviconURL(page_id, candidates));
2556}
2557
[email protected]1dd0bb752014-02-01 01:16:262558void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2559 bool has_video,
2560 bool has_audio) {
2561// Chrome OS does its own detection of audio and video.
2562#if !defined(OS_CHROMEOS)
2563 scoped_ptr<PowerSaveBlocker> blocker;
2564 if (has_video) {
2565 blocker = PowerSaveBlocker::Create(
2566 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2567#if defined(OS_ANDROID)
2568 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2569 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2570#endif
2571 } else if (has_audio) {
2572 blocker = PowerSaveBlocker::Create(
2573 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2574 }
2575
2576 if (blocker) {
2577 power_save_blockers_[render_view_message_source_][player_cookie] =
2578 blocker.release();
2579 }
2580#endif // !defined(OS_CHROMEOS)
2581}
2582
2583void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062584 // Chrome OS does its own detection of audio and video.
2585#if !defined(OS_CHROMEOS)
[email protected]1dd0bb752014-02-01 01:16:262586 delete power_save_blockers_[render_view_message_source_][player_cookie];
2587 power_save_blockers_[render_view_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062588#endif // !defined(OS_CHROMEOS)
2589}
2590
[email protected]9f268072013-11-07 00:02:152591void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(int32 page_id) {
2592 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2593 DidFirstVisuallyNonEmptyPaint(page_id));
2594}
[email protected]d9030b82013-07-19 08:26:062595
[email protected]e67ebf32013-02-13 11:07:192596void WebContentsImpl::DidChangeVisibleSSLState() {
2597 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2598 DidChangeVisibleSSLState());
2599}
2600
[email protected]17e286e2013-03-01 23:29:392601void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2602 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2603 BeforeFormRepostWarningShow());
2604}
2605
[email protected]ec6c05f2013-10-23 18:41:572606
2607void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2608 Activate();
2609 if (delegate_)
2610 delegate_->ShowRepostFormWarningDialog(this);
2611}
2612
[email protected]96d185d2009-04-24 03:28:542613// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592614// loading, or done loading.
2615void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2616 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092617 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262618 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542619 if (is_loading == is_loading_)
2620 return;
2621
2622 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262623 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2624 base::string16());
[email protected]96d185d2009-04-24 03:28:542625 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562626 upload_size_ = 0;
2627 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542628 }
2629
[email protected]fa944cb82013-11-15 17:51:212630 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542631
2632 is_loading_ = is_loading;
2633 waiting_for_response_ = is_loading;
2634
[email protected]6ebdc9b2010-09-27 16:55:572635 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092636 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212637 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542638
[email protected]eab61442013-11-14 18:35:482639 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592640 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482641 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2642 "URL", url);
[email protected]91621872013-10-08 04:04:592643 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2644 DidStartLoading(render_view_host));
2645 } else {
[email protected]eab61442013-11-14 18:35:482646 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2647 "URL", url);
[email protected]91621872013-10-08 04:04:592648 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2649 DidStopLoading(render_view_host));
2650 }
[email protected]66798902013-10-01 18:40:162651
2652 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212653 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2654 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542655 if (details)
[email protected]8ff00d72012-10-23 19:12:212656 det = Details<LoadNotificationDetails>(details);
2657 NotificationService::current()->Notify(
2658 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542659}
2660
[email protected]b172aee2012-04-10 17:05:262661void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462662 // If we are creating a RVH for a restored controller, then we need to make
2663 // sure the RenderView starts with a next_page_id_ larger than the number
2664 // of restored entries. This must be called before the RenderView starts
2665 // navigating (to avoid a race between the browser updating max_page_id and
2666 // the renderer updating next_page_id_). Because of this, we only call this
2667 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562668 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582669 if (max_restored_page_id >
2670 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2671 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2672 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322673}
2674
[email protected]b172aee2012-04-10 17:05:262675bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262676 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322677 // For file URLs without a title, use the pathname instead. In the case of a
2678 // synthesized title, we don't want the update to count toward the "one set
2679 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262680 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322681 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512682 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242683 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322684 explicit_set = false; // Don't count synthetic titles toward the set limit.
2685 } else {
[email protected]8af69c6c2014-03-03 19:05:312686 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322687 explicit_set = true;
2688 }
2689
[email protected]987fc3a2011-05-26 14:18:092690 // If a page is created via window.open and never navigated,
2691 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552692 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092693 if (entry) {
[email protected]36fc0392011-12-25 03:59:512694 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092695 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322696
[email protected]36fc0392011-12-25 03:59:512697 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092698 } else {
2699 if (page_title_when_no_navigation_entry_ == final_title)
2700 return false; // Nothing changed, don't bother.
2701
2702 page_title_when_no_navigation_entry_ = final_title;
2703 }
[email protected]420ae012009-04-24 05:16:322704
[email protected]420ae012009-04-24 05:16:322705 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232706 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322707
[email protected]66798902013-10-01 18:40:162708 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532709 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162710
2711 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212712 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462713 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:212714 NotificationService::current()->Notify(
2715 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
2716 Source<WebContents>(this),
2717 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:042718
[email protected]420ae012009-04-24 05:16:322719 return true;
2720}
2721
[email protected]7b712ee22013-10-03 00:57:282722void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
2723 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:322724 // After sending out a swap notification, we need to send a disconnect
2725 // notification so that clients that pick up a pointer to |this| can NULL the
2726 // pointer. See Bug 1230284.
2727 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:112728 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:282729 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:112730
2731 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:282732 std::pair<RenderViewHost*, RenderViewHost*> details =
2733 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:212734 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:282735 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:212736 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:282737 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:392738
2739 // Ensure that the associated embedder gets cleared after a RenderViewHost
2740 // gets swapped, so we don't reuse the same embedder next time a
2741 // RenderViewHost is attached to this WebContents.
2742 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:322743}
2744
[email protected]da7a7182013-09-06 08:11:112745// TODO(avi): Remove this entire function because this notification is already
2746// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:262747void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:322748 if (!notify_disconnection_)
2749 return;
2750
2751 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:212752 NotificationService::current()->Notify(
2753 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
2754 Source<WebContents>(this),
2755 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:322756}
2757
[email protected]cbb1ef592013-06-05 19:49:462758void WebContentsImpl::NotifyNavigationEntryCommitted(
2759 const LoadCommittedDetails& load_details) {
2760 FOR_EACH_OBSERVER(
2761 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
2762}
2763
[email protected]f114fa42013-12-06 17:06:442764bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
2765 const IPC::Message& message) {
2766 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:312767}
2768
[email protected]b849847b2013-12-10 21:57:582769void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
2770 // Note this is only for subframes, the notification for the main frame
2771 // happens in RenderViewCreated.
2772 FOR_EACH_OBSERVER(WebContentsObserver,
2773 observers_,
2774 RenderFrameCreated(render_frame_host));
2775}
2776
2777void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
2778 FOR_EACH_OBSERVER(WebContentsObserver,
2779 observers_,
2780 RenderFrameDeleted(render_frame_host));
2781}
2782
[email protected]a09d53ce2014-01-31 00:46:422783void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:302784 if (delegate_)
2785 delegate_->WorkerCrashed(this);
2786}
2787
[email protected]a09d53ce2014-01-31 00:46:422788void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
2789 const ContextMenuParams& params) {
2790 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:402791 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:422792 return;
2793
2794 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
2795}
2796
[email protected]a86c0e962013-12-17 17:10:392797WebContents* WebContentsImpl::GetAsWebContents() {
2798 return this;
2799}
2800
[email protected]5a3bdf52012-05-24 15:12:572801RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
2802 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:322803}
2804
[email protected]8ff00d72012-10-23 19:12:212805RendererPreferences WebContentsImpl::GetRendererPrefs(
2806 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:462807 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512808}
2809
[email protected]b172aee2012-04-10 17:05:262810gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:172811 if (delegate_)
2812 return delegate_->GetRootWindowResizerRect();
2813 return gfx::Rect();
2814}
2815
[email protected]7a846df2012-09-20 19:17:392816void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:272817 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:392818 browser_plugin_embedder_.reset();
2819}
2820
[email protected]b172aee2012-04-10 17:05:262821void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:442822 // Don't send notifications if we are just creating a swapped-out RVH for
2823 // the opener chain. These won't be used for view-source or WebUI, so it's
2824 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:242825 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:442826 return;
2827
[email protected]86f98a22013-03-20 14:35:002828 if (delegate_)
2829 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:082830
[email protected]8ff00d72012-10-23 19:12:212831 NotificationService::current()->Notify(
2832 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
2833 Source<WebContents>(this),
2834 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322835
2836 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352837 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:212838 if (GetRenderManager()->pending_web_ui())
2839 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322840
[email protected]6286a372013-10-09 04:03:272841 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:332842 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:322843 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:182844 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:582845 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:322846 }
[email protected]0666aef2009-05-13 19:48:082847
[email protected]60780f412013-02-25 16:34:102848 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:262849
2850 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:252851 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:582852
2853 // We tell the observers now instead of when the main RenderFrameHostImpl is
2854 // constructed because otherwise it would be too early (i.e. IPCs sent to the
2855 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:362856 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:582857 FOR_EACH_OBSERVER(
2858 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:322859}
2860
[email protected]b172aee2012-04-10 17:05:262861void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:522862 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322863 // Don't notify the world, since this came from a renderer in the
2864 // background.
2865 return;
2866 }
2867
[email protected]da7a7182013-09-06 08:11:112868 notify_disconnection_ = true;
2869 // TODO(avi): Remove. http://crbug.com/170921
2870 NotificationService::current()->Notify(
2871 NOTIFICATION_WEB_CONTENTS_CONNECTED,
2872 Source<WebContents>(this),
2873 NotificationService::NoDetails());
2874
[email protected]be1f56ab2011-12-22 06:55:312875 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:232876 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302877
2878 // Restore the focus to the tab (otherwise the focus will be on the top
2879 // window).
[email protected]484ae5912010-09-29 19:16:142880 if (was_crashed && !FocusLocationBarByDefault() &&
2881 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:062882 view_->Focus();
[email protected]484ae5912010-09-29 19:16:142883 }
[email protected]32ded2212011-11-10 18:51:432884
[email protected]d8c660432011-12-22 20:51:252885 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:322886}
2887
[email protected]ec6a7eb2013-04-22 17:34:222888void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
2889 base::TerminationStatus status,
2890 int error_code) {
[email protected]151a63d2011-12-20 22:32:522891 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:322892 // The pending page's RenderViewHost is gone.
2893 return;
2894 }
2895
[email protected]2fcdcc32014-03-05 02:14:072896 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
2897 // renderer may not have made a clean exit.
2898 if (IsFullscreenForCurrentTab())
2899 ToggleFullscreenMode(false);
2900
[email protected]698191dc2014-02-25 01:06:132901 // Cancel any visible dialogs so they are not left dangling over the sad tab.
2902 if (dialog_manager_)
2903 dialog_manager_->CancelActiveAndPendingDialogs(this);
2904
[email protected]d9030b82013-07-19 08:26:062905 ClearPowerSaveBlockers(rvh);
[email protected]e3b10d12014-03-28 16:06:092906 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:322907 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232908 SetIsCrashed(status, error_code);
[email protected]be1f56ab2011-12-22 06:55:312909 GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_);
[email protected]420ae012009-04-24 05:16:322910
[email protected]d8c660432011-12-22 20:51:252911 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:272912 observers_,
[email protected]58d5cfe2013-07-10 02:40:522913 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:322914}
2915
[email protected]b172aee2012-04-10 17:05:262916void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d9030b82013-07-19 08:26:062917 ClearPowerSaveBlockers(rvh);
[email protected]fa944cb82013-11-15 17:51:212918 GetRenderManager()->RenderViewDeleted(rvh);
[email protected]d8c660432011-12-22 20:51:252919 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:062920}
2921
[email protected]b172aee2012-04-10 17:05:262922void WebContentsImpl::UpdateState(RenderViewHost* rvh,
2923 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:042924 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:152925 // Ensure that this state update comes from either the active RVH or one of
2926 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:412927 // TODO(nasko): This should go through RenderFrameHost.
2928 // TODO(creis): We can't update state for cross-process subframes until we
2929 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
2930 if (rvh != GetRenderViewHost() &&
2931 !GetRenderManager()->IsRVHOnSwappedOutList(
2932 static_cast<RenderViewHostImpl*>(rvh)))
2933 return;
[email protected]420ae012009-04-24 05:16:322934
2935 // We must be prepared to handle state updates for any page, these occur
2936 // when the user is scrolling and entering form data, as well as when we're
2937 // leaving a page, in which case our state may have already been moved to
2938 // the next page. The navigation controller will look up the appropriate
2939 // NavigationEntry and update it when it is notified via the delegate.
2940
2941 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582942 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:322943 if (entry_index < 0)
2944 return;
[email protected]10f417c52011-12-28 21:04:232945 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:322946
[email protected]691aa2f2013-05-28 22:52:042947 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:322948 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:042949 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:322950 controller_.NotifyEntryChanged(entry, entry_index);
2951}
2952
[email protected]b172aee2012-04-10 17:05:262953void WebContentsImpl::UpdateTitle(RenderViewHost* rvh,
2954 int32 page_id,
[email protected]fcf75d42013-12-03 20:11:262955 const base::string16& title,
[email protected]b172aee2012-04-10 17:05:262956 base::i18n::TextDirection title_direction) {
[email protected]420ae012009-04-24 05:16:322957 // If we have a title, that's a pretty good indication that we've started
2958 // getting useful data.
2959 SetNotWaitingForResponse();
2960
[email protected]73eb2602012-02-09 19:50:552961 // Try to find the navigation entry, which might not be the current one.
2962 // For example, it might be from a pending RVH for the pending entry.
[email protected]10f417c52011-12-28 21:04:232963 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
[email protected]9f76c1e2012-03-05 15:15:582964 rvh->GetSiteInstance(), page_id);
[email protected]987fc3a2011-05-26 14:18:092965
[email protected]73eb2602012-02-09 19:50:552966 // We can handle title updates when we don't have an entry in
2967 // UpdateTitleForEntry, but only if the update is from the current RVH.
2968 if (!entry && rvh != GetRenderViewHost())
2969 return;
2970
[email protected]a49e10b2011-08-01 23:57:462971 // TODO(evan): make use of title_direction.
2972 // http://code.google.com/p/chromium/issues/detail?id=27094
[email protected]987fc3a2011-05-26 14:18:092973 if (!UpdateTitleForEntry(entry, title))
[email protected]420ae012009-04-24 05:16:322974 return;
2975
2976 // Broadcast notifications when the UI should be updated.
2977 if (entry == controller_.GetEntryAtOffset(0))
[email protected]8ff00d72012-10-23 19:12:212978 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
[email protected]420ae012009-04-24 05:16:322979}
2980
[email protected]b172aee2012-04-10 17:05:262981void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host,
2982 const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312983 SetEncoding(encoding);
[email protected]420ae012009-04-24 05:16:322984}
2985
[email protected]b172aee2012-04-10 17:05:262986void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:512987 if (delegate_)
2988 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:322989}
2990
[email protected]b172aee2012-04-10 17:05:262991void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:102992#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:292993 // The UI may be in an event-tracking loop, such as between the
2994 // mouse-down and mouse-up in text selection or a button click.
2995 // Defer the close until after tracking is complete, so that we
2996 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:292997 // TODO(shess): This could get more fine-grained. For instance,
2998 // closing a tab in another window while selecting text in the
2999 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103000 if (view_->IsEventTracking()) {
3001 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293002 return;
3003 }
[email protected]60780f412013-02-25 16:34:103004#endif
[email protected]07707302009-11-06 00:50:293005
[email protected]420ae012009-04-24 05:16:323006 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523007 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513008 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323009}
3010
[email protected]66bbadaf2014-03-28 16:25:543011void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
3012 // TODO(creis): Handle subframes that go fullscreen.
3013 if (rfh->GetRenderViewHost() == GetRenderViewHost()) {
[email protected]2fcdcc32014-03-05 02:14:073014 // Exit fullscreen mode before the current RVH is swapped out. For numerous
3015 // cases, there is no guarantee the renderer would/could initiate an exit.
3016 // Example: http://crbug.com/347232
3017 if (IsFullscreenForCurrentTab()) {
[email protected]66bbadaf2014-03-28 16:25:543018 rfh->GetRenderViewHost()->ExitFullscreen();
[email protected]2fcdcc32014-03-05 02:14:073019 DCHECK(!IsFullscreenForCurrentTab());
3020 }
3021
3022 if (delegate_)
3023 delegate_->SwappedOut(this);
3024 }
[email protected]cd9ed79d2011-11-15 19:22:573025}
3026
[email protected]b172aee2012-04-10 17:05:263027void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513028 if (delegate_ && delegate_->IsPopupOrPanel(this))
3029 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323030}
3031
[email protected]e3b10d12014-03-28 16:06:093032void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3033 bool to_different_document) {
3034 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3035 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323036}
3037
[email protected]723971b2014-02-12 11:08:253038void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323039 scoped_ptr<LoadNotificationDetails> details;
3040
[email protected]9595fd82013-04-19 21:28:493041 // Use the last committed entry rather than the active one, in case a
3042 // pending entry has been created.
3043 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203044 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493045
[email protected]420ae012009-04-24 05:16:323046 // An entry may not exist for a stop when loading an initial blank page or
3047 // if an iframe injected by script into a blank page finishes loading.
3048 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203049 base::TimeDelta elapsed =
3050 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323051
3052 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513053 entry->GetVirtualURL(),
3054 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323055 elapsed,
3056 &controller_,
3057 controller_.GetCurrentEntryIndex()));
3058 }
3059
[email protected]e3b10d12014-03-28 16:06:093060 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3061 details.get());
[email protected]420ae012009-04-24 05:16:323062}
3063
[email protected]b172aee2012-04-10 17:05:263064void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163065 controller_.DiscardNonCommittedEntries();
3066
3067 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213068 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163069}
3070
[email protected]b172aee2012-04-10 17:05:263071void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513072 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133073 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403074}
3075
[email protected]7cc78902012-12-06 02:32:263076void WebContentsImpl::DidDisownOpener(RenderViewHost* rvh) {
[email protected]f54d94a2013-04-11 22:44:393077 if (opener_) {
3078 // Clear our opener so that future cross-process navigations don't have an
3079 // opener assigned.
[email protected]7fff43e2013-05-21 20:21:103080 RemoveDestructionObserver(opener_);
[email protected]f54d94a2013-04-11 22:44:393081 opener_ = NULL;
3082 }
[email protected]7cc78902012-12-06 02:32:263083
3084 // Notify all swapped out RenderViewHosts for this tab. This is important
3085 // in case we go back to them, or if another window in those processes tries
3086 // to access window.opener.
[email protected]fa944cb82013-11-15 17:51:213087 GetRenderManager()->DidDisownOpener(rvh);
[email protected]7cc78902012-12-06 02:32:263088}
3089
[email protected]59167c22013-06-03 18:07:323090void WebContentsImpl::DidAccessInitialDocument() {
3091 // Update the URL display.
3092 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3093}
3094
[email protected]87717d0e2012-04-26 02:58:433095void WebContentsImpl::DocumentAvailableInMainFrame(
3096 RenderViewHost* render_view_host) {
3097 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3098 DocumentAvailableInMainFrame());
[email protected]952a68e2011-11-17 00:36:103099}
3100
[email protected]b172aee2012-04-10 17:05:263101void WebContentsImpl::DocumentOnLoadCompletedInMainFrame(
[email protected]25497492010-09-11 15:15:083102 RenderViewHost* render_view_host,
3103 int32 page_id) {
[email protected]6578fef2013-10-14 02:35:093104 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3105 DocumentOnLoadCompletedInMainFrame(page_id));
3106
3107 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213108 NotificationService::current()->Notify(
3109 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3110 Source<WebContents>(this),
3111 Details<int>(&page_id));
[email protected]25497492010-09-11 15:15:083112}
3113
[email protected]e1c3a552012-05-04 20:51:323114void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3115 // Tell the active RenderViewHost to run unload handlers and close, as long
3116 // as the request came from a RenderViewHost in the same BrowsingInstance.
3117 // In most cases, we receive this from a swapped out RenderViewHost.
3118 // It is possible to receive it from one that has just been swapped in,
3119 // in which case we might as well deliver the message anyway.
3120 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3121 GetRenderViewHost()->ClosePage();
3122}
3123
[email protected]f546640b2012-05-15 00:03:493124void WebContentsImpl::RouteMessageEvent(
3125 RenderViewHost* rvh,
3126 const ViewMsg_PostMessage_Params& params) {
3127 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363128 // came from a RenderViewHost in the same BrowsingInstance or if this
3129 // WebContents is dedicated to a browser plugin guest.
3130 // Note: This check means that an embedder could theoretically receive a
3131 // postMessage from anyone (not just its own guests). However, this is
3132 // probably not a risk for apps since other pages won't have references
3133 // to App windows.
3134 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3135 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493136 return;
3137
3138 ViewMsg_PostMessage_Params new_params(params);
3139
[email protected]0bc7f3542013-10-21 15:05:533140 if (!params.message_port_ids.empty()) {
3141 MessagePortMessageFilter* message_port_message_filter =
3142 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3143 ->message_port_message_filter();
3144 std::vector<int> new_routing_ids(params.message_port_ids.size());
3145 for (size_t i = 0; i < params.message_port_ids.size(); ++i) {
3146 new_routing_ids[i] = message_port_message_filter->GetNextRoutingID();
3147 MessagePortService::GetInstance()->UpdateMessagePort(
3148 params.message_port_ids[i],
3149 message_port_message_filter,
3150 new_routing_ids[i]);
3151 }
3152 new_params.new_routing_ids = new_routing_ids;
3153 }
3154
[email protected]f546640b2012-05-15 00:03:493155 // If there is a source_routing_id, translate it to the routing ID for
3156 // the equivalent swapped out RVH in the target process. If we need
3157 // to create a swapped out RVH for the source tab, we create its opener
3158 // chain as well, since those will also be accessible to the target page.
3159 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3160 // Try to look up the WebContents for the source page.
3161 WebContentsImpl* source_contents = NULL;
3162 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3163 rvh->GetProcess()->GetID(), params.source_routing_id);
3164 if (source_rvh) {
3165 source_contents = static_cast<WebContentsImpl*>(
3166 source_rvh->GetDelegate()->GetAsWebContents());
3167 }
3168
3169 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363170 if (GetBrowserPluginGuest()) {
3171 // We create a swapped out RenderView for the embedder in the guest's
3172 // render process but we intentionally do not expose the embedder's
3173 // opener chain to it.
3174 new_params.source_routing_id =
3175 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3176 } else {
3177 new_params.source_routing_id =
3178 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3179 }
[email protected]f546640b2012-05-15 00:03:493180 } else {
3181 // We couldn't find it, so don't pass a source frame.
3182 new_params.source_routing_id = MSG_ROUTING_NONE;
3183 }
3184 }
3185
3186 // In most cases, we receive this from a swapped out RenderViewHost.
3187 // It is possible to receive it from one that has just been swapped in,
3188 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183189 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493190}
3191
[email protected]b172aee2012-04-10 17:05:263192void WebContentsImpl::RunJavaScriptMessage(
[email protected]fedec012012-01-28 03:09:343193 RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263194 const base::string16& message,
3195 const base::string16& default_prompt,
[email protected]420ae012009-04-24 05:16:323196 const GURL& frame_url,
[email protected]8ff00d72012-10-23 19:12:213197 JavaScriptMessageType javascript_message_type,
[email protected]420ae012009-04-24 05:16:323198 IPC::Message* reply_msg,
3199 bool* did_suppress_message) {
[email protected]3ab9cb82011-06-03 18:02:073200 // Suppress JavaScript dialogs when requested. Also suppress messages when
3201 // showing an interstitial as it's shown over the previous page and we don't
3202 // want the hidden page's dialogs to interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503203 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243204 static_cast<RenderViewHostImpl*>(rvh)->IsSwappedOut() ||
[email protected]0bfbf882011-12-22 18:19:273205 ShowingInterstitialPage() ||
[email protected]3ab9cb82011-06-03 18:02:073206 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523207 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153208 !delegate_->GetJavaScriptDialogManager();
[email protected]420ae012009-04-24 05:16:323209
3210 if (!suppress_this_message) {
[email protected]8ff00d72012-10-23 19:12:213211 std::string accept_lang = GetContentClient()->browser()->
[email protected]55df9092012-02-29 22:56:433212 GetAcceptLangs(GetBrowserContext());
[email protected]71a88bb2013-02-01 22:05:153213 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3214 dialog_manager_->RunJavaScriptDialog(
[email protected]55df9092012-02-29 22:56:433215 this,
3216 frame_url.GetOrigin(),
3217 accept_lang,
3218 javascript_message_type,
3219 message,
[email protected]51da7e32012-01-30 19:24:523220 default_prompt,
[email protected]b172aee2012-04-10 17:05:263221 base::Bind(&WebContentsImpl::OnDialogClosed,
3222 base::Unretained(this),
3223 rvh,
3224 reply_msg),
[email protected]51da7e32012-01-30 19:24:523225 &suppress_this_message);
[email protected]420ae012009-04-24 05:16:323226 }
[email protected]3ab9cb82011-06-03 18:02:073227
[email protected]6dd2f1e2013-09-11 15:06:013228 *did_suppress_message = suppress_this_message;
3229
[email protected]3ab9cb82011-06-03 18:02:073230 if (suppress_this_message) {
3231 // If we are suppressing messages, just reply as if the user immediately
3232 // pressed "Cancel".
[email protected]fcf75d42013-12-03 20:11:263233 OnDialogClosed(rvh, reply_msg, false, base::string16());
[email protected]3ab9cb82011-06-03 18:02:073234 }
3235
[email protected]6dd2f1e2013-09-11 15:06:013236 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3237 // http://crbug.com/288961 ). The only safe thing to do here is return.
[email protected]420ae012009-04-24 05:16:323238}
3239
[email protected]b172aee2012-04-10 17:05:263240void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh,
[email protected]fcf75d42013-12-03 20:11:263241 const base::string16& message,
[email protected]b172aee2012-04-10 17:05:263242 bool is_reload,
3243 IPC::Message* reply_msg) {
[email protected]9f76c1e2012-03-05 15:15:583244 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
[email protected]6934a702011-12-20 00:04:513245 if (delegate_)
3246 delegate_->WillRunBeforeUnloadConfirm();
[email protected]3ab9cb82011-06-03 18:02:073247
3248 bool suppress_this_message =
[email protected]21b41c7e892014-02-28 01:52:243249 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
[email protected]3ab9cb82011-06-03 18:02:073250 !delegate_ ||
[email protected]51da7e32012-01-30 19:24:523251 delegate_->ShouldSuppressDialogs() ||
[email protected]71a88bb2013-02-01 22:05:153252 !delegate_->GetJavaScriptDialogManager();
[email protected]992db4c2011-05-12 15:37:153253 if (suppress_this_message) {
[email protected]fedec012012-01-28 03:09:343254 // The reply must be sent to the RVH that sent the request.
[email protected]fcf75d42013-12-03 20:11:263255 rvhi->JavaScriptDialogClosed(reply_msg, true, base::string16());
[email protected]8f55e802010-12-06 18:11:503256 return;
3257 }
[email protected]3ab9cb82011-06-03 18:02:073258
[email protected]7ab1e7d62009-10-14 23:32:013259 is_showing_before_unload_dialog_ = true;
[email protected]71a88bb2013-02-01 22:05:153260 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3261 dialog_manager_->RunBeforeUnloadDialog(
[email protected]3b3301f62012-02-29 04:32:323262 this, message, is_reload,
[email protected]b172aee2012-04-10 17:05:263263 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh,
[email protected]51da7e32012-01-30 19:24:523264 reply_msg));
[email protected]420ae012009-04-24 05:16:323265}
3266
[email protected]a796f202012-05-30 14:14:253267bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263268 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253269 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263270 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253271 if (!delegate_)
3272 return false;
3273 return delegate_->AddMessageToConsole(this, level, message, line_no,
3274 source_id);
3275}
3276
[email protected]b172aee2012-04-10 17:05:263277WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273278 // We want to base the page config off of the actual URL, rather than the
3279 // virtual URL.
3280 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3281 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003282 GURL url = controller_.GetActiveEntry()
3283 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153284
[email protected]fa944cb82013-11-15 17:51:213285 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323286}
3287
[email protected]0eba810b2012-10-18 03:19:363288int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213289 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413290 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3291 true, true);
[email protected]0eba810b2012-10-18 03:19:363292}
3293
[email protected]b172aee2012-04-10 17:05:263294void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273295 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253296 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223297
[email protected]ea114722012-03-12 01:11:253298 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173299 if (rdh) // NULL in unittests.
3300 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253301}
3302
[email protected]b172aee2012-04-10 17:05:263303void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443304 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253305 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443306}
3307
[email protected]b172aee2012-04-10 17:05:263308void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563309 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263310 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153311 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523312 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153313 return;
3314
[email protected]9f76c1e2012-03-05 15:15:583315 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3316
[email protected]e5fc1632011-08-08 07:51:533317 // Ignore renderer unresponsive event if debugger is attached to the tab
3318 // since the event may be a result of the renderer sitting on a breakpoint.
3319 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363320 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533321 return;
3322
[email protected]2e9d79f2013-08-16 05:45:563323 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323324 // Hang occurred while firing the beforeunload/unload handler.
3325 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583326 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323327
[email protected]fa944cb82013-11-15 17:51:213328 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323329 return;
3330
3331 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563332 // nothing we can do to recover. If the hang is in the beforeunload handler,
3333 // pretend the beforeunload listeners have all fired and allow the delegate
3334 // to continue closing; the user will not have the option of cancelling the
3335 // close. Otherwise, pretend the unload listeners have all fired and close
3336 // the tab.
3337 bool close = true;
3338 if (is_during_beforeunload) {
3339 delegate_->BeforeUnloadFired(this, true, &close);
3340 }
3341 if (close)
3342 Close(rvh);
[email protected]420ae012009-04-24 05:16:323343 return;
3344 }
3345
[email protected]9f76c1e2012-03-05 15:15:583346 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473347 return;
3348
[email protected]6934a702011-12-20 00:04:513349 if (delegate_)
3350 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323351}
3352
[email protected]b172aee2012-04-10 17:05:263353void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513354 if (delegate_)
3355 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323356}
3357
[email protected]b172aee2012-04-10 17:05:263358void WebContentsImpl::LoadStateChanged(
3359 const GURL& url,
3360 const net::LoadStateWithParam& load_state,
3361 uint64 upload_position,
3362 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323363 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563364 upload_position_ = upload_position;
3365 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503366 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213367 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303368 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213369 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323370 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463371 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213372 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463373 }
[email protected]420ae012009-04-24 05:16:323374}
3375
[email protected]b172aee2012-04-10 17:05:263376void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553377 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323378 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123379 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3380 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513381 if (delegate_)
3382 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093383 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323384}
3385
[email protected]58d5cfe2013-07-10 02:40:523386void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543387 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233388 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223389 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543390}
3391
[email protected]b172aee2012-04-10 17:05:263392void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103393 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213394 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263395 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3396 // here during container initialization and normal window size will be set
3397 // later. In case of tab duplication this resizing to 0x0 prevents setting
3398 // normal size later so just ignore it.
3399 if (!size.IsEmpty())
3400 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323401}
3402
[email protected]af905902013-10-01 21:38:513403void WebContentsImpl::CancelModalDialogsForRenderManager() {
3404 // We need to cancel modal dialogs when doing a process swap, since the load
3405 // deferrer would prevent us from swapping out.
3406 if (dialog_manager_)
3407 dialog_manager_->CancelActiveAndPendingDialogs(this);
3408}
3409
[email protected]7b712ee22013-10-03 00:57:283410void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3411 RenderViewHost* new_host) {
3412 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083413
3414 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003415 if (delegate_)
3416 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393417
[email protected]7b712ee22013-10-03 00:57:283418 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543419}
3420
[email protected]14392a52012-05-02 20:28:443421int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3422 SiteInstance* instance) {
3423 if (!opener_)
3424 return MSG_ROUTING_NONE;
3425
3426 // Recursively create RenderViews for anything else in the opener chain.
3427 return opener_->CreateOpenerRenderViews(instance);
3428}
3429
3430int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3431 int opener_route_id = MSG_ROUTING_NONE;
3432
3433 // If this tab has an opener, ensure it has a RenderView in the given
3434 // SiteInstance as well.
3435 if (opener_)
3436 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3437
[email protected]45a22ad2013-02-21 03:25:003438 // If any of the renderers (current, pending, or swapped out) for this
3439 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213440 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3441 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373442
[email protected]fa944cb82013-11-15 17:51:213443 if (GetRenderManager()->pending_render_view_host() &&
3444 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3445 instance)
3446 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003447
[email protected]fa944cb82013-11-15 17:51:213448 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373449 instance);
3450 if (rvh)
3451 return rvh->GetRoutingID();
3452
[email protected]14392a52012-05-02 20:28:443453 // Create a swapped out RenderView in the given SiteInstance if none exists,
3454 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413455 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3456 true, true);
[email protected]14392a52012-05-02 20:28:443457}
3458
[email protected]b172aee2012-04-10 17:05:263459NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193460 return GetController();
[email protected]3a3d47472010-07-15 21:03:543461}
3462
[email protected]b172aee2012-04-10 17:05:263463WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563464 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323465}
3466
[email protected]10f417c52011-12-28 21:04:233467NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263468 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323469 return controller_.GetLastCommittedEntry();
3470}
3471
[email protected]b172aee2012-04-10 17:05:263472bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163473 RenderViewHost* render_view_host,
3474 int opener_route_id,
3475 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033476 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443477 // Can be NULL during tests.
[email protected]bffc8302014-01-23 20:52:163478 RenderWidgetHostView* rwh_view;
3479 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3480 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3481 // case this because RWH is still a base class of RenderViewHost, and child
3482 // frame RWHVs are unique in that they do not have their own WebContents.
3483 if (frame_connector) {
3484 RenderWidgetHostViewChildFrame* rwh_view_child =
3485 new RenderWidgetHostViewChildFrame(render_view_host);
3486 frame_connector->set_view(rwh_view_child);
3487 rwh_view = rwh_view_child;
3488 } else {
3489 rwh_view = view_->CreateViewForWidget(render_view_host);
3490 }
[email protected]1a98a932009-11-17 00:12:523491
[email protected]420ae012009-04-24 05:16:323492 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443493 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213494 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323495
[email protected]74ce1ad2011-12-16 21:51:463496 // Make sure we use the correct starting page_id in the new RenderView.
3497 UpdateMaxPageIDIfNecessary(render_view_host);
3498 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583499 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463500
[email protected]9f76c1e2012-03-05 15:15:583501 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263502 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493503 opener_route_id,
[email protected]500ca7f12012-10-25 00:13:133504 max_page_id)) {
[email protected]a4127722011-04-27 23:13:523505 return false;
[email protected]14392a52012-05-02 20:28:443506 }
[email protected]a4127722011-04-27 23:13:523507
[email protected]a220b5932013-09-21 03:47:443508#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503509 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3510 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443511 if (rwh_view) {
3512 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3513 render_widget_host->WasResized();
3514 }
[email protected]f8233cc2011-05-31 20:24:503515#endif
3516
[email protected]420ae012009-04-24 05:16:323517 return true;
3518}
3519
[email protected]7d244f12013-08-22 21:41:513520#if defined(OS_ANDROID)
[email protected]155c7f22013-12-09 17:07:183521base::android::ScopedJavaLocalRef<jobject>
3522WebContentsImpl::GetJavaWebContents() {
3523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3524
3525 WebContentsAndroid* web_contents_android =
3526 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3527 if (!web_contents_android) {
3528 web_contents_android = new WebContentsAndroid(this);
3529 SetUserData(kWebContentsAndroidKey, web_contents_android);
3530 }
3531 return web_contents_android->GetJavaObject();
3532}
3533
[email protected]7d244f12013-08-22 21:41:513534bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3535 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163536 MSG_ROUTING_NONE,
3537 NULL);
[email protected]7d244f12013-08-22 21:41:513538}
3539#endif
3540
[email protected]b172aee2012-04-10 17:05:263541void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh,
3542 IPC::Message* reply_msg,
3543 bool success,
[email protected]fcf75d42013-12-03 20:11:263544 const base::string16& user_input) {
[email protected]beb440c2009-11-06 04:08:543545 if (is_showing_before_unload_dialog_ && !success) {
3546 // If a beforeunload dialog is canceled, we need to stop the throbber from
3547 // spinning, since we forced it to start spinning in Navigate.
[email protected]723971b2014-02-12 11:08:253548 DidStopLoading(rvh->GetMainFrame());
[email protected]15d160c02012-07-04 10:52:353549 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103550
[email protected]6d65a462013-06-21 21:29:123551 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3552 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543553 }
3554 is_showing_before_unload_dialog_ = false;
[email protected]9f76c1e2012-03-05 15:15:583555 static_cast<RenderViewHostImpl*>(
3556 rvh)->JavaScriptDialogClosed(reply_msg, success, user_input);
[email protected]beb440c2009-11-06 04:08:543557}
3558
[email protected]b172aee2012-04-10 17:05:263559void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]8ff00d72012-10-23 19:12:213560 encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123561 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103562}
[email protected]f45d2a72010-03-08 23:28:353563
[email protected]b172aee2012-04-10 17:05:263564void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103565 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443566 // Can be NULL during tests.
3567 if (rwh_view)
[email protected]d487beefe2011-12-21 05:41:213568 rwh_view->SetSize(GetView()->GetContainerSize());
[email protected]33f74972010-12-08 16:40:363569}
[email protected]9f76c1e2012-03-05 15:15:583570
[email protected]1ac10dca2013-08-20 20:47:043571bool WebContentsImpl::IsHidden() {
3572 return capturer_count_ == 0 && !should_normally_be_visible_;
3573}
3574
[email protected]b0936d22013-11-28 06:47:363575RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213576 return frame_tree_.root()->render_manager();
3577}
3578
[email protected]b172aee2012-04-10 17:05:263579RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583580 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3581}
[email protected]7900bfdb2012-05-24 19:31:243582
[email protected]f8497342013-02-05 22:15:023583BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393584 return browser_plugin_guest_.get();
3585}
3586
[email protected]738f57a2013-06-29 21:06:543587void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3588 CHECK(!browser_plugin_guest_);
3589 browser_plugin_guest_.reset(guest);
3590}
3591
[email protected]f8497342013-02-05 22:15:023592BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393593 return browser_plugin_embedder_.get();
3594}
[email protected]8ff00d72012-10-23 19:12:213595
[email protected]8eb04562013-03-06 03:41:143596BrowserPluginGuestManager*
3597 WebContentsImpl::GetBrowserPluginGuestManager() const {
3598 return static_cast<BrowserPluginGuestManager*>(
3599 GetBrowserContext()->GetUserData(
3600 browser_plugin::kBrowserPluginGuestManagerKeyName));
3601}
3602
[email protected]d9030b82013-07-19 08:26:063603void WebContentsImpl::ClearPowerSaveBlockers(
3604 RenderViewHost* render_view_host) {
3605 STLDeleteValues(&power_save_blockers_[render_view_host]);
3606 power_save_blockers_.erase(render_view_host);
3607}
3608
3609void WebContentsImpl::ClearAllPowerSaveBlockers() {
3610 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3611 i != power_save_blockers_.end(); ++i)
3612 STLDeleteValues(&power_save_blockers_[i->first]);
3613 power_save_blockers_.clear();
3614}
3615
[email protected]dc0fd432013-08-27 15:29:213616gfx::Size WebContentsImpl::GetSizeForNewRenderView() const {
3617 gfx::Size size;
3618 if (delegate_)
3619 size = delegate_->GetSizeForNewRenderView(this);
3620 if (size.IsEmpty())
3621 size = view_->GetContainerSize();
3622 return size;
3623}
3624
[email protected]9b159a52013-10-03 17:24:553625void WebContentsImpl::OnFrameRemoved(
3626 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583627 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553628 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583629 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553630}
3631
[email protected]222f5822014-02-05 23:40:493632void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3633 if (!delegate_)
3634 return;
3635 const gfx::Size new_size = GetPreferredSize();
3636 if (new_size != old_size)
3637 delegate_->UpdatePreferredSize(this, new_size);
3638}
3639
[email protected]8ff00d72012-10-23 19:12:213640} // namespace content