blob: dd371919e5d473c7b8f7960d12221e94d4997be4 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/browser_plugin/browser_plugin_embedder.h"
22#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5923#include "content/browser/child_process_security_policy_impl.h"
[email protected]49413ca52014-03-05 14:13:4324#include "content/browser/devtools/render_view_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4125#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0426#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4627#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1228#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1629#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1630#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4031#include "content/browser/frame_host/interstitial_page_impl.h"
32#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0133#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1834#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1635#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]f28ef9a32014-05-12 16:36:1036#include "content/browser/geolocation/geolocation_dispatcher_host.h"
[email protected]5c9250872012-01-30 17:24:0537#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4438#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5339#include "content/browser/message_port_message_filter.h"
40#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0641#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3042#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5043#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3244#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5045#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4846#include "content/browser/renderer_host/render_widget_host_view_base.h"
[email protected]b6583592012-01-25 19:52:3347#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1148#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5849#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0350#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5651#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1452#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4253#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4454#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0255#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1756#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5157#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0258#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3659#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1160#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2861#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4462#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3663#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1764#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1465#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4666#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1567#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0068#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2769#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0070#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3771#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1472#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3273#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3474#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3875#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4276#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2577#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2178#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4879#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5480#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4981#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2082#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0383#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5784#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1685#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2986#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5387#include "net/http/http_cache.h"
88#include "net/http/http_transaction_factory.h"
89#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3490#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5691#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0192#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4193#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5294#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1895#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3196
[email protected]583418cc2013-01-17 14:01:1097#if defined(OS_ANDROID)
98#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:4599#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18100#include "content/browser/web_contents/web_contents_android.h"
[email protected]74ebfb12013-06-07 20:48:00101#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10102#endif
103
[email protected]f66df822012-05-18 16:52:17104#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50105#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57106#endif
[email protected]3e45ba92009-02-20 21:09:00107
[email protected]420ae012009-04-24 05:16:32108// Cross-Site Navigations
109//
[email protected]b172aee2012-04-10 17:05:26110// If a WebContentsImpl is told to navigate to a different web site (as
111// determined by SiteInstance), it will replace its current RenderViewHost with
112// a new RenderViewHost dedicated to the new SiteInstance. This works as
113// follows:
[email protected]420ae012009-04-24 05:16:32114//
[email protected]fc6c1872013-10-03 01:22:35115// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46116// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32117// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35118// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32119// run in the current RVH.
120// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35121// that it has a pending cross-site request. We will check this on the IO
122// thread when deciding how to handle the response.
123// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46124// cancel all the pending logic. Otherwise we allow the pending RVH to send
125// the navigation request to its renderer.
126// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35127// main resource load on the pending RVH. It creates a
128// CrossSiteResourceHandler to check whether a process swap is needed when
129// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46130// - When RDH receives a response, the BufferedResourceHandler determines
131// whether it is a download. If so, it sends a message to the new renderer
132// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26133// pending RVH remains until the next DidNavigate event for this
134// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32135// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35136// download, the CrossSiteResourceHandler checks whether a process swap is
137// needed (either because CrossSiteRequestManager has state for it or because
138// a transfer was needed for a redirect).
139// - If so, CrossSiteResourceHandler pauses the response to first run the old
140// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36141// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
142// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35143// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
144// to a new process is needed, based on the stored pending_nav_params_. (This
145// is independent of whether we started out with a cross-process navigation.)
146// - If not, it just tells the ResourceDispatcherHost to resume the response
147// to its current RenderViewHost.
148// - If so, it cancels the current pending RenderViewHost and sets up a new
149// navigation using RequestTransferURL. When the transferred request
150// arrives in the ResourceDispatcherHost, we transfer the response and
151// resume it.
[email protected]420ae012009-04-24 05:16:32152// - The pending renderer sends a FrameNavigate message that invokes the
153// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46154// pending RVH.
[email protected]b0936d22013-11-28 06:47:36155// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15156// the user goes back. The process only stays live if another tab is using
157// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32158
[email protected]8ff00d72012-10-23 19:12:21159namespace content {
[email protected]420ae012009-04-24 05:16:32160namespace {
161
[email protected]960b0372014-05-19 18:01:00162const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
163
164// This matches what Blink's ProgressTracker has traditionally used for a
165// minimum progress value.
166const double kMinimumLoadingProgress = 0.1;
167
[email protected]82114f52012-03-20 22:53:41168const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05169
[email protected]155c7f22013-12-09 17:07:18170#if defined(OS_ANDROID)
171const char kWebContentsAndroidKey[] = "web_contents_android";
172#endif // OS_ANDROID
173
[email protected]e4abd3b42013-11-12 18:28:47174base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46175g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
176
[email protected]988ed7132014-03-31 16:25:58177static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39178 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29179 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30180 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02181 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58182 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02183 ++g_next_image_download_id,
184 url,
185 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30186 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02187 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39188}
189
[email protected]8bfc8272013-09-09 20:10:53190void NotifyCacheOnIO(
191 scoped_refptr<net::URLRequestContextGetter> request_context,
192 const GURL& url,
193 const std::string& http_method) {
194 request_context->GetURLRequestContext()->http_transaction_factory()->
195 GetCache()->OnExternalCacheHit(url, http_method);
196}
197
[email protected]9b159a52013-10-03 17:24:55198// Helper function for retrieving all the sites in a frame tree.
199bool CollectSites(BrowserContext* context,
200 std::set<GURL>* sites,
201 FrameTreeNode* node) {
202 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
203 return true;
204}
205
[email protected]a86c0e962013-12-17 17:10:39206bool ForEachFrameInternal(
207 const base::Callback<void(RenderFrameHost*)>& on_frame,
208 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41209 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39210 return true;
211}
212
213void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
214 IPC::Message* message_copy = new IPC::Message(*message);
215 message_copy->set_routing_id(rfh->GetRoutingID());
216 rfh->Send(message_copy);
217}
218
[email protected]de3c5d82014-05-28 22:12:59219void AddRenderWidgetHostToSet(std::set<RenderWidgetHostImpl*>* set,
220 RenderFrameHost* rfh) {
221 set->insert(static_cast<RenderFrameHostImpl*>(rfh)->GetRenderWidgetHost());
222}
223
[email protected]420ae012009-04-24 05:16:32224} // namespace
225
[email protected]54944cde2012-12-09 09:24:59226WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15227 return WebContentsImpl::CreateWithOpener(
228 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19229}
230
231WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59232 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30233 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59234 WebContentsImpl* new_contents = new WebContentsImpl(
235 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30236
237 for (SessionStorageNamespaceMap::const_iterator it =
238 session_storage_namespace_map.begin();
239 it != session_storage_namespace_map.end();
240 ++it) {
241 new_contents->GetController()
242 .SetSessionStorageNamespace(it->first, it->second.get());
243 }
244
[email protected]54944cde2012-12-09 09:24:59245 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19246 return new_contents;
[email protected]a81343d232011-12-27 07:39:20247}
[email protected]746d3052012-05-22 15:15:47248
[email protected]e4abd3b42013-11-12 18:28:47249void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46250 g_created_callbacks.Get().push_back(callback);
251}
252
[email protected]e4abd3b42013-11-12 18:28:47253void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46254 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
255 if (g_created_callbacks.Get().at(i).Equals(callback)) {
256 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
257 return;
258 }
259 }
260}
261
[email protected]299d7f12012-05-23 05:31:15262WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47263 return rvh->GetDelegate()->GetAsWebContents();
264}
265
[email protected]a86c0e962013-12-17 17:10:39266WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
267 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
268 if (!rfh_impl)
269 return NULL;
270 return rfh_impl->delegate()->GetAsWebContents();
271}
272
[email protected]7fff43e2013-05-21 20:21:10273// WebContentsImpl::DestructionObserver ----------------------------------------
274
275class WebContentsImpl::DestructionObserver : public WebContentsObserver {
276 public:
277 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
278 : WebContentsObserver(watched_contents),
279 owner_(owner) {
280 }
281
282 // WebContentsObserver:
[email protected]12a46832014-05-09 13:35:58283 virtual void WebContentsDestroyed() OVERRIDE {
284 owner_->OnWebContentsDestroyed(
285 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10286 }
287
288 private:
289 WebContentsImpl* owner_;
290
291 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
292};
293
[email protected]8ed16472014-04-11 19:02:48294WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
295 int render_frame_id,
296 ColorChooser* chooser,
297 int identifier)
298 : render_process_id(render_process_id),
299 render_frame_id(render_frame_id),
300 chooser(chooser),
301 identifier(identifier) {
302}
303
304WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
305}
306
[email protected]b172aee2012-04-10 17:05:26307// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32308
[email protected]b172aee2012-04-10 17:05:26309WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21310 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19311 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42312 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22313 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57314 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44315 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49316 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08317#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41318 accessible_parent_(NULL),
319#endif
[email protected]6ea6bdf2013-12-06 13:35:01320 frame_tree_(new NavigatorImpl(&controller_, this),
321 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34322 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03323 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23324 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
325 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34326 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26327 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00328 loading_total_progress_(0.0),
329 loading_weak_factory_(this),
330 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56331 upload_size_(0),
332 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47333 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10334 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55335 capturer_count_(0),
336 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57337 is_being_destroyed_(false),
338 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15339 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01340 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02341 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38342 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21343 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
344 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29345 totalPinchGestureAmount_(0),
346 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44347 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42348 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]87de04b02014-04-08 22:14:49349 is_subframe_(false),
[email protected]e85165c642014-06-10 14:34:31350 touch_emulation_enabled_(false),
[email protected]87de04b02014-04-08 22:14:49351 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46352 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
353 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55354 frame_tree_.SetFrameRemoveListener(
355 base::Bind(&WebContentsImpl::OnFrameRemoved,
356 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35357}
initial.commit09911bf2008-07-26 23:55:29358
[email protected]b172aee2012-04-10 17:05:26359WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32360 is_being_destroyed_ = true;
361
[email protected]21b41c7e892014-02-28 01:52:24362 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
363 // shutdown and be deleted as well.
364 frame_tree_.ForEach(
365 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
366
[email protected]d9030b82013-07-19 08:26:06367 ClearAllPowerSaveBlockers();
368
[email protected]b24b68a2012-09-24 21:57:26369 for (std::set<RenderWidgetHostImpl*>::iterator iter =
370 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
371 (*iter)->DetachDelegate();
372 }
373 created_widgets_.clear();
374
[email protected]3ab9cb82011-06-03 18:02:07375 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15376 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11377 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07378
[email protected]8ed16472014-04-11 19:02:48379 if (color_chooser_info_.get())
380 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20381
[email protected]420ae012009-04-24 05:16:32382 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32383
[email protected]ca13a442012-04-17 14:00:12384 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21385 NotificationService::current()->Notify(
386 NOTIFICATION_WEB_CONTENTS_DESTROYED,
387 Source<WebContents>(this),
388 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32389
[email protected]df0c843f2014-05-23 20:37:23390 // Destroy all frame tree nodes except for the root; this notifies observers.
391 frame_tree_.ResetForMainFrameSwap();
392 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59393
[email protected]df0c843f2014-05-23 20:37:23394 // Manually call the observer methods for the root frame tree node.
395 RenderFrameHostManager* root = GetRenderManager();
396 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27397 FOR_EACH_OBSERVER(WebContentsObserver,
398 observers_,
[email protected]df0c843f2014-05-23 20:37:23399 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27400 }
[email protected]df0c843f2014-05-23 20:37:23401 FOR_EACH_OBSERVER(WebContentsObserver,
402 observers_,
403 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27404
[email protected]df0c843f2014-05-23 20:37:23405 if (root->pending_render_view_host()) {
406 FOR_EACH_OBSERVER(WebContentsObserver,
407 observers_,
408 RenderViewDeleted(root->pending_render_view_host()));
409 }
[email protected]c06c58c2014-03-12 20:31:59410
[email protected]f273ee52013-10-18 16:05:27411 FOR_EACH_OBSERVER(WebContentsObserver,
412 observers_,
[email protected]df0c843f2014-05-23 20:37:23413 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27414
[email protected]2db9bd72012-04-13 20:20:56415 FOR_EACH_OBSERVER(WebContentsObserver,
416 observers_,
[email protected]12a46832014-05-09 13:35:58417 WebContentsDestroyed());
418
419 FOR_EACH_OBSERVER(WebContentsObserver,
420 observers_,
421 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08422
[email protected]6934a702011-12-20 00:04:51423 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10424
425 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
426 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42427}
428
[email protected]d1198fd2012-08-13 22:50:19429WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59430 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19431 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03432 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59433 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06434 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19435
[email protected]83100cd2014-05-10 11:50:06436 if (params.guest_instance_id) {
[email protected]50d326e2014-05-20 17:59:06437 scoped_ptr<base::DictionaryValue> extra_params;
438 if (params.guest_extra_params)
439 extra_params.reset(params.guest_extra_params->DeepCopy());
[email protected]83100cd2014-05-10 11:50:06440 // This makes |new_contents| act as a guest.
441 // For more info, see comment above class BrowserPluginGuest.
442 BrowserPluginGuest::Create(params.guest_instance_id,
443 params.site_instance,
444 new_contents,
[email protected]50d326e2014-05-20 17:59:06445 extra_params.Pass(),
446 opener ? opener->GetBrowserPluginGuest() : NULL);
[email protected]83100cd2014-05-10 11:50:06447 // We are instantiating a WebContents for browser plugin. Set its subframe
448 // bit to true.
449 new_contents->is_subframe_ = true;
450 }
[email protected]54944cde2012-12-09 09:24:59451 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19452 return new_contents;
453}
454
[email protected]b0936d22013-11-28 06:47:36455RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21456 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28457}
458
[email protected]7bb761892012-07-20 09:32:47459bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
460 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44461 return OnMessageReceived(render_view_host, NULL, message);
462}
463
464bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
465 RenderFrameHost* render_frame_host,
466 const IPC::Message& message) {
467 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56468 if (GetWebUI() &&
469 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17470 return true;
[email protected]d2353452012-01-19 19:53:56471 }
[email protected]f82d57b52011-04-27 19:13:17472
[email protected]d8c660432011-12-22 20:51:25473 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
474 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33475 if (render_frame_host) {
476 while ((observer = it.GetNext()) != NULL)
477 if (observer->OnMessageReceived(message, render_frame_host))
478 return true;
479 } else {
480 while ((observer = it.GetNext()) != NULL)
481 if (observer->OnMessageReceived(message))
482 return true;
483 }
[email protected]403415a2011-01-10 18:57:53484
[email protected]1d62cf72014-02-07 21:31:57485 // Message handlers should be aware of which
486 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
487 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43488 if (render_frame_host) {
489 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
490 render_frame_host->GetRenderViewHost(), message))
491 return true;
[email protected]1d62cf72014-02-07 21:31:57492 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43493 } else {
494 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
495 render_view_host, message))
496 return true;
[email protected]1d62cf72014-02-07 21:31:57497 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43498 }
[email protected]1d62cf72014-02-07 21:31:57499
[email protected]724159a2010-12-30 01:11:18500 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33501 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]f114fa42013-12-06 17:06:44502 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
503 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40504 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
505 OnDomOperationResponse)
[email protected]8ed16472014-04-11 19:02:48506 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
507 OnDocumentLoadedInFrame)
508 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00509 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
510 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
511 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
512 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48513 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
514 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
515 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
516 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19517 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
518 OnMediaPlayingNotification)
519 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
520 OnMediaPausedNotification)
[email protected]724159a2010-12-30 01:11:18521 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
522 OnDidLoadResourceFromMemoryCache)
523 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
524 OnDidDisplayInsecureContent)
525 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
526 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25527 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26528 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21529 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20530 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
531 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16532 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10533 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50534 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50535 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
536 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55537 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
538 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02539 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
540 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]9f268072013-11-07 00:02:15541 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
542 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07543 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
544 OnShowValidationMessage)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
546 OnHideValidationMessage)
547 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
548 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48549#if defined(OS_ANDROID)
550 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
551 OnFindMatchRectsReply)
552 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
553 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48554#endif
[email protected]724159a2010-12-30 01:11:18555 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33556 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44557 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57558 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18559
[email protected]724159a2010-12-30 01:11:18560 return handled;
561}
562
[email protected]b172aee2012-04-10 17:05:26563void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18564 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21565 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43566 if (delegate_)
567 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18568}
569
[email protected]d1198fd2012-08-13 22:50:19570NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56571 return controller_;
572}
573
[email protected]d1198fd2012-08-13 22:50:19574const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56575 return controller_;
576}
577
[email protected]8ff00d72012-10-23 19:12:21578BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55579 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30580}
581
[email protected]b172aee2012-04-10 17:05:26582const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24583 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32584 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51585 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31586}
587
[email protected]a093ce02013-07-22 20:53:14588const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24589 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32590 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24591 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
592}
593
594const GURL& WebContentsImpl::GetLastCommittedURL() const {
595 // We may not have a navigation entry yet.
596 NavigationEntry* entry = controller_.GetLastCommittedEntry();
597 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
598}
599
[email protected]8ff00d72012-10-23 19:12:21600WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31601 return delegate_;
602}
603
[email protected]8ff00d72012-10-23 19:12:21604void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31605 // TODO(cbentzel): remove this debugging code?
606 if (delegate == delegate_)
607 return;
608 if (delegate_)
609 delegate_->Detach(this);
610 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08611 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31612 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08613 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00614 if (view_)
[email protected]e85165c642014-06-10 14:34:31615 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08616 }
[email protected]be1f56ab2011-12-22 06:55:31617}
618
[email protected]8ff00d72012-10-23 19:12:21619RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21620 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41621 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16622}
623
[email protected]60eca4eb2013-12-06 00:02:16624RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41625 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16626}
627
[email protected]9c9343b2014-03-08 02:56:07628RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
629 if (!frame_tree_.GetFocusedFrame())
630 return NULL;
631 return frame_tree_.GetFocusedFrame()->current_frame_host();
632}
633
[email protected]a86c0e962013-12-17 17:10:39634void WebContentsImpl::ForEachFrame(
635 const base::Callback<void(RenderFrameHost*)>& on_frame) {
636 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
637}
638
639void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
640 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
641 delete message;
642}
643
[email protected]b172aee2012-04-10 17:05:26644RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21645 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31646}
647
[email protected]6b618e62012-08-16 12:59:18648int WebContentsImpl::GetRoutingID() const {
649 if (!GetRenderViewHost())
650 return MSG_ROUTING_NONE;
651
652 return GetRenderViewHost()->GetRoutingID();
653}
654
[email protected]44470a22013-01-24 01:21:54655int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
656 return fullscreen_widget_routing_id_;
657}
658
[email protected]b172aee2012-04-10 17:05:26659RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21660 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31661}
662
[email protected]4aebbca2013-09-17 22:26:49663RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
664 const {
665 RenderWidgetHost* const widget_host =
666 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
667 GetFullscreenWidgetRoutingID());
668 return widget_host ? widget_host->GetView() : NULL;
669}
670
[email protected]8ff00d72012-10-23 19:12:21671WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31672 return view_.get();
673}
674
[email protected]8ff00d72012-10-23 19:12:21675WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56676 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03677 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
678 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22679 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58680 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22681 web_ui->SetController(controller);
682 return web_ui;
683 }
684
685 delete web_ui;
686 return NULL;
687}
688
[email protected]8ff00d72012-10-23 19:12:21689WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21690 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
691 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31692}
693
[email protected]8ff00d72012-10-23 19:12:21694WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21695 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34696}
697
[email protected]86ef6a392012-05-11 22:03:11698void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22699 if (GetUserAgentOverride() == override)
700 return;
701
702 renderer_preferences_.user_agent_override = override;
703
704 // Send the new override string to the renderer.
705 RenderViewHost* host = GetRenderViewHost();
706 if (host)
707 host->SyncRendererPrefs();
708
709 // Reload the page if a load is currently in progress to avoid having
710 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27711 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22712 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
713 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53714
715 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
716 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11717}
718
719const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22720 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11721}
722
[email protected]2ceee8f2014-01-14 18:02:08723#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41724void WebContentsImpl::SetParentNativeViewAccessible(
725gfx::NativeViewAccessible accessible_parent) {
726 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45727 if (GetRenderViewHost())
728 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41729}
730#endif
731
[email protected]fcf75d42013-12-03 20:11:26732const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55733 // Transient entries take precedence. They are used for interstitial pages
734 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23735 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08736 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21737 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30738 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23739 if (entry) {
[email protected]b5cca982011-05-26 04:42:08740 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23741 }
[email protected]fa944cb82013-11-15 17:51:21742 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
743 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58744 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54745 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32746 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54747 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35748 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26749 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54750 if (!title.empty())
751 return title;
752 }
753 }
754
755 // We use the title for the last committed entry rather than a pending
756 // navigation entry. For example, when the user types in a URL, we want to
757 // keep the old page's title until the new load has committed and we get a new
758 // title.
[email protected]96d185d2009-04-24 03:28:54759 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32760
[email protected]9eeafc012013-11-25 23:49:47761 // We make an exception for initial navigations.
762 if (controller_.IsInitialNavigation()) {
763 // We only want to use the title from the visible entry in one of two cases:
764 // 1. There's already a committed entry for an initial navigation, in which
765 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
766 // 2. The pending entry has been explicitly assigned a title to display.
767 //
768 // If there's no last committed entry and no assigned title, we should fall
769 // back to |page_title_when_no_navigation_entry_| rather than showing the
770 // URL.
771 if (entry ||
772 (controller_.GetVisibleEntry() &&
773 !controller_.GetVisibleEntry()->GetTitle().empty())) {
774 entry = controller_.GetVisibleEntry();
775 }
776 }
[email protected]59167c22013-06-03 18:07:32777
[email protected]45d0ef7f2011-01-05 13:46:23778 if (entry) {
[email protected]b5cca982011-05-26 04:42:08779 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23780 }
[email protected]987fc3a2011-05-26 14:18:09781
782 // |page_title_when_no_navigation_entry_| is finally used
783 // if no title cannot be retrieved.
784 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54785}
786
[email protected]b172aee2012-04-10 17:05:26787int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46788 return GetMaxPageIDForSiteInstance(GetSiteInstance());
789}
790
[email protected]b172aee2012-04-10 17:05:26791int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
792 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33793 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
794 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46795
[email protected]b6583592012-01-25 19:52:33796 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34797}
798
[email protected]b172aee2012-04-10 17:05:26799void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46800 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
801}
802
[email protected]b172aee2012-04-10 17:05:26803void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33804 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46805 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33806 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34807}
808
[email protected]ec6c05f2013-10-23 18:41:57809void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
810 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
811 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57812}
813
[email protected]b172aee2012-04-10 17:05:26814SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21815 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54816}
817
[email protected]b172aee2012-04-10 17:05:26818SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21819 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
820 GetRenderManager()->pending_render_view_host() :
821 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58822 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38823}
824
[email protected]b172aee2012-04-10 17:05:26825bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31826 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49827}
828
[email protected]6dfed692014-05-22 04:18:03829bool WebContentsImpl::IsLoadingToDifferentDocument() const {
830 return is_loading_ && is_load_to_different_document_;
831}
832
[email protected]b172aee2012-04-10 17:05:26833bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03834 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31835}
836
[email protected]b172aee2012-04-10 17:05:26837const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31838 return load_state_;
839}
840
[email protected]fcf75d42013-12-03 20:11:26841const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31842 return load_state_host_;
843}
844
[email protected]b172aee2012-04-10 17:05:26845uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31846 return upload_size_;
847}
848
[email protected]b172aee2012-04-10 17:05:26849uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31850 return upload_position_;
851}
852
[email protected]1ae93fb2013-06-14 03:38:56853std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56854 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39855 frame_tree_.ForEach(base::Bind(&CollectSites,
856 base::Unretained(GetBrowserContext()),
857 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56858 return sites;
859}
860
[email protected]b172aee2012-04-10 17:05:26861const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54862 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31863}
864
[email protected]b172aee2012-04-10 17:05:26865bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31866 return displayed_insecure_content_;
867}
868
[email protected]222f5822014-02-05 23:40:49869void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25870 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55871 ++capturer_count_;
872 DVLOG(1) << "There are now " << capturer_count_
873 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49874
875 // Note: This provides a hint to upstream code to size the views optimally
876 // for quality (e.g., to avoid scaling).
877 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
878 preferred_size_for_capture_ = capture_size;
879 OnPreferredSizeChanged(preferred_size_);
880 }
[email protected]54597982013-02-06 01:59:55881}
882
883void WebContentsImpl::DecrementCapturerCount() {
884 --capturer_count_;
885 DVLOG(1) << "There are now " << capturer_count_
886 << " capturing(s) of WebContentsImpl@" << this;
887 DCHECK_LE(0, capturer_count_);
888
[email protected]5a652232013-02-12 06:15:25889 if (is_being_destroyed_)
890 return;
891
[email protected]222f5822014-02-05 23:40:49892 if (capturer_count_ == 0) {
893 const gfx::Size old_size = preferred_size_for_capture_;
894 preferred_size_for_capture_ = gfx::Size();
895 OnPreferredSizeChanged(old_size);
896 }
897
[email protected]1ac10dca2013-08-20 20:47:04898 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55899 DVLOG(1) << "Executing delayed WasHidden().";
900 WasHidden();
901 }
[email protected]be1f56ab2011-12-22 06:55:31902}
903
[email protected]f2bd40812013-07-20 04:30:44904int WebContentsImpl::GetCapturerCount() const {
905 return capturer_count_;
906}
907
[email protected]b172aee2012-04-10 17:05:26908bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31909 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
910 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
911 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49912}
913
[email protected]b172aee2012-04-10 17:05:26914void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
915 int error_code) {
[email protected]443b80e2010-12-14 00:42:23916 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34917 return;
918
[email protected]443b80e2010-12-14 00:42:23919 crashed_status_ = status;
920 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21921 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34922}
923
[email protected]b172aee2012-04-10 17:05:26924base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31925 return crashed_status_;
926}
927
[email protected]b172aee2012-04-10 17:05:26928bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31929 return is_being_destroyed_;
930}
931
[email protected]b172aee2012-04-10 17:05:26932void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34933 if (delegate_)
934 delegate_->NavigationStateChanged(this, changed_flags);
935}
936
[email protected]9a890452014-02-13 22:21:02937base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
938 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33939}
940
[email protected]9e2e4632012-07-27 16:38:41941void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54942 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:59943
944 std::set<RenderWidgetHostImpl*> widgets = GetRenderWidgetHostsInTree();
945 for (std::set<RenderWidgetHostImpl*>::iterator iter = widgets.begin();
946 iter != widgets.end();
947 iter++) {
948 RenderWidgetHostView* rwhv = (*iter)->GetView();
949 if (rwhv) {
950 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43951#if defined(OS_MACOSX)
[email protected]de3c5d82014-05-28 22:12:59952 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43953#endif
[email protected]de3c5d82014-05-28 22:12:59954 }
[email protected]789e9152009-08-04 21:59:43955 }
[email protected]96d185d2009-04-24 03:28:54956
[email protected]9a890452014-02-13 22:21:02957 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38958
[email protected]b9769d82012-02-10 00:23:59959 // The resize rect might have changed while this was inactive -- send the new
960 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58961 RenderViewHostImpl* rvh =
962 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59963 if (rvh) {
964 rvh->ResizeRectChanged(GetRootWindowResizerRect());
965 }
[email protected]96d185d2009-04-24 03:28:54966
[email protected]c0d9d5672013-10-09 07:38:03967 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
968
[email protected]54597982013-02-06 01:59:55969 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31970}
971
[email protected]b172aee2012-04-10 17:05:26972void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55973 // If there are entities capturing screenshots or video (e.g., mirroring),
974 // don't activate the "disable rendering" optimization.
975 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52976 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55977 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26978 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52979 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33980 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52981 // calls us).
[email protected]de3c5d82014-05-28 22:12:59982 std::set<RenderWidgetHostImpl*> widgets = GetRenderWidgetHostsInTree();
983 for (std::set<RenderWidgetHostImpl*>::iterator iter = widgets.begin();
984 iter != widgets.end();
985 iter++) {
986 RenderWidgetHostView* rwhv = (*iter)->GetView();
987 if (rwhv)
988 rwhv->Hide();
989 }
[email protected]96d185d2009-04-24 03:28:54990 }
991
[email protected]c0d9d5672013-10-09 07:38:03992 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
993
[email protected]54597982013-02-06 01:59:55994 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37995}
996
[email protected]b172aee2012-04-10 17:05:26997bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31998 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27999 return WillNotifyDisconnection() &&
1000 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581001 !static_cast<RenderViewHostImpl*>(
1002 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311003}
1004
[email protected]1c3f80bd2014-04-08 23:02:061005void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1006 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1007 for_cross_site_transition);
1008}
1009
[email protected]b172aee2012-04-10 17:05:261010void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211011 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401012 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271013}
1014
[email protected]b172aee2012-04-10 17:05:261015WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441016 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451017 // We pass our own opener so that the cloned page can access it if it was
1018 // before.
[email protected]54944cde2012-12-09 09:24:591019 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451020 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591021 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191022 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221023 FOR_EACH_OBSERVER(WebContentsObserver,
1024 observers_,
1025 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271026 return tc;
1027}
1028
[email protected]14392a52012-05-02 20:28:441029void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211030 const NotificationSource& source,
1031 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441032 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211033 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1034 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501035 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1036 i != pending_widget_views_.end(); ++i) {
1037 if (host->GetView() == i->second) {
1038 pending_widget_views_.erase(i);
1039 break;
1040 }
1041 }
1042 break;
1043 }
[email protected]14392a52012-05-02 20:28:441044 default:
1045 NOTREACHED();
1046 }
1047}
1048
[email protected]ec6c05f2013-10-23 18:41:571049WebContents* WebContentsImpl::GetWebContents() {
1050 return this;
1051}
1052
[email protected]54944cde2012-12-09 09:24:591053void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211054 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361055 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211056 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431057 should_normally_be_visible_ = !params.initially_hidden;
1058
[email protected]fa944cb82013-11-15 17:51:211059 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041060 params.browser_context, params.site_instance, params.routing_id,
1061 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191062
[email protected]fc2b46b2014-05-03 16:33:451063 WebContentsViewDelegate* delegate =
1064 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1065
1066 if (browser_plugin_guest_) {
1067 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1068 this, delegate, &render_view_host_delegate_view_));
1069
1070 WebContentsViewGuest* rv = new WebContentsViewGuest(
1071 this, browser_plugin_guest_.get(), platform_view.Pass(),
1072 render_view_host_delegate_view_);
1073 render_view_host_delegate_view_ = rv;
1074 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191075 } else {
[email protected]fc2b46b2014-05-03 16:33:451076 // Regular WebContentsView.
1077 view_.reset(CreateWebContentsView(
1078 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191079 }
[email protected]fc2b46b2014-05-03 16:33:451080 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191081 CHECK(view_.get());
1082
[email protected]ed245db2012-12-18 08:00:451083 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591084 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191085
1086 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101087 if (opener_)
1088 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191089
1090 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211091 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1092 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101093
1094 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
1095
[email protected]c7654a232013-06-12 21:04:441096#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101097 date_time_chooser_.reset(new DateTimeChooserAndroid());
1098#endif
[email protected]d1198fd2012-08-13 22:50:191099}
1100
[email protected]7fff43e2013-05-21 20:21:101101void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1102 RemoveDestructionObserver(web_contents);
1103
[email protected]14392a52012-05-02 20:28:441104 // Clear the opener if it has been closed.
1105 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441106 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511107 return;
[email protected]14392a52012-05-02 20:28:441108 }
[email protected]ceee8cd2013-03-08 04:59:511109 // Clear a pending contents that has been closed before being shown.
1110 for (PendingContents::iterator iter = pending_contents_.begin();
1111 iter != pending_contents_.end();
1112 ++iter) {
1113 if (iter->second != web_contents)
1114 continue;
1115 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511116 return;
1117 }
1118 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441119}
1120
[email protected]7fff43e2013-05-21 20:21:101121void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1122 if (!ContainsKey(destruction_observers_, web_contents)) {
1123 destruction_observers_[web_contents] =
1124 new DestructionObserver(this, web_contents);
1125 }
1126}
1127
1128void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1129 DestructionObservers::iterator iter =
1130 destruction_observers_.find(web_contents);
1131 if (iter != destruction_observers_.end()) {
1132 delete destruction_observers_[web_contents];
1133 destruction_observers_.erase(iter);
1134 }
1135}
1136
[email protected]b172aee2012-04-10 17:05:261137void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311138 observers_.AddObserver(observer);
1139}
1140
[email protected]b172aee2012-04-10 17:05:261141void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311142 observers_.RemoveObserver(observer);
1143}
1144
[email protected]de3c5d82014-05-28 22:12:591145std::set<RenderWidgetHostImpl*> WebContentsImpl::GetRenderWidgetHostsInTree() {
1146 std::set<RenderWidgetHostImpl*> set;
1147 ForEachFrame(base::Bind(&AddRenderWidgetHostToSet, base::Unretained(&set)));
1148 return set;
1149}
1150
[email protected]b172aee2012-04-10 17:05:261151void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341152 if (delegate_)
1153 delegate_->ActivateContents(this);
1154}
1155
[email protected]b172aee2012-04-10 17:05:261156void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121157 if (delegate_)
1158 delegate_->DeactivateContents(this);
1159}
1160
[email protected]b172aee2012-04-10 17:05:261161void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481162 if (delegate_)
1163 delegate_->LostCapture();
1164}
1165
[email protected]b24b68a2012-09-24 21:57:261166void WebContentsImpl::RenderWidgetDeleted(
1167 RenderWidgetHostImpl* render_widget_host) {
1168 if (is_being_destroyed_) {
1169 // |created_widgets_| might have been destroyed.
1170 return;
1171 }
1172
1173 std::set<RenderWidgetHostImpl*>::iterator iter =
1174 created_widgets_.find(render_widget_host);
1175 if (iter != created_widgets_.end())
1176 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541177
1178 if (render_widget_host &&
1179 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491180 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1181 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541182 FOR_EACH_OBSERVER(WebContentsObserver,
1183 observers_,
1184 DidDestroyFullscreenWidget(
1185 fullscreen_widget_routing_id_));
1186 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1187 }
[email protected]b24b68a2012-09-24 21:57:261188}
1189
[email protected]b172aee2012-04-10 17:05:261190bool WebContentsImpl::PreHandleKeyboardEvent(
1191 const NativeWebKeyboardEvent& event,
1192 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481193 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131194 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481195}
1196
[email protected]b172aee2012-04-10 17:05:261197void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481198 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131199 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481200}
1201
[email protected]d92026ef2014-03-03 21:04:131202bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461203 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191204#if !defined(OS_MACOSX)
1205 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1206 // isn't done for two reasons:
1207 // -the OS already has a gesture to do this through pinch-zoom
1208 // -if a user starts an inertial scroll, let's go, and presses control
1209 // (i.e. control+tab) then the OS's buffered scroll events will come in
1210 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521211 if (delegate_ &&
1212 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551213 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1214 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1215 // gestures, which are regrettably easy to trigger accidentally.
1216 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521217 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1218 return true;
1219 }
[email protected]bccc4472013-04-18 16:37:191220#endif
[email protected]fb3f066e2013-02-12 19:12:521221 return false;
1222}
1223
[email protected]04bce562014-01-30 05:34:541224bool WebContentsImpl::PreHandleGestureEvent(
1225 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031226 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541227}
1228
[email protected]bab38af2014-03-30 17:37:291229bool WebContentsImpl::HandleGestureEvent(
1230 const blink::WebGestureEvent& event) {
1231 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1232 // Use them to implement browser zoom, as for HandleWheelEvent above.
1233 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331234 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291235 // The scale difference necessary to trigger a zoom action. Derived from
1236 // experimentation to find a value that feels reasonable.
1237 const float kZoomStepValue = 0.6f;
1238
1239 // Find the (absolute) thresholds on either side of the current zoom factor,
1240 // then convert those to actual numbers to trigger a zoom in or out.
1241 // This logic deliberately makes the range around the starting zoom value
1242 // for the gesture twice as large as the other ranges (i.e., the notches are
1243 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1244 // so that it's easier to get back to your starting point than it is to
1245 // overshoot.
1246 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1247 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1248 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1249 : -backStep;
1250 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1251 : backStep;
1252
[email protected]fb546cb2014-04-28 14:09:371253 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291254 if (totalPinchGestureAmount_ > zoomInThreshold) {
1255 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461256 if (delegate_)
1257 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291258 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1259 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461260 if (delegate_)
1261 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291262 }
1263 return true;
1264 }
1265
1266 return false;
1267}
1268
[email protected]2ceee8f2014-01-14 18:02:081269#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411270gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1271 return accessible_parent_;
1272}
1273#endif
1274
[email protected]b172aee2012-04-10 17:05:261275void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431276 if (delegate_)
1277 delegate_->HandleMouseDown();
1278}
1279
[email protected]b172aee2012-04-10 17:05:261280void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481281 if (delegate_)
1282 delegate_->HandleMouseUp();
1283}
1284
[email protected]590a634e2012-07-19 16:38:231285void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481286 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231287 delegate_->HandlePointerActivate();
1288}
1289
1290void WebContentsImpl::HandleGestureBegin() {
1291 if (delegate_)
1292 delegate_->HandleGestureBegin();
1293}
1294
1295void WebContentsImpl::HandleGestureEnd() {
1296 if (delegate_)
1297 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481298}
1299
[email protected]b172aee2012-04-10 17:05:261300void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491301 // This method is being called to enter or leave renderer-initiated fullscreen
1302 // mode. Either way, make sure any existing fullscreen widget is shut down
1303 // first.
1304 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1305 if (widget_view)
1306 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1307
[email protected]8a5e0ca2011-08-25 06:30:471308 if (delegate_)
1309 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371310
1311 FOR_EACH_OBSERVER(WebContentsObserver,
1312 observers_,
1313 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471314}
1315
[email protected]b172aee2012-04-10 17:05:261316bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381317 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121318}
1319
[email protected]a9c81f02012-06-01 00:15:441320void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1321 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371322 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441323 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371324 } else {
1325 GotResponseToLockMouseRequest(false);
1326 }
1327}
1328
[email protected]b172aee2012-04-10 17:05:261329void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371330 if (delegate_)
1331 delegate_->LostMouseLock();
1332}
1333
[email protected]bafe6cd2012-05-23 23:09:501334void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201335 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501336 int route_id,
[email protected]227692c52013-05-31 22:43:041337 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131338 const ViewHostMsg_CreateWindow_Params& params,
1339 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501340 // We usually create the new window in the same BrowsingInstance (group of
1341 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551342 // if the opener is being suppressed (in a non-guest), we create a new
1343 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251344 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551345
[email protected]04cbd3d2013-12-04 04:58:201346 // If the opener is to be suppressed, the new window can be in any process.
1347 // Since routing ids are process specific, we must not have one passed in
1348 // as argument here.
1349 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1350
[email protected]bafe6cd2012-05-23 23:09:501351 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551352 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571353 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501354 GetSiteInstance();
1355
[email protected]04cbd3d2013-12-04 04:58:201356 // A message to create a new window can only come from the active process for
1357 // this WebContentsImpl instance. If any other process sends the request,
1358 // it is invalid and the process must be terminated.
1359 if (GetRenderProcessHost()->GetID() != render_process_id) {
1360 base::ProcessHandle process_handle =
1361 RenderProcessHost::FromID(render_process_id)->GetHandle();
1362 if (process_handle != base::kNullProcessHandle) {
1363 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391364 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201365 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1366 }
1367 return;
1368 }
1369
[email protected]d1198fd2012-08-13 22:50:191370 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341371 //
1372 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301373 const std::string& partition_id =
1374 GetContentClient()->browser()->
1375 GetStoragePartitionIdForSite(GetBrowserContext(),
1376 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461377 StoragePartition* partition = BrowserContext::GetStoragePartition(
1378 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411379 DOMStorageContextWrapper* dom_storage_context =
1380 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191381 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1382 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1383 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371384
1385 if (delegate_ &&
1386 !delegate_->ShouldCreateWebContents(this,
1387 route_id,
1388 params.window_container_type,
1389 params.frame_name,
1390 params.target_url,
1391 partition_id,
1392 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011393 if (route_id != MSG_ROUTING_NONE &&
1394 !RenderViewHost::FromID(render_process_id, route_id)) {
1395 // If the embedder didn't create a WebContents for this route, we need to
1396 // delete the RenderView that had already been created.
1397 Send(new ViewMsg_Close(route_id));
1398 }
[email protected]dd6730412013-08-14 15:03:371399 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1400 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1401 main_frame_route_id);
1402 return;
1403 }
1404
1405 // Create the new web contents. This will automatically create the new
1406 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461407 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591408 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041409 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061410 create_params.opener = this;
1411 create_params.opener_suppressed = params.opener_suppressed;
1412 if (params.disposition == NEW_BACKGROUND_TAB)
1413 create_params.initially_hidden = true;
1414
[email protected]c4538072013-03-18 02:17:551415 if (!is_guest) {
1416 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451417 create_params.initial_size = GetContainerBounds().size();
[email protected]c4538072013-03-18 02:17:551418 } else {
[email protected]50d326e2014-05-20 17:59:061419 create_params.guest_instance_id =
[email protected]139355f2014-05-11 14:21:281420 GetBrowserContext()->GetGuestManager()->GetNextInstanceID();
[email protected]c4538072013-03-18 02:17:551421 }
[email protected]50d326e2014-05-20 17:59:061422 WebContentsImpl* new_contents = static_cast<WebContentsImpl*>(
1423 WebContents::Create(create_params));
1424 new_contents->GetController().SetSessionStorageNamespace(
1425 partition_id,
1426 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261427 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191428
[email protected]c4538072013-03-18 02:17:551429 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341430 // will be shown immediately).
1431 if (!params.opener_suppressed) {
1432 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451433 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501434
[email protected]d70bea92013-04-05 04:23:341435 // TODO(brettw): It seems bogus that we have to call this function on the
1436 // newly created object and give it one of its own member variables.
1437 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1438 }
[email protected]bafe6cd2012-05-23 23:09:501439 // Save the created window associated with the route so we can show it
1440 // later.
1441 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1442 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101443 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501444 }
1445
1446 if (delegate_) {
1447 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071448 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131449 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501450 }
1451
1452 if (params.opener_suppressed) {
1453 // When the opener is suppressed, the original renderer cannot access the
1454 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001455 bool was_blocked = false;
1456 if (delegate_) {
1457 gfx::Rect initial_pos;
1458 delegate_->AddNewContents(
1459 this, new_contents, params.disposition, initial_pos,
1460 params.user_gesture, &was_blocked);
1461 }
1462 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211463 OpenURLParams open_params(params.target_url,
1464 Referrer(),
1465 CURRENT_TAB,
1466 PAGE_TRANSITION_LINK,
1467 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301468 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001469 new_contents->OpenURL(open_params);
1470 }
[email protected]bafe6cd2012-05-23 23:09:501471 }
1472}
1473
[email protected]a8504022013-12-04 20:23:511474void WebContentsImpl::CreateNewWidget(int render_process_id,
1475 int route_id,
[email protected]180ef242013-11-07 06:50:461476 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511477 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501478}
1479
[email protected]a8504022013-12-04 20:23:511480void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1481 int route_id) {
1482 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501483}
1484
[email protected]a8504022013-12-04 20:23:511485void WebContentsImpl::CreateNewWidget(int render_process_id,
1486 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501487 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461488 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211489 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511490 // A message to create a new widget can only come from the active process for
1491 // this WebContentsImpl instance. If any other process sends the request,
1492 // it is invalid and the process must be terminated.
1493 if (process->GetID() != render_process_id) {
1494 base::ProcessHandle process_handle =
1495 RenderProcessHost::FromID(render_process_id)->GetHandle();
1496 if (process_handle != base::kNullProcessHandle) {
1497 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391498 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511499 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1500 }
1501 return;
1502 }
1503
[email protected]bafe6cd2012-05-23 23:09:501504 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041505 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261506 created_widgets_.insert(widget_host);
1507
[email protected]cfd80b02014-05-01 17:46:481508 RenderWidgetHostViewBase* widget_view =
1509 static_cast<RenderWidgetHostViewBase*>(
1510 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191511 if (!widget_view)
1512 return;
[email protected]bafe6cd2012-05-23 23:09:501513 if (!is_fullscreen) {
1514 // Popups should not get activated.
1515 widget_view->SetPopupType(popup_type);
1516 }
1517 // Save the created widget associated with the route so we can show it later.
1518 pending_widget_views_[route_id] = widget_view;
1519
1520#if defined(OS_MACOSX)
1521 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1522 // to allow it to survive the trip without being hosted.
1523 base::mac::NSObjectRetain(widget_view->GetNativeView());
1524#endif
1525}
1526
1527void WebContentsImpl::ShowCreatedWindow(int route_id,
1528 WindowOpenDisposition disposition,
1529 const gfx::Rect& initial_pos,
1530 bool user_gesture) {
1531 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001532 if (contents) {
1533 WebContentsDelegate* delegate = GetDelegate();
1534 if (delegate) {
1535 delegate->AddNewContents(
1536 this, contents, disposition, initial_pos, user_gesture, NULL);
1537 }
1538 }
[email protected]bafe6cd2012-05-23 23:09:501539}
1540
1541void WebContentsImpl::ShowCreatedWidget(int route_id,
1542 const gfx::Rect& initial_pos) {
1543 ShowCreatedWidget(route_id, false, initial_pos);
1544}
1545
1546void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1547 ShowCreatedWidget(route_id, true, gfx::Rect());
1548}
1549
1550void WebContentsImpl::ShowCreatedWidget(int route_id,
1551 bool is_fullscreen,
1552 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481553 RenderWidgetHostViewBase* widget_host_view =
1554 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501555 if (!widget_host_view)
1556 return;
[email protected]cfd80b02014-05-01 17:46:481557
1558 RenderWidgetHostView* view = NULL;
1559 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1560 if (guest && guest->embedder_web_contents()) {
1561 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1562 } else {
1563 view = GetRenderWidgetHostView();
1564 }
1565
[email protected]4aebbca2013-09-17 22:26:491566 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311567 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1568 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491569 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1570 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1571 delegate_->ToggleFullscreenModeForTab(this, true);
1572 } else {
[email protected]cfd80b02014-05-01 17:46:481573 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491574 }
[email protected]4aebbca2013-09-17 22:26:491575 FOR_EACH_OBSERVER(WebContentsObserver,
1576 observers_,
1577 DidShowFullscreenWidget(route_id));
1578 if (!widget_host_view->HasFocus())
1579 widget_host_view->Focus();
1580 } else {
[email protected]cfd80b02014-05-01 17:46:481581 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491582 }
[email protected]89054502012-06-03 10:29:241583
1584 RenderWidgetHostImpl* render_widget_host_impl =
1585 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1586 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311587 // Only allow privileged mouse lock for fullscreen render widget, which is
1588 // used to implement Pepper Flash fullscreen.
1589 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501590
1591#if defined(OS_MACOSX)
1592 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1593 // properly embedded (or purposefully ignored) we can release the retain we
1594 // took in CreateNewWidget().
1595 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1596#endif
1597}
1598
1599WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1600 PendingContents::iterator iter = pending_contents_.find(route_id);
1601
1602 // Certain systems can block the creation of new windows. If we didn't succeed
1603 // in creating one, just return NULL.
1604 if (iter == pending_contents_.end()) {
1605 return NULL;
1606 }
1607
1608 WebContentsImpl* new_contents = iter->second;
1609 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101610 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501611
[email protected]d70bea92013-04-05 04:23:341612 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251613 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341614 return new_contents;
1615
[email protected]bafe6cd2012-05-23 23:09:501616 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1617 !new_contents->GetRenderViewHost()->GetView())
1618 return NULL;
1619
1620 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1621 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1622 return new_contents;
1623}
1624
1625RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1626 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1627 if (iter == pending_widget_views_.end()) {
1628 DCHECK(false);
1629 return NULL;
1630 }
1631
1632 RenderWidgetHostView* widget_host_view = iter->second;
1633 pending_widget_views_.erase(route_id);
1634
1635 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1636 if (!widget_host->GetProcess()->HasConnection()) {
1637 // The view has gone away or the renderer crashed. Nothing to do.
1638 return NULL;
1639 }
1640
1641 return widget_host_view;
1642}
1643
[email protected]f13b4202012-06-12 23:53:231644void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091645 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211646 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371647 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231648 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371649 } else {
1650 callback.Run(MediaStreamDevices(),
1651 MEDIA_DEVICE_INVALID_STATE,
1652 scoped_ptr<MediaStreamUI>());
1653 }
[email protected]f13b4202012-06-12 23:53:231654}
1655
[email protected]cc9200432013-07-23 23:02:401656SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1657 SiteInstance* instance) {
1658 return controller_.GetSessionStorageNamespace(instance);
1659}
1660
[email protected]6de7fc482014-06-06 10:46:441661SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1662 return controller_.GetSessionStorageNamespaceMap();
1663}
1664
[email protected]9b159a52013-10-03 17:24:551665FrameTree* WebContentsImpl::GetFrameTree() {
1666 return &frame_tree_;
1667}
1668
[email protected]31a71eaf2014-03-13 01:47:361669void WebContentsImpl::AccessibilityEventReceived(
1670 const std::vector<AXEventNotificationDetails>& details) {
1671 FOR_EACH_OBSERVER(
1672 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1673}
1674
[email protected]edc3af82013-12-12 21:24:071675void WebContentsImpl::OnShowValidationMessage(
1676 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291677 const base::string16& main_text,
1678 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071679 if (delegate_)
1680 delegate_->ShowValidationMessage(
1681 this, anchor_in_root_view, main_text, sub_text);
1682}
1683
1684void WebContentsImpl::OnHideValidationMessage() {
1685 if (delegate_)
1686 delegate_->HideValidationMessage(this);
1687}
1688
1689void WebContentsImpl::OnMoveValidationMessage(
1690 const gfx::Rect& anchor_in_root_view) {
1691 if (delegate_)
1692 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1693}
1694
[email protected]32deec62013-05-15 23:55:041695void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1696 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441697 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041698}
1699
[email protected]e85165c642014-06-10 14:34:311700void WebContentsImpl::OnTouchEmulationEnabled(bool enabled) {
1701 touch_emulation_enabled_ = enabled;
1702 if (view_)
1703 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
1704}
1705
[email protected]b172aee2012-04-10 17:05:261706void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491707 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231708 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491709 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331710}
1711
[email protected]b172aee2012-04-10 17:05:261712void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341713 if (delegate_)
1714 delegate_->ResizeDueToAutoResize(this, new_size);
1715}
1716
[email protected]b172aee2012-04-10 17:05:261717WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201718 if (!delegate_)
1719 return NULL;
[email protected]00c37fc2011-08-02 00:22:501720
[email protected]e5d549d2011-12-28 01:29:201721 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201722 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341723}
1724
[email protected]6b618e62012-08-16 12:59:181725bool WebContentsImpl::Send(IPC::Message* message) {
1726 if (!GetRenderViewHost()) {
1727 delete message;
1728 return false;
1729 }
1730
1731 return GetRenderViewHost()->Send(message);
1732}
1733
[email protected]b172aee2012-04-10 17:05:261734bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501735 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261736 FrameTreeNode* node = frame_tree_.root();
1737
1738 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1739 // specified in the pending entry.
1740 NavigationEntryImpl* pending_entry =
1741 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1742 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1743 pending_entry->frame_tree_node_id() != -1) {
1744 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1745 }
1746
1747 return node->navigator()->NavigateToPendingEntry(
1748 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541749}
[email protected]96d185d2009-04-24 03:28:541750
[email protected]a86c0e962013-12-17 17:10:391751void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1752 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441753 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391754 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441755}
1756
[email protected]20ca0382013-02-28 19:50:071757void WebContentsImpl::AttachInterstitialPage(
1758 InterstitialPageImpl* interstitial_page) {
1759 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211760 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291761
1762 // Cancel any visible dialogs so that they don't interfere with the
1763 // interstitial.
1764 if (dialog_manager_)
1765 dialog_manager_->CancelActiveAndPendingDialogs(this);
1766
[email protected]20ca0382013-02-28 19:50:071767 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1768 DidAttachInterstitialPage());
1769}
1770
1771void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571772 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211773 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071774 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1775 DidDetachInterstitialPage());
1776}
1777
[email protected]b172aee2012-04-10 17:05:261778void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331779 const SiteInstance* site_instance,
1780 int history_length,
1781 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411782 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1783 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211784 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191785 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141786 return;
[email protected]9e1ad4b2011-08-14 16:49:191787 }
[email protected]9f76c1e2012-03-05 15:15:581788 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191789 if (!rvh) {
1790 NOTREACHED();
1791 return;
1792 }
[email protected]9f76c1e2012-03-05 15:15:581793 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191794 NOTREACHED();
1795 return;
1796 }
[email protected]6b618e62012-08-16 12:59:181797 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1798 history_length,
1799 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141800}
1801
[email protected]4fed3702014-04-01 09:08:001802void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171803 RenderFrameHost* focused_frame = GetFocusedFrame();
1804 if (!focused_frame)
1805 return;
1806
[email protected]959be4c2014-04-08 15:01:331807 focused_frame->Send(new FrameMsg_Reload(
1808 focused_frame->GetRoutingID(), ignore_cache));
1809}
1810
1811void WebContentsImpl::Undo() {
1812 RenderFrameHost* focused_frame = GetFocusedFrame();
1813 if (!focused_frame)
1814 return;
1815
1816 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1817 RecordAction(base::UserMetricsAction("Undo"));
1818}
1819
1820void WebContentsImpl::Redo() {
1821 RenderFrameHost* focused_frame = GetFocusedFrame();
1822 if (!focused_frame)
1823 return;
1824 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1825 RecordAction(base::UserMetricsAction("Redo"));
1826}
1827
1828void WebContentsImpl::Cut() {
1829 RenderFrameHost* focused_frame = GetFocusedFrame();
1830 if (!focused_frame)
1831 return;
1832
1833 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1834 RecordAction(base::UserMetricsAction("Cut"));
1835}
1836
1837void WebContentsImpl::Copy() {
1838 RenderFrameHost* focused_frame = GetFocusedFrame();
1839 if (!focused_frame)
1840 return;
1841
1842 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1843 RecordAction(base::UserMetricsAction("Copy"));
1844}
1845
1846void WebContentsImpl::CopyToFindPboard() {
1847#if defined(OS_MACOSX)
1848 RenderFrameHost* focused_frame = GetFocusedFrame();
1849 if (!focused_frame)
1850 return;
1851
1852 // Windows/Linux don't have the concept of a find pasteboard.
1853 focused_frame->Send(
1854 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1855 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1856#endif
1857}
1858
1859void WebContentsImpl::Paste() {
1860 RenderFrameHost* focused_frame = GetFocusedFrame();
1861 if (!focused_frame)
1862 return;
1863
1864 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1865 RecordAction(base::UserMetricsAction("Paste"));
1866}
1867
1868void WebContentsImpl::PasteAndMatchStyle() {
1869 RenderFrameHost* focused_frame = GetFocusedFrame();
1870 if (!focused_frame)
1871 return;
1872
1873 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1874 focused_frame->GetRoutingID()));
1875 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1876}
1877
1878void WebContentsImpl::Delete() {
1879 RenderFrameHost* focused_frame = GetFocusedFrame();
1880 if (!focused_frame)
1881 return;
1882
1883 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1884 RecordAction(base::UserMetricsAction("DeleteSelection"));
1885}
1886
1887void WebContentsImpl::SelectAll() {
1888 RenderFrameHost* focused_frame = GetFocusedFrame();
1889 if (!focused_frame)
1890 return;
1891
1892 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1893 RecordAction(base::UserMetricsAction("SelectAll"));
1894}
1895
1896void WebContentsImpl::Unselect() {
1897 RenderFrameHost* focused_frame = GetFocusedFrame();
1898 if (!focused_frame)
1899 return;
1900
1901 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1902 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171903}
1904
1905void WebContentsImpl::Replace(const base::string16& word) {
1906 RenderFrameHost* focused_frame = GetFocusedFrame();
1907 if (!focused_frame)
1908 return;
1909
[email protected]959be4c2014-04-08 15:01:331910 focused_frame->Send(new InputMsg_Replace(
1911 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171912}
1913
1914void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1915 RenderFrameHost* focused_frame = GetFocusedFrame();
1916 if (!focused_frame)
1917 return;
1918
[email protected]959be4c2014-04-08 15:01:331919 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1920 focused_frame->GetRoutingID(), word));
1921}
1922
1923void WebContentsImpl::NotifyContextMenuClosed(
1924 const CustomContextMenuContext& context) {
1925 RenderFrameHost* focused_frame = GetFocusedFrame();
1926 if (!focused_frame)
1927 return;
1928
1929 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1930 focused_frame->GetRoutingID(), context));
1931}
1932
1933void WebContentsImpl::ExecuteCustomContextMenuCommand(
1934 int action, const CustomContextMenuContext& context) {
1935 RenderFrameHost* focused_frame = GetFocusedFrame();
1936 if (!focused_frame)
1937 return;
1938
1939 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1940 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001941}
1942
[email protected]fc2b46b2014-05-03 16:33:451943gfx::NativeView WebContentsImpl::GetNativeView() {
1944 return view_->GetNativeView();
1945}
1946
1947gfx::NativeView WebContentsImpl::GetContentNativeView() {
1948 return view_->GetContentNativeView();
1949}
1950
1951gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1952 return view_->GetTopLevelNativeWindow();
1953}
1954
1955gfx::Rect WebContentsImpl::GetViewBounds() {
1956 return view_->GetViewBounds();
1957}
1958
1959gfx::Rect WebContentsImpl::GetContainerBounds() {
1960 gfx::Rect rv;
1961 view_->GetContainerBounds(&rv);
1962 return rv;
1963}
1964
1965DropData* WebContentsImpl::GetDropData() {
1966 return view_->GetDropData();
1967}
1968
1969void WebContentsImpl::Focus() {
1970 view_->Focus();
1971}
1972
1973void WebContentsImpl::SetInitialFocus() {
1974 view_->SetInitialFocus();
1975}
1976
1977void WebContentsImpl::StoreFocus() {
1978 view_->StoreFocus();
1979}
1980
1981void WebContentsImpl::RestoreFocus() {
1982 view_->RestoreFocus();
1983}
1984
[email protected]b172aee2012-04-10 17:05:261985void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271986 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211987 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541988 return;
1989 }
[email protected]9f76c1e2012-03-05 15:15:581990 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541991}
1992
[email protected]b172aee2012-04-10 17:05:261993bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211994 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541995}
1996
[email protected]b172aee2012-04-10 17:05:261997InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211998 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221999}
2000
[email protected]b172aee2012-04-10 17:05:262001bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162002 // WebKit creates Document object when MIME type is application/xhtml+xml,
2003 // so we also support this MIME type.
2004 return contents_mime_type_ == "text/html" ||
2005 contents_mime_type_ == "text/xml" ||
2006 contents_mime_type_ == "application/xhtml+xml" ||
2007 contents_mime_type_ == "text/plain" ||
2008 contents_mime_type_ == "text/css" ||
2009 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2010}
2011
[email protected]b172aee2012-04-10 17:05:262012void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592013 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162014 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552015 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012016 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142017 return;
[email protected]c7dd2f62011-07-18 15:57:592018 }
2019
2020 Stop();
2021
2022 // Create the save package and possibly prompt the user for the name to save
2023 // the page as. The user prompt is an asynchronous operation that runs on
2024 // another thread.
2025 save_package_ = new SavePackage(this);
2026 save_package_->GetSaveInfo();
2027}
2028
2029// Used in automated testing to bypass prompting the user for file names.
2030// Instead, the names and paths are hard coded rather than running them through
2031// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342032bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2033 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212034 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592035 // Stop the page from navigating.
2036 Stop();
2037
2038 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212039 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592040}
2041
[email protected]3c71576ce2013-07-23 02:00:012042void WebContentsImpl::SaveFrame(const GURL& url,
2043 const Referrer& referrer) {
2044 if (!GetURL().is_valid())
2045 return;
2046 bool is_main_frame = (url == GetURL());
2047
2048 DownloadManager* dlm =
2049 BrowserContext::GetDownloadManager(GetBrowserContext());
2050 if (!dlm)
2051 return;
2052 int64 post_id = -1;
2053 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272054 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012055 if (entry)
2056 post_id = entry->GetPostID();
2057 }
2058 scoped_ptr<DownloadUrlParameters> params(
2059 DownloadUrlParameters::FromWebContents(this, url));
2060 params->set_referrer(referrer);
2061 params->set_post_id(post_id);
2062 params->set_prefer_cache(true);
2063 if (post_id >= 0)
2064 params->set_method("POST");
2065 params->set_prompt(true);
2066 dlm->DownloadUrl(params.Pass());
2067}
2068
[email protected]b172aee2012-04-10 17:05:262069void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342070 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482071 const base::Callback<void(int64)>& callback) {
2072 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122073}
2074
[email protected]b172aee2012-04-10 17:05:262075const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272076 return contents_mime_type_;
2077}
2078
[email protected]b172aee2012-04-10 17:05:262079bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272080 return notify_disconnection_;
2081}
2082
[email protected]b172aee2012-04-10 17:05:262083void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312084 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182085 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162086}
2087
[email protected]b172aee2012-04-10 17:05:262088void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542089 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182090 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162091}
2092
[email protected]8ff00d72012-10-23 19:12:212093RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272094 return &renderer_preferences_;
2095}
2096
[email protected]e35ccd52012-05-23 16:22:472097void WebContentsImpl::Close() {
2098 Close(GetRenderViewHost());
2099}
2100
[email protected]cf200a562013-05-03 16:24:292101void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462102 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292103 if (browser_plugin_embedder_.get())
2104 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2105 screen_x, screen_y, operation);
2106 if (GetRenderViewHost())
2107 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2108 screen_x, screen_y, operation);
2109}
2110
[email protected]d60f3702013-12-26 16:30:242111void WebContentsImpl::DidGetResourceResponseStart(
2112 const ResourceRequestDetails& details) {
2113 controller_.ssl_manager()->DidStartResourceResponse(details);
2114
2115 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2116 DidGetResourceResponseStart(details));
2117
2118 // TODO(avi): Remove. http://crbug.com/170921
2119 NotificationService::current()->Notify(
2120 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2121 Source<WebContents>(this),
2122 Details<const ResourceRequestDetails>(&details));
2123}
2124
2125void WebContentsImpl::DidGetRedirectForResourceRequest(
2126 RenderViewHost* render_view_host,
2127 const ResourceRedirectDetails& details) {
2128 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2129
2130 FOR_EACH_OBSERVER(
2131 WebContentsObserver,
2132 observers_,
2133 DidGetRedirectForResourceRequest(render_view_host, details));
2134
2135 // TODO(avi): Remove. http://crbug.com/170921
2136 NotificationService::current()->Notify(
2137 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2138 Source<WebContents>(this),
2139 Details<const ResourceRedirectDetails>(&details));
2140}
2141
[email protected]b172aee2012-04-10 17:05:262142void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522143 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582144 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512145 if (delegate_)
2146 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292147 if (browser_plugin_embedder_.get())
2148 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342149}
2150
[email protected]e35ccd52012-05-23 16:22:472151void WebContentsImpl::UserGestureDone() {
2152 OnUserGesture();
2153}
2154
[email protected]b172aee2012-04-10 17:05:262155void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272156 closed_by_user_gesture_ = value;
2157}
2158
[email protected]b172aee2012-04-10 17:05:262159bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272160 return closed_by_user_gesture_;
2161}
2162
[email protected]b172aee2012-04-10 17:05:262163int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592164 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172165 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012166 // Calculate the zoom percent from the factor. Round up to the nearest whole
2167 // number.
[email protected]b75b8292010-10-01 07:28:252168 int percent = static_cast<int>(
[email protected]fce823222014-05-30 16:24:302169 ZoomLevelToZoomFactor(HostZoomMap::GetZoomLevel(this)) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252170 *enable_decrement = percent > minimum_zoom_percent_;
2171 *enable_increment = percent < maximum_zoom_percent_;
2172 return percent;
2173}
2174
[email protected]b172aee2012-04-10 17:05:262175void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502176 if (!delegate_)
2177 return;
2178
[email protected]6286a372013-10-09 04:03:272179 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2180 if (!entry)
[email protected]1788e772010-12-15 16:40:502181 return;
2182
[email protected]6286a372013-10-09 04:03:272183 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122184}
2185
[email protected]b172aee2012-04-10 17:05:262186void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042187 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272188 if (!delegate_)
2189 return;
2190
[email protected]691aa2f2013-05-28 22:52:042191 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272192}
2193
[email protected]b172aee2012-04-10 17:05:262194int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272195 return minimum_zoom_percent_;
2196}
2197
[email protected]b172aee2012-04-10 17:05:262198int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272199 return maximum_zoom_percent_;
2200}
2201
[email protected]b172aee2012-04-10 17:05:262202gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492203 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232204}
2205
[email protected]b172aee2012-04-10 17:05:262206bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052207 if (GetBrowserPluginGuest())
2208 return GetBrowserPluginGuest()->LockMouse(allowed);
2209
[email protected]0bfbf882011-12-22 18:19:272210 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582211 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272212}
2213
[email protected]b172aee2012-04-10 17:05:262214bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442215 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502216}
2217
[email protected]cb805452013-05-22 15:16:212218void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482219 if (!color_chooser_info_.get())
2220 return;
2221 RenderFrameHost* rfh = RenderFrameHost::FromID(
2222 color_chooser_info_->render_process_id,
2223 color_chooser_info_->render_frame_id);
2224 if (!rfh)
2225 return;
2226
2227 rfh->Send(new FrameMsg_DidChooseColorResponse(
2228 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202229}
2230
[email protected]cb805452013-05-22 15:16:212231void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482232 if (!color_chooser_info_.get())
2233 return;
2234 RenderFrameHost* rfh = RenderFrameHost::FromID(
2235 color_chooser_info_->render_process_id,
2236 color_chooser_info_->render_frame_id);
2237 if (!rfh)
2238 return;
2239
2240 rfh->Send(new FrameMsg_DidEndColorChooser(
2241 rfh->GetRoutingID(), color_chooser_info_->identifier));
2242 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202243}
2244
[email protected]41225fe2013-03-29 05:32:022245int WebContentsImpl::DownloadImage(const GURL& url,
2246 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302247 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022248 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582249 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022250 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392251 return id;
2252}
2253
[email protected]5dcaf8e2013-12-28 01:31:422254bool WebContentsImpl::IsSubframe() const {
2255 return is_subframe_;
2256}
2257
[email protected]36ec24f2014-01-09 00:32:082258void WebContentsImpl::Find(int request_id,
2259 const base::string16& search_text,
2260 const blink::WebFindOptions& options) {
2261 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2262}
2263
2264void WebContentsImpl::StopFinding(StopFindAction action) {
2265 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2266}
2267
[email protected]4fe53add2014-04-08 19:53:362268void WebContentsImpl::InsertCSS(const std::string& css) {
2269 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2270 GetMainFrame()->GetRoutingID(), css));
2271}
2272
[email protected]b172aee2012-04-10 17:05:262273bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272274 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172275 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332276 return true;
2277 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272278}
2279
[email protected]b172aee2012-04-10 17:05:262280void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272281 if (delegate_)
2282 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212283}
2284
[email protected]52913802013-12-10 05:52:182285void WebContentsImpl::DidStartProvisionalLoad(
2286 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072287 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182288 const GURL& validated_url,
2289 bool is_error_page,
2290 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262291 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]d974a0a2013-01-10 01:43:572292
[email protected]0d60f0192011-04-14 12:40:102293 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272294 int render_frame_id = render_frame_host->GetRoutingID();
2295 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252296 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072297 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272298 render_frame_id, parent_routing_id, is_main_frame,
2299 validated_url, is_error_page, is_iframe_srcdoc,
2300 render_view_host));
[email protected]400992b2012-06-14 00:03:542301
2302 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182303 FOR_EACH_OBSERVER(
2304 WebContentsObserver,
2305 observers_,
2306 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582307 render_frame_host));
[email protected]400992b2012-06-14 00:03:542308 }
2309}
2310
[email protected]3109fbb72014-01-06 23:57:152311void WebContentsImpl::DidFailProvisionalLoadWithError(
2312 RenderFrameHostImpl* render_frame_host,
2313 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2314 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272315 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262316 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272317 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152318 FOR_EACH_OBSERVER(
2319 WebContentsObserver,
2320 observers_,
[email protected]161eabd2014-03-19 19:47:272321 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152322 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262323 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152324 validated_url,
2325 params.error_code,
2326 params.error_description,
[email protected]161eabd2014-03-19 19:47:272327 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152328}
2329
[email protected]b80624c2014-02-09 02:46:552330void WebContentsImpl::DidFailLoadWithError(
2331 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552332 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552333 int error_code,
2334 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272335 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262336 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272337 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552338 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272339 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262340 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552341}
2342
[email protected]52913802013-12-10 05:52:182343void WebContentsImpl::NotifyChangedNavigationState(
2344 InvalidateTypes changed_flags) {
2345 NotifyNavigationStateChanged(changed_flags);
2346}
2347
[email protected]3691e5cf2014-01-22 10:16:202348void WebContentsImpl::AboutToNavigateRenderFrame(
2349 RenderFrameHostImpl* render_frame_host) {
2350 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272351 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202352 FOR_EACH_OBSERVER(
2353 WebContentsObserver,
2354 observers_,
[email protected]161eabd2014-03-19 19:47:272355 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202356}
2357
2358void WebContentsImpl::DidStartNavigationToPendingEntry(
2359 RenderFrameHostImpl* render_frame_host,
2360 const GURL& url,
2361 NavigationController::ReloadType reload_type) {
2362 // Notify observers about navigation.
2363 FOR_EACH_OBSERVER(
2364 WebContentsObserver,
2365 observers_,
2366 DidStartNavigationToPendingEntry(url, reload_type));
2367}
2368
[email protected]8cb834e2014-03-06 14:23:232369void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2370 const OpenURLParams& params) {
2371 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182372 WebContents* new_contents = OpenURL(params);
2373
2374 if (new_contents) {
2375 // Notify observers.
2376 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2377 DidOpenRequestedURL(new_contents,
2378 params.url,
2379 params.referrer,
2380 params.disposition,
2381 params.transition,
[email protected]8cb834e2014-03-06 14:23:232382 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182383 }
2384}
2385
[email protected]aa62afd2014-04-22 19:22:462386bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2387 if (!delegate_)
2388 return false;
2389 return delegate_->ShouldPreserveAbortedURLs(this);
2390}
2391
[email protected]400992b2012-06-14 00:03:542392void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582393 RenderFrameHostImpl* render_frame_host,
2394 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542395 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582396 FOR_EACH_OBSERVER(
2397 WebContentsObserver,
2398 observers_,
2399 ProvisionalChangeToMainFrameUrl(validated_target_url,
2400 render_frame_host));
[email protected]724159a2010-12-30 01:11:182401}
2402
[email protected]37567b432014-02-12 01:12:222403void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432404 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222405 const base::string16& frame_unique_name,
2406 bool is_main_frame,
2407 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432408 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432409 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272410 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222411 // Notify observers about the commit of the provisional load.
2412 FOR_EACH_OBSERVER(
2413 WebContentsObserver,
2414 observers_,
[email protected]27dd82fd2014-03-03 22:11:432415 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222416 frame_unique_name,
2417 is_main_frame,
2418 url,
2419 transition_type,
2420 render_view_host));
2421}
2422
[email protected]0d0f4c492014-04-02 06:42:572423void WebContentsImpl::DidNavigateMainFramePreCommit(
2424 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2425 // Ensure fullscreen mode is exited before committing the navigation to a
2426 // different page. The next page will not start out assuming it is in
2427 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192428 if (controller_.IsURLInPageNavigation(params.url,
2429 params.was_within_same_page,
2430 NAVIGATION_TYPE_UNKNOWN)) {
2431 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572432 return;
2433 }
2434 if (IsFullscreenForCurrentTab())
2435 GetRenderViewHost()->ExitFullscreen();
2436 DCHECK(!IsFullscreenForCurrentTab());
2437}
2438
[email protected]37567b432014-02-12 01:12:222439void WebContentsImpl::DidNavigateMainFramePostCommit(
2440 const LoadCommittedDetails& details,
2441 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2442 if (details.is_navigation_to_different_page()) {
2443 // Clear the status bubble. This is a workaround for a bug where WebKit
2444 // doesn't let us know that the cursor left an element during a
2445 // transition (this is also why the mouse cursor remains as a hand after
2446 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2447 // clear the bubble when a user navigates to a named anchor in the same
2448 // page.
2449 UpdateTargetURL(details.entry->GetPageID(), GURL());
2450 }
2451
2452 if (!details.is_in_page) {
2453 // Once the main frame is navigated, we're no longer considered to have
2454 // displayed insecure content.
2455 displayed_insecure_content_ = false;
2456 SSLManager::NotifySSLInternalStateChanged(
2457 GetController().GetBrowserContext());
2458 }
2459
2460 // Notify observers about navigation.
2461 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2462 DidNavigateMainFrame(details, params));
2463
[email protected]e85165c642014-06-10 14:34:312464 if (delegate_)
[email protected]37567b432014-02-12 01:12:222465 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312466 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222467}
2468
2469void WebContentsImpl::DidNavigateAnyFramePostCommit(
2470 RenderFrameHostImpl* render_frame_host,
2471 const LoadCommittedDetails& details,
2472 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102473 // Now that something has committed, we don't need to track whether the
2474 // initial page has been accessed.
2475 has_accessed_initial_document_ = false;
2476
[email protected]37567b432014-02-12 01:12:222477 // If we navigate off the page, close all JavaScript dialogs.
2478 if (dialog_manager_ && !details.is_in_page)
2479 dialog_manager_->CancelActiveAndPendingDialogs(this);
2480
2481 // Notify observers about navigation.
2482 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2483 DidNavigateAnyFrame(details, params));
2484}
2485
2486void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2487 contents_mime_type_ = mime_type;
2488}
2489
[email protected]277857a2014-06-03 10:38:012490bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312491 // Disable overscroll when touch emulation is on. See crbug.com/369938.
2492 if (touch_emulation_enabled_)
2493 return false;
2494
[email protected]37567b432014-02-12 01:12:222495 if (delegate_)
2496 return delegate_->CanOverscrollContent();
2497
2498 return false;
2499}
2500
[email protected]b172aee2012-04-10 17:05:262501void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182502 const GURL& url,
[email protected]70435962011-08-02 20:13:282503 const std::string& security_info,
2504 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182505 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282506 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192507 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182508 cache.Increment();
2509
2510 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082511 int cert_id = 0;
2512 net::CertStatus cert_status = 0;
2513 int security_bits = -1;
2514 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122515 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212516 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122517 &security_bits, &connection_status,
2518 &signed_certificate_timestamp_ids);
2519 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212520 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002521 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2522 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182523
[email protected]b0f724c2013-09-05 04:21:132524 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2525
2526 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2527 DidLoadResourceFromMemoryCache(details));
2528
[email protected]8bfc8272013-09-09 20:10:532529 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2530 scoped_refptr<net::URLRequestContextGetter> request_context(
2531 resource_type == ResourceType::MEDIA ?
2532 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2533 GetRenderProcessHost()->GetID()) :
2534 GetBrowserContext()->GetRequestContextForRenderProcess(
2535 GetRenderProcessHost()->GetID()));
2536 BrowserThread::PostTask(
2537 BrowserThread::IO,
2538 FROM_HERE,
2539 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2540 }
[email protected]724159a2010-12-30 01:11:182541}
2542
[email protected]b172aee2012-04-10 17:05:262543void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392544 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182545 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192546 SSLManager::NotifySSLInternalStateChanged(
2547 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182548}
2549
[email protected]b172aee2012-04-10 17:05:262550void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022551 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582552 LOG(WARNING) << security_origin << " ran insecure content from "
2553 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392554 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412555 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392556 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182557 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412558 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192559 SSLManager::NotifySSLInternalStateChanged(
2560 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182561}
2562
[email protected]501052ff2014-02-21 22:19:072563void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572564 CHECK(render_frame_message_source_);
2565 CHECK(!render_view_message_source_);
2566 RenderFrameHostImpl* rfh =
2567 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2568
[email protected]161eabd2014-03-19 19:47:272569 int render_frame_id = rfh->GetRoutingID();
2570 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572571 FOR_EACH_OBSERVER(WebContentsObserver,
2572 observers_,
[email protected]161eabd2014-03-19 19:47:272573 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182574}
2575
[email protected]b172aee2012-04-10 17:05:262576void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262577 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372578 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122579 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2580 GetRenderProcessHost()->ReceivedBadMessage();
2581 return;
2582 }
[email protected]a1b99262013-12-27 21:56:222583
[email protected]8b3af1e2014-01-24 13:29:122584 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442585 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372586 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422587 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372588
[email protected]61ac9e242014-03-21 20:55:262589 RenderFrameHostImpl* rfh =
2590 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272591 int render_frame_id = rfh->GetRoutingID();
2592 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262593 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252594 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272595 DidFinishLoad(render_frame_id, validated_url,
2596 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312597}
2598
[email protected]960b0372014-05-19 18:01:002599void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2600 RenderFrameHostImpl* rfh =
2601 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2602 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2603
2604 // It is possible to get multiple calls to OnDidStartLoading that don't have
2605 // corresponding calls to OnDidStopLoading:
2606 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2607 // out for a cross-process navigation, and it turns into a placeholder for
2608 // one being rendered in a different process.
2609 // - Also, there might be more than one RenderFrameHost sharing the same
2610 // FrameTreeNode (and thus sharing its ID) each sending a start.
2611 // - But in the future, once clamy@ moves navigation network requests to the
2612 // browser process, there's a good chance that callbacks about starting and
2613 // stopping will all be handled by the browser. When that happens, there
2614 // should no longer be a start/stop call imbalance. TODO(avi): When this
2615 // future arrives, update this code to not allow this case.
2616 DCHECK_GE(loading_frames_in_progress_, 0);
2617 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2618 if (loading_frames_in_progress_ == 0)
2619 DidStartLoading(rfh, to_different_document);
2620 ++loading_frames_in_progress_;
2621 }
2622
2623 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2624 SendLoadProgressChanged();
2625}
2626
2627void WebContentsImpl::OnDidStopLoading() {
2628 RenderFrameHostImpl* rfh =
2629 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2630 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2631
2632 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2633 // Load stopped while we were still tracking load. Make sure we update
2634 // progress based on this frame's completion.
2635 loading_progresses_[render_frame_id] = 1.0;
2636 SendLoadProgressChanged();
2637 // Then we clean-up our states.
2638 if (loading_total_progress_ == 1.0)
2639 ResetLoadProgressState();
2640 }
2641
2642 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2643 // calls DidStopLoading() without a matching DidStartLoading().
2644 if (loading_frames_in_progress_ == 0)
2645 return;
2646 --loading_frames_in_progress_;
2647 if (loading_frames_in_progress_ == 0)
2648 DidStopLoading(rfh);
2649}
2650
2651void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2652 RenderFrameHostImpl* rfh =
2653 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2654 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2655
2656 loading_progresses_[render_frame_id] = load_progress;
2657
2658 // We notify progress change immediately for the first and last updates.
2659 // Also, since the message loop may be pretty busy when a page is loaded, it
2660 // might not execute a posted task in a timely manner so we make sure to
2661 // immediately send progress report if enough time has passed.
2662 base::TimeDelta min_delay =
2663 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2664 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2665 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2666 // If there is a pending task to send progress, it is now obsolete.
2667 loading_weak_factory_.InvalidateWeakPtrs();
2668 SendLoadProgressChanged();
2669 if (loading_total_progress_ == 1.0)
2670 ResetLoadProgressState();
2671 return;
2672 }
2673
2674 if (loading_weak_factory_.HasWeakPtrs())
2675 return;
2676
2677 base::MessageLoop::current()->PostDelayedTask(
2678 FROM_HERE,
2679 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2680 loading_weak_factory_.GetWeakPtr()),
2681 min_delay);
2682}
2683
[email protected]b172aee2012-04-10 17:05:262684void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222685 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2686 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262687}
2688
[email protected]b172aee2012-04-10 17:05:262689void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302690 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262691 minimum_zoom_percent_ = minimum_percent;
2692 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262693}
2694
[email protected]b172aee2012-04-10 17:05:262695void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342696 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432697 if (!delegate_)
2698 return;
2699
[email protected]b9535422012-02-09 01:47:592700 ChildProcessSecurityPolicyImpl* policy =
2701 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222702 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592703 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212704}
2705
[email protected]b172aee2012-04-10 17:05:262706void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2707 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262708 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362709 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432710 if (!delegate_)
2711 return;
2712
[email protected]b9535422012-02-09 01:47:592713 ChildProcessSecurityPolicyImpl* policy =
2714 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322715 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592716 return;
[email protected]8f810632013-06-06 22:33:322717
[email protected]c125e532014-05-10 20:39:062718 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202719}
2720
[email protected]b172aee2012-04-10 17:05:262721void WebContentsImpl::OnFindReply(int request_id,
2722 int number_of_matches,
2723 const gfx::Rect& selection_rect,
2724 int active_match_ordinal,
2725 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432726 if (delegate_) {
2727 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2728 active_match_ordinal, final_update);
2729 }
[email protected]b888919c2011-09-02 00:32:162730}
2731
[email protected]59363fc92012-09-05 03:46:312732#if defined(OS_ANDROID)
2733void WebContentsImpl::OnFindMatchRectsReply(
2734 int version,
2735 const std::vector<gfx::RectF>& rects,
2736 const gfx::RectF& active_rect) {
2737 if (delegate_)
2738 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2739}
[email protected]583418cc2013-01-17 14:01:102740
[email protected]1ff427972013-02-07 21:14:072741void WebContentsImpl::OnOpenDateTimeDialog(
2742 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092743 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2744 GetRenderViewHost(),
2745 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132746 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092747 value.minimum,
2748 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172749 value.step,
2750 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102751}
2752
[email protected]59363fc92012-09-05 03:46:312753#endif
2754
[email protected]f114fa42013-12-06 17:06:442755void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2756 const base::FilePath& path,
2757 bool is_hung) {
2758 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2759
2760 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2761 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2762}
2763
2764void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422765 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442766 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422767 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452768}
2769
[email protected]cfa856d62014-02-22 07:58:402770void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2771 int automation_id) {
2772 DomOperationNotificationDetails details(json_string, automation_id);
2773 NotificationService::current()->Notify(
2774 NOTIFICATION_DOM_OPERATION_RESPONSE,
2775 Source<WebContents>(this),
2776 Details<DomOperationNotificationDetails>(&details));
2777}
2778
[email protected]b172aee2012-04-10 17:05:262779void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2780 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102781 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252782 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102783 AppCacheAccessed(manifest_url, blocked_by_policy));
2784}
2785
[email protected]8bc5ff02013-11-29 06:34:032786void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482787 int color_chooser_id,
2788 SkColor color,
2789 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462790 ColorChooser* new_color_chooser = delegate_ ?
2791 delegate_->OpenColorChooser(this, color, suggestions) :
2792 NULL;
[email protected]820957a2014-01-14 14:56:302793 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212794 return;
[email protected]8ed16472014-04-11 19:02:482795 if (color_chooser_info_.get())
2796 color_chooser_info_->chooser->End();
2797
2798 color_chooser_info_.reset(new ColorChooserInfo(
2799 render_frame_message_source_->GetProcess()->GetID(),
2800 render_frame_message_source_->GetRoutingID(),
2801 new_color_chooser,
2802 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202803}
2804
[email protected]b172aee2012-04-10 17:05:262805void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482806 if (color_chooser_info_ &&
2807 color_chooser_id == color_chooser_info_->identifier)
2808 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202809}
2810
[email protected]b172aee2012-04-10 17:05:262811void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322812 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482813 if (color_chooser_info_ &&
2814 color_chooser_id == color_chooser_info_->identifier)
2815 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202816}
2817
[email protected]d0759f492012-04-19 22:50:502818// This exists for render views that don't have a WebUI, but do have WebUI
2819// bindings enabled.
2820void WebContentsImpl::OnWebUISend(const GURL& source_url,
2821 const std::string& name,
2822 const base::ListValue& args) {
2823 if (delegate_)
2824 delegate_->WebUISend(this, source_url, name, args);
2825}
2826
[email protected]d8415ad92012-08-23 14:40:502827void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442828 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502829 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342830 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162831 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442832 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162833 return;
[email protected]d8415ad92012-08-23 14:40:502834 }
2835
[email protected]8c8fc292012-11-23 18:57:162836 if (!delegate_->RequestPpapiBrokerPermission(
2837 this, url, plugin_path,
2838 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442839 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162840 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442841 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162842 }
[email protected]d8415ad92012-08-23 14:40:502843}
2844
[email protected]ea0309c2013-08-06 19:35:442845void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502846 bool result) {
[email protected]ea0309c2013-08-06 19:35:442847 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502848}
2849
[email protected]c4538072013-03-18 02:17:552850void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372851 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082852 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552853 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392854 // For more info, see comment above classes BrowserPluginEmbedder and
2855 // BrowserPluginGuest.
2856 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142857 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082858 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372859}
2860
[email protected]41225fe2013-03-29 05:32:022861void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392862 int id,
[email protected]749fadd2013-05-15 08:37:482863 int http_status_code,
[email protected]795c28972012-12-06 06:13:392864 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302865 const std::vector<SkBitmap>& bitmaps,
2866 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132867 if (bitmaps.size() != original_bitmap_sizes.size())
2868 return;
2869
[email protected]41225fe2013-03-29 05:32:022870 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2871 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392872 // Currently WebContents notifies us of ANY downloads so that it is
2873 // possible to get here.
2874 return;
2875 }
2876 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302877 iter->second.Run(
2878 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392879 }
[email protected]41225fe2013-03-29 05:32:022880 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392881}
2882
2883void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392884 const std::vector<FaviconURL>& candidates) {
2885 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292886 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392887}
2888
[email protected]1dd0bb752014-02-01 01:16:262889void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2890 bool has_video,
2891 bool has_audio) {
2892// Chrome OS does its own detection of audio and video.
2893#if !defined(OS_CHROMEOS)
2894 scoped_ptr<PowerSaveBlocker> blocker;
2895 if (has_video) {
2896 blocker = PowerSaveBlocker::Create(
2897 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2898#if defined(OS_ANDROID)
2899 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2900 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2901#endif
2902 } else if (has_audio) {
2903 blocker = PowerSaveBlocker::Create(
2904 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2905 }
2906
2907 if (blocker) {
[email protected]96307312014-05-04 01:00:192908 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262909 blocker.release();
2910 }
2911#endif // !defined(OS_CHROMEOS)
2912}
2913
2914void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062915 // Chrome OS does its own detection of audio and video.
2916#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192917 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2918 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062919#endif // !defined(OS_CHROMEOS)
2920}
2921
[email protected]50279492014-05-05 23:24:292922void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152923 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292924 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152925}
[email protected]d9030b82013-07-19 08:26:062926
[email protected]e67ebf32013-02-13 11:07:192927void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:072928 if (delegate_)
2929 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:192930}
2931
[email protected]17e286e2013-03-01 23:29:392932void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2933 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2934 BeforeFormRepostWarningShow());
2935}
2936
[email protected]ec6c05f2013-10-23 18:41:572937
2938void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2939 Activate();
2940 if (delegate_)
2941 delegate_->ShowRepostFormWarningDialog(this);
2942}
2943
[email protected]b4c84012014-04-28 19:51:102944bool WebContentsImpl::HasAccessedInitialDocument() {
2945 return has_accessed_initial_document_;
2946}
2947
[email protected]96d185d2009-04-24 03:28:542948// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592949// loading, or done loading.
2950void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2951 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092952 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262953 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542954 if (is_loading == is_loading_)
2955 return;
2956
2957 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262958 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2959 base::string16());
[email protected]96d185d2009-04-24 03:28:542960 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562961 upload_size_ = 0;
2962 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542963 }
2964
[email protected]fa944cb82013-11-15 17:51:212965 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542966
2967 is_loading_ = is_loading;
2968 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:032969 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:542970
[email protected]6ebdc9b2010-09-27 16:55:572971 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092972 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212973 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542974
[email protected]eab61442013-11-14 18:35:482975 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592976 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482977 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2978 "URL", url);
[email protected]91621872013-10-08 04:04:592979 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2980 DidStartLoading(render_view_host));
2981 } else {
[email protected]eab61442013-11-14 18:35:482982 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2983 "URL", url);
[email protected]91621872013-10-08 04:04:592984 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2985 DidStopLoading(render_view_host));
2986 }
[email protected]66798902013-10-01 18:40:162987
2988 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212989 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2990 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542991 if (details)
[email protected]8ff00d72012-10-23 19:12:212992 det = Details<LoadNotificationDetails>(details);
2993 NotificationService::current()->Notify(
2994 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542995}
2996
[email protected]959be4c2014-04-08 15:01:332997void WebContentsImpl::SelectRange(const gfx::Point& start,
2998 const gfx::Point& end) {
2999 RenderFrameHost* focused_frame = GetFocusedFrame();
3000 if (!focused_frame)
3001 return;
3002
3003 focused_frame->Send(
3004 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
3005}
3006
[email protected]b172aee2012-04-10 17:05:263007void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463008 // If we are creating a RVH for a restored controller, then we need to make
3009 // sure the RenderView starts with a next_page_id_ larger than the number
3010 // of restored entries. This must be called before the RenderView starts
3011 // navigating (to avoid a race between the browser updating max_page_id and
3012 // the renderer updating next_page_id_). Because of this, we only call this
3013 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563014 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583015 if (max_restored_page_id >
3016 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3017 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3018 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323019}
3020
[email protected]b172aee2012-04-10 17:05:263021bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263022 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323023 // For file URLs without a title, use the pathname instead. In the case of a
3024 // synthesized title, we don't want the update to count toward the "one set
3025 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263026 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323027 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513028 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243029 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323030 explicit_set = false; // Don't count synthetic titles toward the set limit.
3031 } else {
[email protected]8af69c6c2014-03-03 19:05:313032 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323033 explicit_set = true;
3034 }
3035
[email protected]987fc3a2011-05-26 14:18:093036 // If a page is created via window.open and never navigated,
3037 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553038 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093039 if (entry) {
[email protected]36fc0392011-12-25 03:59:513040 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093041 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323042
[email protected]36fc0392011-12-25 03:59:513043 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093044 } else {
3045 if (page_title_when_no_navigation_entry_ == final_title)
3046 return false; // Nothing changed, don't bother.
3047
3048 page_title_when_no_navigation_entry_ = final_title;
3049 }
[email protected]420ae012009-04-24 05:16:323050
[email protected]420ae012009-04-24 05:16:323051 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233052 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323053
[email protected]66798902013-10-01 18:40:163054 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533055 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163056
3057 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213058 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463059 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213060 NotificationService::current()->Notify(
3061 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3062 Source<WebContents>(this),
3063 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043064
[email protected]420ae012009-04-24 05:16:323065 return true;
3066}
3067
[email protected]960b0372014-05-19 18:01:003068void WebContentsImpl::SendLoadProgressChanged() {
3069 loading_last_progress_update_ = base::TimeTicks::Now();
3070 double progress = 0.0;
3071 int frame_count = 0;
3072
3073 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3074 it != loading_progresses_.end();
3075 ++it) {
3076 progress += it->second;
3077 ++frame_count;
3078 }
3079 if (frame_count == 0)
3080 return;
3081 progress /= frame_count;
3082 DCHECK(progress <= 1.0);
3083
3084 if (progress <= loading_total_progress_)
3085 return;
3086 loading_total_progress_ = progress;
3087
3088 if (delegate_)
3089 delegate_->LoadProgressChanged(this, progress);
3090}
3091
3092void WebContentsImpl::ResetLoadProgressState() {
3093 loading_progresses_.clear();
3094 loading_total_progress_ = 0.0;
3095 loading_weak_factory_.InvalidateWeakPtrs();
3096 loading_last_progress_update_ = base::TimeTicks();
3097}
3098
[email protected]7b712ee22013-10-03 00:57:283099void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
3100 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323101 // After sending out a swap notification, we need to send a disconnect
3102 // notification so that clients that pick up a pointer to |this| can NULL the
3103 // pointer. See Bug 1230284.
3104 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113105 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283106 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113107
3108 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283109 std::pair<RenderViewHost*, RenderViewHost*> details =
3110 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213111 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283112 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213113 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283114 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393115
3116 // Ensure that the associated embedder gets cleared after a RenderViewHost
3117 // gets swapped, so we don't reuse the same embedder next time a
3118 // RenderViewHost is attached to this WebContents.
3119 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323120}
3121
[email protected]da7a7182013-09-06 08:11:113122// TODO(avi): Remove this entire function because this notification is already
3123// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263124void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323125 if (!notify_disconnection_)
3126 return;
3127
3128 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213129 NotificationService::current()->Notify(
3130 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3131 Source<WebContents>(this),
3132 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323133}
3134
[email protected]cbb1ef592013-06-05 19:49:463135void WebContentsImpl::NotifyNavigationEntryCommitted(
3136 const LoadCommittedDetails& load_details) {
3137 FOR_EACH_OBSERVER(
3138 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3139}
3140
[email protected]f114fa42013-12-06 17:06:443141bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3142 const IPC::Message& message) {
3143 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313144}
3145
[email protected]c31a84802014-04-03 15:55:493146const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3147 return GetLastCommittedURL();
3148}
3149
[email protected]b849847b2013-12-10 21:57:583150void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3151 // Note this is only for subframes, the notification for the main frame
3152 // happens in RenderViewCreated.
3153 FOR_EACH_OBSERVER(WebContentsObserver,
3154 observers_,
3155 RenderFrameCreated(render_frame_host));
3156}
3157
3158void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193159 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583160 FOR_EACH_OBSERVER(WebContentsObserver,
3161 observers_,
3162 RenderFrameDeleted(render_frame_host));
3163}
3164
[email protected]a09d53ce2014-01-31 00:46:423165void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303166 if (delegate_)
3167 delegate_->WorkerCrashed(this);
3168}
3169
[email protected]a09d53ce2014-01-31 00:46:423170void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3171 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103172 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423173 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103174 if (GetBrowserPluginGuest()) {
3175 WebContentsViewGuest* view_guest =
3176 static_cast<WebContentsViewGuest*>(GetView());
3177 context_menu_params = view_guest->ConvertContextMenuParams(params);
3178 }
3179 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423180 return;
3181
[email protected]077e704b2014-05-23 19:24:103182 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3183 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423184}
3185
[email protected]87de04b02014-04-08 22:14:493186void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013187 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493188 const base::string16& message,
3189 const base::string16& default_prompt,
3190 const GURL& frame_url,
3191 JavaScriptMessageType javascript_message_type,
3192 IPC::Message* reply_msg) {
3193 // Suppress JavaScript dialogs when requested. Also suppress messages when
3194 // showing an interstitial as it's shown over the previous page and we don't
3195 // want the hidden page's dialogs to interfere with the interstitial.
3196 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013197 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493198 IsSwappedOut() ||
3199 ShowingInterstitialPage() ||
3200 !delegate_ ||
3201 delegate_->ShouldSuppressDialogs() ||
3202 !delegate_->GetJavaScriptDialogManager();
3203
3204 if (!suppress_this_message) {
3205 std::string accept_lang = GetContentClient()->browser()->
3206 GetAcceptLangs(GetBrowserContext());
3207 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3208 dialog_manager_->RunJavaScriptDialog(
3209 this,
3210 frame_url.GetOrigin(),
3211 accept_lang,
3212 javascript_message_type,
3213 message,
3214 default_prompt,
3215 base::Bind(&WebContentsImpl::OnDialogClosed,
3216 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013217 render_frame_host->GetProcess()->GetID(),
3218 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493219 reply_msg,
3220 false),
3221 &suppress_this_message);
3222 }
3223
3224 if (suppress_this_message) {
3225 // If we are suppressing messages, just reply as if the user immediately
3226 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013227 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3228 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283229 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493230 }
3231
3232 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3233 // http://crbug.com/288961 ). The only safe thing to do here is return.
3234}
3235
3236void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013237 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493238 const base::string16& message,
3239 bool is_reload,
3240 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013241 RenderFrameHostImpl* rfhi =
3242 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493243 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013244 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493245 if (delegate_)
3246 delegate_->WillRunBeforeUnloadConfirm();
3247
3248 bool suppress_this_message =
3249 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3250 !delegate_ ||
3251 delegate_->ShouldSuppressDialogs() ||
3252 !delegate_->GetJavaScriptDialogManager();
3253 if (suppress_this_message) {
3254 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3255 return;
3256 }
3257
3258 is_showing_before_unload_dialog_ = true;
3259 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3260 dialog_manager_->RunBeforeUnloadDialog(
3261 this, message, is_reload,
3262 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013263 render_frame_host->GetProcess()->GetID(),
3264 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283265 false));
[email protected]87de04b02014-04-08 22:14:493266}
3267
[email protected]a86c0e962013-12-17 17:10:393268WebContents* WebContentsImpl::GetAsWebContents() {
3269 return this;
3270}
3271
[email protected]7912e822014-04-16 02:37:033272bool WebContentsImpl::IsNeverVisible() {
3273 if (!delegate_)
3274 return false;
3275 return delegate_->IsNeverVisible(this);
3276}
3277
[email protected]5a3bdf52012-05-24 15:12:573278RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3279 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323280}
3281
[email protected]8ff00d72012-10-23 19:12:213282RendererPreferences WebContentsImpl::GetRendererPrefs(
3283 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463284 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513285}
3286
[email protected]b172aee2012-04-10 17:05:263287gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173288 if (delegate_)
3289 return delegate_->GetRootWindowResizerRect();
3290 return gfx::Rect();
3291}
3292
[email protected]7a846df2012-09-20 19:17:393293void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273294 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393295 browser_plugin_embedder_.reset();
3296}
3297
[email protected]b172aee2012-04-10 17:05:263298void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443299 // Don't send notifications if we are just creating a swapped-out RVH for
3300 // the opener chain. These won't be used for view-source or WebUI, so it's
3301 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243302 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443303 return;
3304
[email protected]86f98a22013-03-20 14:35:003305 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313306 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083307
[email protected]8ff00d72012-10-23 19:12:213308 NotificationService::current()->Notify(
3309 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3310 Source<WebContents>(this),
3311 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323312
3313 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353314 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213315 if (GetRenderManager()->pending_web_ui())
3316 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323317
[email protected]6286a372013-10-09 04:03:273318 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333319 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323320 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183321 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583322 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323323 }
[email protected]0666aef2009-05-13 19:48:083324
[email protected]60780f412013-02-25 16:34:103325 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263326
3327 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253328 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583329
3330 // We tell the observers now instead of when the main RenderFrameHostImpl is
3331 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3332 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363333 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583334 FOR_EACH_OBSERVER(
3335 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323336}
3337
[email protected]b172aee2012-04-10 17:05:263338void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523339 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323340 // Don't notify the world, since this came from a renderer in the
3341 // background.
3342 return;
3343 }
3344
[email protected]da7a7182013-09-06 08:11:113345 notify_disconnection_ = true;
3346 // TODO(avi): Remove. http://crbug.com/170921
3347 NotificationService::current()->Notify(
3348 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3349 Source<WebContents>(this),
3350 NotificationService::NoDetails());
3351
[email protected]be1f56ab2011-12-22 06:55:313352 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233353 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303354
3355 // Restore the focus to the tab (otherwise the focus will be on the top
3356 // window).
[email protected]484ae5912010-09-29 19:16:143357 if (was_crashed && !FocusLocationBarByDefault() &&
3358 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063359 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143360 }
[email protected]32ded2212011-11-10 18:51:433361
[email protected]d8c660432011-12-22 20:51:253362 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323363}
3364
[email protected]ec6a7eb2013-04-22 17:34:223365void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3366 base::TerminationStatus status,
3367 int error_code) {
[email protected]151a63d2011-12-20 22:32:523368 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323369 // The pending page's RenderViewHost is gone.
3370 return;
3371 }
3372
[email protected]2fcdcc32014-03-05 02:14:073373 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3374 // renderer may not have made a clean exit.
3375 if (IsFullscreenForCurrentTab())
3376 ToggleFullscreenMode(false);
3377
[email protected]698191dc2014-02-25 01:06:133378 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3379 if (dialog_manager_)
3380 dialog_manager_->CancelActiveAndPendingDialogs(this);
3381
[email protected]e3b10d12014-03-28 16:06:093382 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323383 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233384 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453385
[email protected]960b0372014-05-19 18:01:003386 // Reset the loading progress. TODO(avi): What does it mean to have a
3387 // "renderer crash" when there is more than one renderer process serving a
3388 // webpage? Once this function is called at a more granular frame level, we
3389 // probably will need to more granularly reset the state here.
3390 ResetLoadProgressState();
3391 loading_frames_in_progress_ = 0;
3392
[email protected]d8c660432011-12-22 20:51:253393 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273394 observers_,
[email protected]58d5cfe2013-07-10 02:40:523395 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323396}
3397
[email protected]b172aee2012-04-10 17:05:263398void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253399 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063400}
3401
[email protected]b172aee2012-04-10 17:05:263402void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3403 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043404 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153405 // Ensure that this state update comes from either the active RVH or one of
3406 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413407 // TODO(nasko): This should go through RenderFrameHost.
3408 // TODO(creis): We can't update state for cross-process subframes until we
3409 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3410 if (rvh != GetRenderViewHost() &&
3411 !GetRenderManager()->IsRVHOnSwappedOutList(
3412 static_cast<RenderViewHostImpl*>(rvh)))
3413 return;
[email protected]420ae012009-04-24 05:16:323414
3415 // We must be prepared to handle state updates for any page, these occur
3416 // when the user is scrolling and entering form data, as well as when we're
3417 // leaving a page, in which case our state may have already been moved to
3418 // the next page. The navigation controller will look up the appropriate
3419 // NavigationEntry and update it when it is notified via the delegate.
3420
3421 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583422 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323423 if (entry_index < 0)
3424 return;
[email protected]10f417c52011-12-28 21:04:233425 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323426
[email protected]691aa2f2013-05-28 22:52:043427 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323428 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043429 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323430 controller_.NotifyEntryChanged(entry, entry_index);
3431}
3432
[email protected]b172aee2012-04-10 17:05:263433void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513434 if (delegate_)
3435 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323436}
3437
[email protected]b172aee2012-04-10 17:05:263438void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103439#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293440 // The UI may be in an event-tracking loop, such as between the
3441 // mouse-down and mouse-up in text selection or a button click.
3442 // Defer the close until after tracking is complete, so that we
3443 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293444 // TODO(shess): This could get more fine-grained. For instance,
3445 // closing a tab in another window while selecting text in the
3446 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103447 if (view_->IsEventTracking()) {
3448 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293449 return;
3450 }
[email protected]60780f412013-02-25 16:34:103451#endif
[email protected]07707302009-11-06 00:50:293452
[email protected]420ae012009-04-24 05:16:323453 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523454 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513455 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323456}
3457
[email protected]66bbadaf2014-03-28 16:25:543458void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573459 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3460 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573461}
3462
[email protected]b172aee2012-04-10 17:05:263463void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513464 if (delegate_ && delegate_->IsPopupOrPanel(this))
3465 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323466}
3467
[email protected]e3b10d12014-03-28 16:06:093468void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3469 bool to_different_document) {
3470 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3471 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323472}
3473
[email protected]723971b2014-02-12 11:08:253474void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323475 scoped_ptr<LoadNotificationDetails> details;
3476
[email protected]9595fd82013-04-19 21:28:493477 // Use the last committed entry rather than the active one, in case a
3478 // pending entry has been created.
3479 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203480 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493481
[email protected]420ae012009-04-24 05:16:323482 // An entry may not exist for a stop when loading an initial blank page or
3483 // if an iframe injected by script into a blank page finishes loading.
3484 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203485 base::TimeDelta elapsed =
3486 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323487
3488 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513489 entry->GetVirtualURL(),
3490 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323491 elapsed,
3492 &controller_,
3493 controller_.GetCurrentEntryIndex()));
3494 }
3495
[email protected]e3b10d12014-03-28 16:06:093496 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3497 details.get());
[email protected]420ae012009-04-24 05:16:323498}
3499
[email protected]b172aee2012-04-10 17:05:263500void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163501 controller_.DiscardNonCommittedEntries();
3502
3503 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213504 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163505}
3506
[email protected]59167c22013-06-03 18:07:323507void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103508 has_accessed_initial_document_ = true;
3509
[email protected]d1371bf8e2014-04-19 03:26:243510 // We may have left a failed browser-initiated navigation in the address bar
3511 // to let the user edit it and try again. Clear it now that content might
3512 // show up underneath it.
3513 if (!IsLoading() && controller_.GetPendingEntry())
3514 controller_.DiscardPendingEntry();
3515
[email protected]59167c22013-06-03 18:07:323516 // Update the URL display.
3517 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3518}
3519
[email protected]3f19f1a2014-05-02 05:23:273520void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3521 if (opener_) {
3522 // Clear our opener so that future cross-process navigations don't have an
3523 // opener assigned.
3524 RemoveDestructionObserver(opener_);
3525 opener_ = NULL;
3526 }
3527
3528 // Notify all swapped out RenderViewHosts for this tab. This is important
3529 // in case we go back to them, or if another window in those processes tries
3530 // to access window.opener.
3531 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3532}
3533
[email protected]39f2f9252014-05-03 00:54:013534void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293535 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093536 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293537 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093538
3539 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213540 NotificationService::current()->Notify(
3541 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3542 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293543 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083544}
3545
[email protected]ef3adfc2014-05-11 00:04:543546void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3547 int32 page_id,
3548 const base::string16& title,
3549 base::i18n::TextDirection title_direction) {
3550 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3551
3552 // If we have a title, that's a pretty good indication that we've started
3553 // getting useful data.
3554 SetNotWaitingForResponse();
3555
3556 // Try to find the navigation entry, which might not be the current one.
3557 // For example, it might be from a pending RVH for the pending entry.
3558 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3559 rvh->GetSiteInstance(), page_id);
3560
3561 // We can handle title updates when we don't have an entry in
3562 // UpdateTitleForEntry, but only if the update is from the current RVH.
3563 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3564 if (!entry && rvh != GetRenderViewHost())
3565 return;
3566
3567 // TODO(evan): make use of title_direction.
3568 // http://code.google.com/p/chromium/issues/detail?id=27094
3569 if (!UpdateTitleForEntry(entry, title))
3570 return;
3571
3572 // Broadcast notifications when the UI should be updated.
3573 if (entry == controller_.GetEntryAtOffset(0))
3574 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3575}
3576
3577void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3578 const std::string& encoding) {
3579 SetEncoding(encoding);
3580}
3581
[email protected]39f2f9252014-05-03 00:54:013582void WebContentsImpl::DocumentAvailableInMainFrame(
3583 RenderViewHost* render_view_host) {
3584 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3585 DocumentAvailableInMainFrame());
3586}
[email protected]e1c3a552012-05-04 20:51:323587void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3588 // Tell the active RenderViewHost to run unload handlers and close, as long
3589 // as the request came from a RenderViewHost in the same BrowsingInstance.
3590 // In most cases, we receive this from a swapped out RenderViewHost.
3591 // It is possible to receive it from one that has just been swapped in,
3592 // in which case we might as well deliver the message anyway.
3593 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3594 GetRenderViewHost()->ClosePage();
3595}
3596
[email protected]f546640b2012-05-15 00:03:493597void WebContentsImpl::RouteMessageEvent(
3598 RenderViewHost* rvh,
3599 const ViewMsg_PostMessage_Params& params) {
3600 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363601 // came from a RenderViewHost in the same BrowsingInstance or if this
3602 // WebContents is dedicated to a browser plugin guest.
3603 // Note: This check means that an embedder could theoretically receive a
3604 // postMessage from anyone (not just its own guests). However, this is
3605 // probably not a risk for apps since other pages won't have references
3606 // to App windows.
3607 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3608 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493609 return;
3610
3611 ViewMsg_PostMessage_Params new_params(params);
3612
[email protected]0bc7f3542013-10-21 15:05:533613 if (!params.message_port_ids.empty()) {
3614 MessagePortMessageFilter* message_port_message_filter =
3615 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3616 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093617 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3618 params.message_port_ids,
3619 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533620 }
3621
[email protected]f546640b2012-05-15 00:03:493622 // If there is a source_routing_id, translate it to the routing ID for
3623 // the equivalent swapped out RVH in the target process. If we need
3624 // to create a swapped out RVH for the source tab, we create its opener
3625 // chain as well, since those will also be accessible to the target page.
3626 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3627 // Try to look up the WebContents for the source page.
3628 WebContentsImpl* source_contents = NULL;
3629 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3630 rvh->GetProcess()->GetID(), params.source_routing_id);
3631 if (source_rvh) {
3632 source_contents = static_cast<WebContentsImpl*>(
3633 source_rvh->GetDelegate()->GetAsWebContents());
3634 }
3635
3636 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363637 if (GetBrowserPluginGuest()) {
3638 // We create a swapped out RenderView for the embedder in the guest's
3639 // render process but we intentionally do not expose the embedder's
3640 // opener chain to it.
3641 new_params.source_routing_id =
3642 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3643 } else {
3644 new_params.source_routing_id =
3645 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3646 }
[email protected]f546640b2012-05-15 00:03:493647 } else {
3648 // We couldn't find it, so don't pass a source frame.
3649 new_params.source_routing_id = MSG_ROUTING_NONE;
3650 }
3651 }
3652
3653 // In most cases, we receive this from a swapped out RenderViewHost.
3654 // It is possible to receive it from one that has just been swapped in,
3655 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183656 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493657}
3658
[email protected]a796f202012-05-30 14:14:253659bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263660 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253661 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263662 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253663 if (!delegate_)
3664 return false;
3665 return delegate_->AddMessageToConsole(this, level, message, line_no,
3666 source_id);
3667}
3668
[email protected]b172aee2012-04-10 17:05:263669WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273670 // We want to base the page config off of the actual URL, rather than the
3671 // virtual URL.
3672 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3673 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003674 GURL url = controller_.GetActiveEntry()
3675 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153676
[email protected]fa944cb82013-11-15 17:51:213677 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323678}
3679
[email protected]0eba810b2012-10-18 03:19:363680int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213681 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413682 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3683 true, true);
[email protected]0eba810b2012-10-18 03:19:363684}
3685
[email protected]b172aee2012-04-10 17:05:263686void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273687 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253688 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223689
[email protected]ea114722012-03-12 01:11:253690 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173691 if (rdh) // NULL in unittests.
3692 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253693}
3694
[email protected]b172aee2012-04-10 17:05:263695void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443696 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253697 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443698}
3699
[email protected]b172aee2012-04-10 17:05:263700void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563701 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263702 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153703 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523704 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153705 return;
3706
[email protected]9f76c1e2012-03-05 15:15:583707 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3708
[email protected]e5fc1632011-08-08 07:51:533709 // Ignore renderer unresponsive event if debugger is attached to the tab
3710 // since the event may be a result of the renderer sitting on a breakpoint.
3711 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363712 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533713 return;
3714
[email protected]2e9d79f2013-08-16 05:45:563715 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323716 // Hang occurred while firing the beforeunload/unload handler.
3717 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583718 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323719
[email protected]fa944cb82013-11-15 17:51:213720 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323721 return;
3722
3723 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563724 // nothing we can do to recover. If the hang is in the beforeunload handler,
3725 // pretend the beforeunload listeners have all fired and allow the delegate
3726 // to continue closing; the user will not have the option of cancelling the
3727 // close. Otherwise, pretend the unload listeners have all fired and close
3728 // the tab.
3729 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463730 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563731 delegate_->BeforeUnloadFired(this, true, &close);
3732 }
3733 if (close)
3734 Close(rvh);
[email protected]420ae012009-04-24 05:16:323735 return;
3736 }
3737
[email protected]9f76c1e2012-03-05 15:15:583738 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473739 return;
3740
[email protected]6934a702011-12-20 00:04:513741 if (delegate_)
3742 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323743}
3744
[email protected]b172aee2012-04-10 17:05:263745void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513746 if (delegate_)
3747 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323748}
3749
[email protected]b172aee2012-04-10 17:05:263750void WebContentsImpl::LoadStateChanged(
3751 const GURL& url,
3752 const net::LoadStateWithParam& load_state,
3753 uint64 upload_position,
3754 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323755 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563756 upload_position_ = upload_position;
3757 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503758 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213759 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303760 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213761 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323762 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463763 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213764 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463765 }
[email protected]420ae012009-04-24 05:16:323766}
3767
[email protected]b172aee2012-04-10 17:05:263768void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553769 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323770 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123771 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3772 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513773 if (delegate_)
3774 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093775 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323776}
3777
[email protected]58d5cfe2013-07-10 02:40:523778void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543779 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233780 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223781 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543782}
3783
[email protected]b172aee2012-04-10 17:05:263784void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103785 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213786 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263787 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3788 // here during container initialization and normal window size will be set
3789 // later. In case of tab duplication this resizing to 0x0 prevents setting
3790 // normal size later so just ignore it.
3791 if (!size.IsEmpty())
3792 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323793}
3794
[email protected]af905902013-10-01 21:38:513795void WebContentsImpl::CancelModalDialogsForRenderManager() {
3796 // We need to cancel modal dialogs when doing a process swap, since the load
3797 // deferrer would prevent us from swapping out.
3798 if (dialog_manager_)
3799 dialog_manager_->CancelActiveAndPendingDialogs(this);
3800}
3801
[email protected]7b712ee22013-10-03 00:57:283802void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3803 RenderViewHost* new_host) {
3804 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083805
3806 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003807 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313808 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393809
[email protected]7b712ee22013-10-03 00:57:283810 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543811}
3812
[email protected]14392a52012-05-02 20:28:443813int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3814 SiteInstance* instance) {
3815 if (!opener_)
3816 return MSG_ROUTING_NONE;
3817
3818 // Recursively create RenderViews for anything else in the opener chain.
3819 return opener_->CreateOpenerRenderViews(instance);
3820}
3821
3822int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3823 int opener_route_id = MSG_ROUTING_NONE;
3824
3825 // If this tab has an opener, ensure it has a RenderView in the given
3826 // SiteInstance as well.
3827 if (opener_)
3828 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3829
[email protected]45a22ad2013-02-21 03:25:003830 // If any of the renderers (current, pending, or swapped out) for this
3831 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213832 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3833 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373834
[email protected]fa944cb82013-11-15 17:51:213835 if (GetRenderManager()->pending_render_view_host() &&
3836 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3837 instance)
3838 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003839
[email protected]fa944cb82013-11-15 17:51:213840 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373841 instance);
3842 if (rvh)
3843 return rvh->GetRoutingID();
3844
[email protected]14392a52012-05-02 20:28:443845 // Create a swapped out RenderView in the given SiteInstance if none exists,
3846 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413847 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3848 true, true);
[email protected]14392a52012-05-02 20:28:443849}
3850
[email protected]b172aee2012-04-10 17:05:263851NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193852 return GetController();
[email protected]3a3d47472010-07-15 21:03:543853}
3854
[email protected]b172aee2012-04-10 17:05:263855WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563856 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323857}
3858
[email protected]10f417c52011-12-28 21:04:233859NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263860 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323861 return controller_.GetLastCommittedEntry();
3862}
3863
[email protected]b172aee2012-04-10 17:05:263864bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163865 RenderViewHost* render_view_host,
3866 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043867 int proxy_routing_id,
[email protected]6ab9d682014-05-22 03:48:593868 bool for_main_frame) {
[email protected]e11f0e92013-06-12 15:12:033869 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443870 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483871 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163872 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3873 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3874 // case this because RWH is still a base class of RenderViewHost, and child
3875 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]6ab9d682014-05-22 03:48:593876 if (!for_main_frame) {
[email protected]bffc8302014-01-23 20:52:163877 RenderWidgetHostViewChildFrame* rwh_view_child =
3878 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:163879 rwh_view = rwh_view_child;
3880 } else {
3881 rwh_view = view_->CreateViewForWidget(render_view_host);
3882 }
[email protected]1a98a932009-11-17 00:12:523883
[email protected]420ae012009-04-24 05:16:323884 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443885 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213886 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323887
[email protected]74ce1ad2011-12-16 21:51:463888 // Make sure we use the correct starting page_id in the new RenderView.
3889 UpdateMaxPageIDIfNecessary(render_view_host);
3890 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583891 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463892
[email protected]9f76c1e2012-03-05 15:15:583893 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263894 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493895 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043896 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:493897 max_page_id,
3898 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523899 return false;
[email protected]14392a52012-05-02 20:28:443900 }
[email protected]a4127722011-04-27 23:13:523901
[email protected]a220b5932013-09-21 03:47:443902#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503903 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3904 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443905 if (rwh_view) {
3906 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3907 render_widget_host->WasResized();
3908 }
[email protected]f8233cc2011-05-31 20:24:503909#endif
3910
[email protected]420ae012009-04-24 05:16:323911 return true;
3912}
3913
[email protected]7d244f12013-08-22 21:41:513914#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453915
[email protected]155c7f22013-12-09 17:07:183916base::android::ScopedJavaLocalRef<jobject>
3917WebContentsImpl::GetJavaWebContents() {
3918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3919
3920 WebContentsAndroid* web_contents_android =
3921 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3922 if (!web_contents_android) {
3923 web_contents_android = new WebContentsAndroid(this);
3924 SetUserData(kWebContentsAndroidKey, web_contents_android);
3925 }
3926 return web_contents_android->GetJavaObject();
3927}
3928
[email protected]7d244f12013-08-22 21:41:513929bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3930 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163931 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:043932 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:593933 true);
[email protected]7d244f12013-08-22 21:41:513934}
[email protected]fc2b46b2014-05-03 16:33:453935
3936#elif defined(OS_MACOSX)
3937
3938void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
3939 view_->SetAllowOverlappingViews(overlapping);
3940}
3941
3942bool WebContentsImpl::GetAllowOverlappingViews() {
3943 return view_->GetAllowOverlappingViews();
3944}
3945
3946void WebContentsImpl::SetOverlayView(WebContents* overlay,
3947 const gfx::Point& offset) {
3948 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
3949 offset);
3950}
3951
3952void WebContentsImpl::RemoveOverlayView() {
3953 view_->RemoveOverlayView();
3954}
3955
[email protected]7d244f12013-08-22 21:41:513956#endif
3957
[email protected]6fba26d2014-04-29 09:38:283958void WebContentsImpl::OnDialogClosed(int render_process_id,
3959 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:263960 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493961 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263962 bool success,
[email protected]fcf75d42013-12-03 20:11:263963 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:283964 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3965 render_frame_id);
[email protected]87de04b02014-04-08 22:14:493966 last_dialog_suppressed_ = dialog_was_suppressed;
3967
[email protected]beb440c2009-11-06 04:08:543968 if (is_showing_before_unload_dialog_ && !success) {
3969 // If a beforeunload dialog is canceled, we need to stop the throbber from
3970 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:283971 if (rfh)
3972 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353973 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103974
[email protected]6d65a462013-06-21 21:29:123975 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3976 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543977 }
[email protected]87de04b02014-04-08 22:14:493978
[email protected]beb440c2009-11-06 04:08:543979 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:283980 if (rfh) {
3981 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3982 dialog_was_suppressed);
3983 } else {
3984 // Don't leak the sync IPC reply if the RFH or process is gone.
3985 delete reply_msg;
3986 }
[email protected]beb440c2009-11-06 04:08:543987}
3988
[email protected]b172aee2012-04-10 17:05:263989void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:543990 if (encoding == last_reported_encoding_)
3991 return;
3992 last_reported_encoding_ = encoding;
3993
3994 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123995 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103996}
[email protected]f45d2a72010-03-08 23:28:353997
[email protected]b172aee2012-04-10 17:05:263998void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:483999 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:444000 // Can be NULL during tests.
4001 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:454002 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:364003}
[email protected]9f76c1e2012-03-05 15:15:584004
[email protected]1ac10dca2013-08-20 20:47:044005bool WebContentsImpl::IsHidden() {
4006 return capturer_count_ == 0 && !should_normally_be_visible_;
4007}
4008
[email protected]b0936d22013-11-28 06:47:364009RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214010 return frame_tree_.root()->render_manager();
4011}
4012
[email protected]b172aee2012-04-10 17:05:264013RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584014 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4015}
[email protected]7900bfdb2012-05-24 19:31:244016
[email protected]f8497342013-02-05 22:15:024017BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394018 return browser_plugin_guest_.get();
4019}
4020
[email protected]738f57a2013-06-29 21:06:544021void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4022 CHECK(!browser_plugin_guest_);
4023 browser_plugin_guest_.reset(guest);
4024}
4025
[email protected]f8497342013-02-05 22:15:024026BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394027 return browser_plugin_embedder_.get();
4028}
[email protected]8ff00d72012-10-23 19:12:214029
[email protected]d9030b82013-07-19 08:26:064030void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194031 RenderFrameHost* render_frame_host) {
4032 STLDeleteValues(&power_save_blockers_[render_frame_host]);
4033 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:064034}
4035
4036void WebContentsImpl::ClearAllPowerSaveBlockers() {
4037 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
4038 i != power_save_blockers_.end(); ++i)
4039 STLDeleteValues(&power_save_blockers_[i->first]);
4040 power_save_blockers_.clear();
4041}
4042
[email protected]fc2b46b2014-05-03 16:33:454043gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214044 gfx::Size size;
4045 if (delegate_)
4046 size = delegate_->GetSizeForNewRenderView(this);
4047 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454048 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214049 return size;
4050}
4051
[email protected]9b159a52013-10-03 17:24:554052void WebContentsImpl::OnFrameRemoved(
4053 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:584054 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:554055 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:584056 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:554057}
4058
[email protected]222f5822014-02-05 23:40:494059void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4060 if (!delegate_)
4061 return;
4062 const gfx::Size new_size = GetPreferredSize();
4063 if (new_size != old_size)
4064 delegate_->UpdatePreferredSize(this, new_size);
4065}
4066
[email protected]8ff00d72012-10-23 19:12:214067} // namespace content