blob: ee24b6f164af50ee23f8275f4a577b196b1b9f20 [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),
350 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46351 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
352 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55353 frame_tree_.SetFrameRemoveListener(
354 base::Bind(&WebContentsImpl::OnFrameRemoved,
355 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35356}
initial.commit09911bf2008-07-26 23:55:29357
[email protected]b172aee2012-04-10 17:05:26358WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32359 is_being_destroyed_ = true;
360
[email protected]21b41c7e892014-02-28 01:52:24361 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
362 // shutdown and be deleted as well.
363 frame_tree_.ForEach(
364 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
365
[email protected]d9030b82013-07-19 08:26:06366 ClearAllPowerSaveBlockers();
367
[email protected]b24b68a2012-09-24 21:57:26368 for (std::set<RenderWidgetHostImpl*>::iterator iter =
369 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
370 (*iter)->DetachDelegate();
371 }
372 created_widgets_.clear();
373
[email protected]3ab9cb82011-06-03 18:02:07374 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15375 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11376 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07377
[email protected]8ed16472014-04-11 19:02:48378 if (color_chooser_info_.get())
379 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20380
[email protected]420ae012009-04-24 05:16:32381 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32382
[email protected]ca13a442012-04-17 14:00:12383 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21384 NotificationService::current()->Notify(
385 NOTIFICATION_WEB_CONTENTS_DESTROYED,
386 Source<WebContents>(this),
387 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32388
[email protected]df0c843f2014-05-23 20:37:23389 // Destroy all frame tree nodes except for the root; this notifies observers.
390 frame_tree_.ResetForMainFrameSwap();
391 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59392
[email protected]df0c843f2014-05-23 20:37:23393 // Manually call the observer methods for the root frame tree node.
394 RenderFrameHostManager* root = GetRenderManager();
395 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27396 FOR_EACH_OBSERVER(WebContentsObserver,
397 observers_,
[email protected]df0c843f2014-05-23 20:37:23398 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27399 }
[email protected]df0c843f2014-05-23 20:37:23400 FOR_EACH_OBSERVER(WebContentsObserver,
401 observers_,
402 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27403
[email protected]df0c843f2014-05-23 20:37:23404 if (root->pending_render_view_host()) {
405 FOR_EACH_OBSERVER(WebContentsObserver,
406 observers_,
407 RenderViewDeleted(root->pending_render_view_host()));
408 }
[email protected]c06c58c2014-03-12 20:31:59409
[email protected]f273ee52013-10-18 16:05:27410 FOR_EACH_OBSERVER(WebContentsObserver,
411 observers_,
[email protected]df0c843f2014-05-23 20:37:23412 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27413
[email protected]2db9bd72012-04-13 20:20:56414 FOR_EACH_OBSERVER(WebContentsObserver,
415 observers_,
[email protected]12a46832014-05-09 13:35:58416 WebContentsDestroyed());
417
418 FOR_EACH_OBSERVER(WebContentsObserver,
419 observers_,
420 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08421
[email protected]6934a702011-12-20 00:04:51422 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10423
424 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
425 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42426}
427
[email protected]d1198fd2012-08-13 22:50:19428WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59429 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19430 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03431 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59432 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06433 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19434
[email protected]83100cd2014-05-10 11:50:06435 if (params.guest_instance_id) {
[email protected]50d326e2014-05-20 17:59:06436 scoped_ptr<base::DictionaryValue> extra_params;
437 if (params.guest_extra_params)
438 extra_params.reset(params.guest_extra_params->DeepCopy());
[email protected]83100cd2014-05-10 11:50:06439 // This makes |new_contents| act as a guest.
440 // For more info, see comment above class BrowserPluginGuest.
441 BrowserPluginGuest::Create(params.guest_instance_id,
442 params.site_instance,
443 new_contents,
[email protected]50d326e2014-05-20 17:59:06444 extra_params.Pass(),
445 opener ? opener->GetBrowserPluginGuest() : NULL);
[email protected]83100cd2014-05-10 11:50:06446 // We are instantiating a WebContents for browser plugin. Set its subframe
447 // bit to true.
448 new_contents->is_subframe_ = true;
449 }
[email protected]54944cde2012-12-09 09:24:59450 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19451 return new_contents;
452}
453
[email protected]b0936d22013-11-28 06:47:36454RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21455 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28456}
457
[email protected]7bb761892012-07-20 09:32:47458bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
459 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44460 return OnMessageReceived(render_view_host, NULL, message);
461}
462
463bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
464 RenderFrameHost* render_frame_host,
465 const IPC::Message& message) {
466 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56467 if (GetWebUI() &&
468 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17469 return true;
[email protected]d2353452012-01-19 19:53:56470 }
[email protected]f82d57b52011-04-27 19:13:17471
[email protected]d8c660432011-12-22 20:51:25472 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
473 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33474 if (render_frame_host) {
475 while ((observer = it.GetNext()) != NULL)
476 if (observer->OnMessageReceived(message, render_frame_host))
477 return true;
478 } else {
479 while ((observer = it.GetNext()) != NULL)
480 if (observer->OnMessageReceived(message))
481 return true;
482 }
[email protected]403415a2011-01-10 18:57:53483
[email protected]1d62cf72014-02-07 21:31:57484 // Message handlers should be aware of which
485 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
486 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43487 if (render_frame_host) {
488 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
489 render_frame_host->GetRenderViewHost(), message))
490 return true;
[email protected]1d62cf72014-02-07 21:31:57491 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43492 } else {
493 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
494 render_view_host, message))
495 return true;
[email protected]1d62cf72014-02-07 21:31:57496 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43497 }
[email protected]1d62cf72014-02-07 21:31:57498
[email protected]724159a2010-12-30 01:11:18499 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33500 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]f114fa42013-12-06 17:06:44501 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
502 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40503 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
504 OnDomOperationResponse)
[email protected]8ed16472014-04-11 19:02:48505 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
506 OnDocumentLoadedInFrame)
507 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00508 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
509 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
510 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
511 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48512 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
513 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
514 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
515 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19516 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
517 OnMediaPlayingNotification)
518 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
519 OnMediaPausedNotification)
[email protected]724159a2010-12-30 01:11:18520 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
521 OnDidLoadResourceFromMemoryCache)
522 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
523 OnDidDisplayInsecureContent)
524 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
525 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25526 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26527 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21528 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20529 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
530 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16531 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10532 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50533 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50534 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
535 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55536 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
537 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02538 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
539 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]9f268072013-11-07 00:02:15540 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
541 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07542 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
543 OnShowValidationMessage)
544 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
545 OnHideValidationMessage)
546 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
547 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48548#if defined(OS_ANDROID)
549 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
550 OnFindMatchRectsReply)
551 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
552 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48553#endif
[email protected]724159a2010-12-30 01:11:18554 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33555 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44556 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57557 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18558
[email protected]724159a2010-12-30 01:11:18559 return handled;
560}
561
[email protected]b172aee2012-04-10 17:05:26562void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18563 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21564 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43565 if (delegate_)
566 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18567}
568
[email protected]d1198fd2012-08-13 22:50:19569NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56570 return controller_;
571}
572
[email protected]d1198fd2012-08-13 22:50:19573const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56574 return controller_;
575}
576
[email protected]8ff00d72012-10-23 19:12:21577BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55578 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30579}
580
[email protected]b172aee2012-04-10 17:05:26581const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24582 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32583 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51584 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31585}
586
[email protected]a093ce02013-07-22 20:53:14587const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24588 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32589 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24590 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
591}
592
593const GURL& WebContentsImpl::GetLastCommittedURL() const {
594 // We may not have a navigation entry yet.
595 NavigationEntry* entry = controller_.GetLastCommittedEntry();
596 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
597}
598
[email protected]8ff00d72012-10-23 19:12:21599WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31600 return delegate_;
601}
602
[email protected]8ff00d72012-10-23 19:12:21603void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31604 // TODO(cbentzel): remove this debugging code?
605 if (delegate == delegate_)
606 return;
607 if (delegate_)
608 delegate_->Detach(this);
609 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08610 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31611 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08612 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00613 if (view_)
614 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08615 }
[email protected]be1f56ab2011-12-22 06:55:31616}
617
[email protected]8ff00d72012-10-23 19:12:21618RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21619 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41620 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16621}
622
[email protected]60eca4eb2013-12-06 00:02:16623RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41624 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16625}
626
[email protected]9c9343b2014-03-08 02:56:07627RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
628 if (!frame_tree_.GetFocusedFrame())
629 return NULL;
630 return frame_tree_.GetFocusedFrame()->current_frame_host();
631}
632
[email protected]a86c0e962013-12-17 17:10:39633void WebContentsImpl::ForEachFrame(
634 const base::Callback<void(RenderFrameHost*)>& on_frame) {
635 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
636}
637
638void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
639 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
640 delete message;
641}
642
[email protected]b172aee2012-04-10 17:05:26643RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21644 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31645}
646
[email protected]6b618e62012-08-16 12:59:18647int WebContentsImpl::GetRoutingID() const {
648 if (!GetRenderViewHost())
649 return MSG_ROUTING_NONE;
650
651 return GetRenderViewHost()->GetRoutingID();
652}
653
[email protected]44470a22013-01-24 01:21:54654int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
655 return fullscreen_widget_routing_id_;
656}
657
[email protected]b172aee2012-04-10 17:05:26658RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21659 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31660}
661
[email protected]4aebbca2013-09-17 22:26:49662RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
663 const {
664 RenderWidgetHost* const widget_host =
665 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
666 GetFullscreenWidgetRoutingID());
667 return widget_host ? widget_host->GetView() : NULL;
668}
669
[email protected]8ff00d72012-10-23 19:12:21670WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31671 return view_.get();
672}
673
[email protected]8ff00d72012-10-23 19:12:21674WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56675 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03676 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
677 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22678 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58679 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22680 web_ui->SetController(controller);
681 return web_ui;
682 }
683
684 delete web_ui;
685 return NULL;
686}
687
[email protected]8ff00d72012-10-23 19:12:21688WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21689 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
690 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31691}
692
[email protected]8ff00d72012-10-23 19:12:21693WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21694 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34695}
696
[email protected]86ef6a392012-05-11 22:03:11697void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22698 if (GetUserAgentOverride() == override)
699 return;
700
701 renderer_preferences_.user_agent_override = override;
702
703 // Send the new override string to the renderer.
704 RenderViewHost* host = GetRenderViewHost();
705 if (host)
706 host->SyncRendererPrefs();
707
708 // Reload the page if a load is currently in progress to avoid having
709 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27710 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22711 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
712 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53713
714 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
715 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11716}
717
718const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22719 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11720}
721
[email protected]2ceee8f2014-01-14 18:02:08722#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41723void WebContentsImpl::SetParentNativeViewAccessible(
724gfx::NativeViewAccessible accessible_parent) {
725 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45726 if (GetRenderViewHost())
727 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41728}
729#endif
730
[email protected]fcf75d42013-12-03 20:11:26731const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55732 // Transient entries take precedence. They are used for interstitial pages
733 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23734 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08735 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21736 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30737 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23738 if (entry) {
[email protected]b5cca982011-05-26 04:42:08739 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23740 }
[email protected]fa944cb82013-11-15 17:51:21741 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
742 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58743 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54744 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32745 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54746 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35747 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26748 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54749 if (!title.empty())
750 return title;
751 }
752 }
753
754 // We use the title for the last committed entry rather than a pending
755 // navigation entry. For example, when the user types in a URL, we want to
756 // keep the old page's title until the new load has committed and we get a new
757 // title.
[email protected]96d185d2009-04-24 03:28:54758 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32759
[email protected]9eeafc012013-11-25 23:49:47760 // We make an exception for initial navigations.
761 if (controller_.IsInitialNavigation()) {
762 // We only want to use the title from the visible entry in one of two cases:
763 // 1. There's already a committed entry for an initial navigation, in which
764 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
765 // 2. The pending entry has been explicitly assigned a title to display.
766 //
767 // If there's no last committed entry and no assigned title, we should fall
768 // back to |page_title_when_no_navigation_entry_| rather than showing the
769 // URL.
770 if (entry ||
771 (controller_.GetVisibleEntry() &&
772 !controller_.GetVisibleEntry()->GetTitle().empty())) {
773 entry = controller_.GetVisibleEntry();
774 }
775 }
[email protected]59167c22013-06-03 18:07:32776
[email protected]45d0ef7f2011-01-05 13:46:23777 if (entry) {
[email protected]b5cca982011-05-26 04:42:08778 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23779 }
[email protected]987fc3a2011-05-26 14:18:09780
781 // |page_title_when_no_navigation_entry_| is finally used
782 // if no title cannot be retrieved.
783 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54784}
785
[email protected]b172aee2012-04-10 17:05:26786int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46787 return GetMaxPageIDForSiteInstance(GetSiteInstance());
788}
789
[email protected]b172aee2012-04-10 17:05:26790int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
791 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33792 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
793 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46794
[email protected]b6583592012-01-25 19:52:33795 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34796}
797
[email protected]b172aee2012-04-10 17:05:26798void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46799 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
800}
801
[email protected]b172aee2012-04-10 17:05:26802void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33803 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46804 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33805 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34806}
807
[email protected]ec6c05f2013-10-23 18:41:57808void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
809 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
810 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57811}
812
[email protected]b172aee2012-04-10 17:05:26813SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21814 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54815}
816
[email protected]b172aee2012-04-10 17:05:26817SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21818 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
819 GetRenderManager()->pending_render_view_host() :
820 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58821 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38822}
823
[email protected]b172aee2012-04-10 17:05:26824bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31825 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49826}
827
[email protected]6dfed692014-05-22 04:18:03828bool WebContentsImpl::IsLoadingToDifferentDocument() const {
829 return is_loading_ && is_load_to_different_document_;
830}
831
[email protected]b172aee2012-04-10 17:05:26832bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03833 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31834}
835
[email protected]b172aee2012-04-10 17:05:26836const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31837 return load_state_;
838}
839
[email protected]fcf75d42013-12-03 20:11:26840const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31841 return load_state_host_;
842}
843
[email protected]b172aee2012-04-10 17:05:26844uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31845 return upload_size_;
846}
847
[email protected]b172aee2012-04-10 17:05:26848uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31849 return upload_position_;
850}
851
[email protected]1ae93fb2013-06-14 03:38:56852std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56853 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39854 frame_tree_.ForEach(base::Bind(&CollectSites,
855 base::Unretained(GetBrowserContext()),
856 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56857 return sites;
858}
859
[email protected]b172aee2012-04-10 17:05:26860const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54861 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31862}
863
[email protected]b172aee2012-04-10 17:05:26864bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31865 return displayed_insecure_content_;
866}
867
[email protected]222f5822014-02-05 23:40:49868void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25869 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55870 ++capturer_count_;
871 DVLOG(1) << "There are now " << capturer_count_
872 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49873
874 // Note: This provides a hint to upstream code to size the views optimally
875 // for quality (e.g., to avoid scaling).
876 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
877 preferred_size_for_capture_ = capture_size;
878 OnPreferredSizeChanged(preferred_size_);
879 }
[email protected]54597982013-02-06 01:59:55880}
881
882void WebContentsImpl::DecrementCapturerCount() {
883 --capturer_count_;
884 DVLOG(1) << "There are now " << capturer_count_
885 << " capturing(s) of WebContentsImpl@" << this;
886 DCHECK_LE(0, capturer_count_);
887
[email protected]5a652232013-02-12 06:15:25888 if (is_being_destroyed_)
889 return;
890
[email protected]222f5822014-02-05 23:40:49891 if (capturer_count_ == 0) {
892 const gfx::Size old_size = preferred_size_for_capture_;
893 preferred_size_for_capture_ = gfx::Size();
894 OnPreferredSizeChanged(old_size);
895 }
896
[email protected]1ac10dca2013-08-20 20:47:04897 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55898 DVLOG(1) << "Executing delayed WasHidden().";
899 WasHidden();
900 }
[email protected]be1f56ab2011-12-22 06:55:31901}
902
[email protected]f2bd40812013-07-20 04:30:44903int WebContentsImpl::GetCapturerCount() const {
904 return capturer_count_;
905}
906
[email protected]b172aee2012-04-10 17:05:26907bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31908 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
909 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
910 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49911}
912
[email protected]b172aee2012-04-10 17:05:26913void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
914 int error_code) {
[email protected]443b80e2010-12-14 00:42:23915 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34916 return;
917
[email protected]443b80e2010-12-14 00:42:23918 crashed_status_ = status;
919 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21920 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34921}
922
[email protected]b172aee2012-04-10 17:05:26923base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31924 return crashed_status_;
925}
926
[email protected]b172aee2012-04-10 17:05:26927bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31928 return is_being_destroyed_;
929}
930
[email protected]b172aee2012-04-10 17:05:26931void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34932 if (delegate_)
933 delegate_->NavigationStateChanged(this, changed_flags);
934}
935
[email protected]9a890452014-02-13 22:21:02936base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
937 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33938}
939
[email protected]9e2e4632012-07-27 16:38:41940void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54941 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:59942
943 std::set<RenderWidgetHostImpl*> widgets = GetRenderWidgetHostsInTree();
944 for (std::set<RenderWidgetHostImpl*>::iterator iter = widgets.begin();
945 iter != widgets.end();
946 iter++) {
947 RenderWidgetHostView* rwhv = (*iter)->GetView();
948 if (rwhv) {
949 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43950#if defined(OS_MACOSX)
[email protected]de3c5d82014-05-28 22:12:59951 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43952#endif
[email protected]de3c5d82014-05-28 22:12:59953 }
[email protected]789e9152009-08-04 21:59:43954 }
[email protected]96d185d2009-04-24 03:28:54955
[email protected]9a890452014-02-13 22:21:02956 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38957
[email protected]b9769d82012-02-10 00:23:59958 // The resize rect might have changed while this was inactive -- send the new
959 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58960 RenderViewHostImpl* rvh =
961 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59962 if (rvh) {
963 rvh->ResizeRectChanged(GetRootWindowResizerRect());
964 }
[email protected]96d185d2009-04-24 03:28:54965
[email protected]c0d9d5672013-10-09 07:38:03966 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
967
[email protected]54597982013-02-06 01:59:55968 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31969}
970
[email protected]b172aee2012-04-10 17:05:26971void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55972 // If there are entities capturing screenshots or video (e.g., mirroring),
973 // don't activate the "disable rendering" optimization.
974 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52975 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55976 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26977 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52978 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33979 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52980 // calls us).
[email protected]de3c5d82014-05-28 22:12:59981 std::set<RenderWidgetHostImpl*> widgets = GetRenderWidgetHostsInTree();
982 for (std::set<RenderWidgetHostImpl*>::iterator iter = widgets.begin();
983 iter != widgets.end();
984 iter++) {
985 RenderWidgetHostView* rwhv = (*iter)->GetView();
986 if (rwhv)
987 rwhv->Hide();
988 }
[email protected]96d185d2009-04-24 03:28:54989 }
990
[email protected]c0d9d5672013-10-09 07:38:03991 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
992
[email protected]54597982013-02-06 01:59:55993 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37994}
995
[email protected]b172aee2012-04-10 17:05:26996bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31997 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27998 return WillNotifyDisconnection() &&
999 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581000 !static_cast<RenderViewHostImpl*>(
1001 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311002}
1003
[email protected]1c3f80bd2014-04-08 23:02:061004void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1005 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1006 for_cross_site_transition);
1007}
1008
[email protected]b172aee2012-04-10 17:05:261009void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211010 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401011 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271012}
1013
[email protected]b172aee2012-04-10 17:05:261014WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441015 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451016 // We pass our own opener so that the cloned page can access it if it was
1017 // before.
[email protected]54944cde2012-12-09 09:24:591018 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451019 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591020 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191021 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221022 FOR_EACH_OBSERVER(WebContentsObserver,
1023 observers_,
1024 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271025 return tc;
1026}
1027
[email protected]14392a52012-05-02 20:28:441028void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211029 const NotificationSource& source,
1030 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441031 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211032 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1033 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501034 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1035 i != pending_widget_views_.end(); ++i) {
1036 if (host->GetView() == i->second) {
1037 pending_widget_views_.erase(i);
1038 break;
1039 }
1040 }
1041 break;
1042 }
[email protected]14392a52012-05-02 20:28:441043 default:
1044 NOTREACHED();
1045 }
1046}
1047
[email protected]ec6c05f2013-10-23 18:41:571048WebContents* WebContentsImpl::GetWebContents() {
1049 return this;
1050}
1051
[email protected]54944cde2012-12-09 09:24:591052void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211053 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361054 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211055 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431056 should_normally_be_visible_ = !params.initially_hidden;
1057
[email protected]fa944cb82013-11-15 17:51:211058 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041059 params.browser_context, params.site_instance, params.routing_id,
1060 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191061
[email protected]fc2b46b2014-05-03 16:33:451062 WebContentsViewDelegate* delegate =
1063 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1064
1065 if (browser_plugin_guest_) {
1066 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1067 this, delegate, &render_view_host_delegate_view_));
1068
1069 WebContentsViewGuest* rv = new WebContentsViewGuest(
1070 this, browser_plugin_guest_.get(), platform_view.Pass(),
1071 render_view_host_delegate_view_);
1072 render_view_host_delegate_view_ = rv;
1073 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191074 } else {
[email protected]fc2b46b2014-05-03 16:33:451075 // Regular WebContentsView.
1076 view_.reset(CreateWebContentsView(
1077 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191078 }
[email protected]fc2b46b2014-05-03 16:33:451079 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191080 CHECK(view_.get());
1081
[email protected]ed245db2012-12-18 08:00:451082 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591083 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191084
1085 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101086 if (opener_)
1087 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191088
1089 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211090 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1091 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101092
1093 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
1094
[email protected]c7654a232013-06-12 21:04:441095#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101096 date_time_chooser_.reset(new DateTimeChooserAndroid());
1097#endif
[email protected]d1198fd2012-08-13 22:50:191098}
1099
[email protected]7fff43e2013-05-21 20:21:101100void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1101 RemoveDestructionObserver(web_contents);
1102
[email protected]14392a52012-05-02 20:28:441103 // Clear the opener if it has been closed.
1104 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441105 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511106 return;
[email protected]14392a52012-05-02 20:28:441107 }
[email protected]ceee8cd2013-03-08 04:59:511108 // Clear a pending contents that has been closed before being shown.
1109 for (PendingContents::iterator iter = pending_contents_.begin();
1110 iter != pending_contents_.end();
1111 ++iter) {
1112 if (iter->second != web_contents)
1113 continue;
1114 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511115 return;
1116 }
1117 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441118}
1119
[email protected]7fff43e2013-05-21 20:21:101120void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1121 if (!ContainsKey(destruction_observers_, web_contents)) {
1122 destruction_observers_[web_contents] =
1123 new DestructionObserver(this, web_contents);
1124 }
1125}
1126
1127void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1128 DestructionObservers::iterator iter =
1129 destruction_observers_.find(web_contents);
1130 if (iter != destruction_observers_.end()) {
1131 delete destruction_observers_[web_contents];
1132 destruction_observers_.erase(iter);
1133 }
1134}
1135
[email protected]b172aee2012-04-10 17:05:261136void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311137 observers_.AddObserver(observer);
1138}
1139
[email protected]b172aee2012-04-10 17:05:261140void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311141 observers_.RemoveObserver(observer);
1142}
1143
[email protected]de3c5d82014-05-28 22:12:591144std::set<RenderWidgetHostImpl*> WebContentsImpl::GetRenderWidgetHostsInTree() {
1145 std::set<RenderWidgetHostImpl*> set;
1146 ForEachFrame(base::Bind(&AddRenderWidgetHostToSet, base::Unretained(&set)));
1147 return set;
1148}
1149
[email protected]b172aee2012-04-10 17:05:261150void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341151 if (delegate_)
1152 delegate_->ActivateContents(this);
1153}
1154
[email protected]b172aee2012-04-10 17:05:261155void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121156 if (delegate_)
1157 delegate_->DeactivateContents(this);
1158}
1159
[email protected]b172aee2012-04-10 17:05:261160void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481161 if (delegate_)
1162 delegate_->LostCapture();
1163}
1164
[email protected]b24b68a2012-09-24 21:57:261165void WebContentsImpl::RenderWidgetDeleted(
1166 RenderWidgetHostImpl* render_widget_host) {
1167 if (is_being_destroyed_) {
1168 // |created_widgets_| might have been destroyed.
1169 return;
1170 }
1171
1172 std::set<RenderWidgetHostImpl*>::iterator iter =
1173 created_widgets_.find(render_widget_host);
1174 if (iter != created_widgets_.end())
1175 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541176
1177 if (render_widget_host &&
1178 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491179 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1180 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541181 FOR_EACH_OBSERVER(WebContentsObserver,
1182 observers_,
1183 DidDestroyFullscreenWidget(
1184 fullscreen_widget_routing_id_));
1185 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1186 }
[email protected]b24b68a2012-09-24 21:57:261187}
1188
[email protected]b172aee2012-04-10 17:05:261189bool WebContentsImpl::PreHandleKeyboardEvent(
1190 const NativeWebKeyboardEvent& event,
1191 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481192 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131193 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481194}
1195
[email protected]b172aee2012-04-10 17:05:261196void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481197 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131198 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481199}
1200
[email protected]d92026ef2014-03-03 21:04:131201bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461202 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191203#if !defined(OS_MACOSX)
1204 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1205 // isn't done for two reasons:
1206 // -the OS already has a gesture to do this through pinch-zoom
1207 // -if a user starts an inertial scroll, let's go, and presses control
1208 // (i.e. control+tab) then the OS's buffered scroll events will come in
1209 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521210 if (delegate_ &&
1211 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551212 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1213 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1214 // gestures, which are regrettably easy to trigger accidentally.
1215 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521216 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1217 return true;
1218 }
[email protected]bccc4472013-04-18 16:37:191219#endif
[email protected]fb3f066e2013-02-12 19:12:521220 return false;
1221}
1222
[email protected]04bce562014-01-30 05:34:541223bool WebContentsImpl::PreHandleGestureEvent(
1224 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031225 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541226}
1227
[email protected]bab38af2014-03-30 17:37:291228bool WebContentsImpl::HandleGestureEvent(
1229 const blink::WebGestureEvent& event) {
1230 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1231 // Use them to implement browser zoom, as for HandleWheelEvent above.
1232 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331233 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291234 // The scale difference necessary to trigger a zoom action. Derived from
1235 // experimentation to find a value that feels reasonable.
1236 const float kZoomStepValue = 0.6f;
1237
1238 // Find the (absolute) thresholds on either side of the current zoom factor,
1239 // then convert those to actual numbers to trigger a zoom in or out.
1240 // This logic deliberately makes the range around the starting zoom value
1241 // for the gesture twice as large as the other ranges (i.e., the notches are
1242 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1243 // so that it's easier to get back to your starting point than it is to
1244 // overshoot.
1245 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1246 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1247 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1248 : -backStep;
1249 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1250 : backStep;
1251
[email protected]fb546cb2014-04-28 14:09:371252 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291253 if (totalPinchGestureAmount_ > zoomInThreshold) {
1254 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461255 if (delegate_)
1256 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291257 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1258 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461259 if (delegate_)
1260 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291261 }
1262 return true;
1263 }
1264
1265 return false;
1266}
1267
[email protected]2ceee8f2014-01-14 18:02:081268#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411269gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1270 return accessible_parent_;
1271}
1272#endif
1273
[email protected]b172aee2012-04-10 17:05:261274void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431275 if (delegate_)
1276 delegate_->HandleMouseDown();
1277}
1278
[email protected]b172aee2012-04-10 17:05:261279void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481280 if (delegate_)
1281 delegate_->HandleMouseUp();
1282}
1283
[email protected]590a634e2012-07-19 16:38:231284void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481285 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231286 delegate_->HandlePointerActivate();
1287}
1288
1289void WebContentsImpl::HandleGestureBegin() {
1290 if (delegate_)
1291 delegate_->HandleGestureBegin();
1292}
1293
1294void WebContentsImpl::HandleGestureEnd() {
1295 if (delegate_)
1296 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481297}
1298
[email protected]b172aee2012-04-10 17:05:261299void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491300 // This method is being called to enter or leave renderer-initiated fullscreen
1301 // mode. Either way, make sure any existing fullscreen widget is shut down
1302 // first.
1303 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1304 if (widget_view)
1305 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1306
[email protected]8a5e0ca2011-08-25 06:30:471307 if (delegate_)
1308 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371309
1310 FOR_EACH_OBSERVER(WebContentsObserver,
1311 observers_,
1312 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471313}
1314
[email protected]b172aee2012-04-10 17:05:261315bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381316 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121317}
1318
[email protected]a9c81f02012-06-01 00:15:441319void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1320 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371321 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441322 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371323 } else {
1324 GotResponseToLockMouseRequest(false);
1325 }
1326}
1327
[email protected]b172aee2012-04-10 17:05:261328void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371329 if (delegate_)
1330 delegate_->LostMouseLock();
1331}
1332
[email protected]bafe6cd2012-05-23 23:09:501333void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201334 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501335 int route_id,
[email protected]227692c52013-05-31 22:43:041336 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131337 const ViewHostMsg_CreateWindow_Params& params,
1338 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501339 // We usually create the new window in the same BrowsingInstance (group of
1340 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551341 // if the opener is being suppressed (in a non-guest), we create a new
1342 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251343 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551344
[email protected]04cbd3d2013-12-04 04:58:201345 // If the opener is to be suppressed, the new window can be in any process.
1346 // Since routing ids are process specific, we must not have one passed in
1347 // as argument here.
1348 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1349
[email protected]bafe6cd2012-05-23 23:09:501350 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551351 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571352 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501353 GetSiteInstance();
1354
[email protected]04cbd3d2013-12-04 04:58:201355 // A message to create a new window can only come from the active process for
1356 // this WebContentsImpl instance. If any other process sends the request,
1357 // it is invalid and the process must be terminated.
1358 if (GetRenderProcessHost()->GetID() != render_process_id) {
1359 base::ProcessHandle process_handle =
1360 RenderProcessHost::FromID(render_process_id)->GetHandle();
1361 if (process_handle != base::kNullProcessHandle) {
1362 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391363 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201364 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1365 }
1366 return;
1367 }
1368
[email protected]d1198fd2012-08-13 22:50:191369 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341370 //
1371 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301372 const std::string& partition_id =
1373 GetContentClient()->browser()->
1374 GetStoragePartitionIdForSite(GetBrowserContext(),
1375 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461376 StoragePartition* partition = BrowserContext::GetStoragePartition(
1377 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411378 DOMStorageContextWrapper* dom_storage_context =
1379 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191380 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1381 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1382 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371383
1384 if (delegate_ &&
1385 !delegate_->ShouldCreateWebContents(this,
1386 route_id,
1387 params.window_container_type,
1388 params.frame_name,
1389 params.target_url,
1390 partition_id,
1391 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011392 if (route_id != MSG_ROUTING_NONE &&
1393 !RenderViewHost::FromID(render_process_id, route_id)) {
1394 // If the embedder didn't create a WebContents for this route, we need to
1395 // delete the RenderView that had already been created.
1396 Send(new ViewMsg_Close(route_id));
1397 }
[email protected]dd6730412013-08-14 15:03:371398 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1399 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1400 main_frame_route_id);
1401 return;
1402 }
1403
1404 // Create the new web contents. This will automatically create the new
1405 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461406 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591407 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041408 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061409 create_params.opener = this;
1410 create_params.opener_suppressed = params.opener_suppressed;
1411 if (params.disposition == NEW_BACKGROUND_TAB)
1412 create_params.initially_hidden = true;
1413
[email protected]c4538072013-03-18 02:17:551414 if (!is_guest) {
1415 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451416 create_params.initial_size = GetContainerBounds().size();
[email protected]c4538072013-03-18 02:17:551417 } else {
[email protected]50d326e2014-05-20 17:59:061418 create_params.guest_instance_id =
[email protected]139355f2014-05-11 14:21:281419 GetBrowserContext()->GetGuestManager()->GetNextInstanceID();
[email protected]c4538072013-03-18 02:17:551420 }
[email protected]50d326e2014-05-20 17:59:061421 WebContentsImpl* new_contents = static_cast<WebContentsImpl*>(
1422 WebContents::Create(create_params));
1423 new_contents->GetController().SetSessionStorageNamespace(
1424 partition_id,
1425 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261426 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191427
[email protected]c4538072013-03-18 02:17:551428 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341429 // will be shown immediately).
1430 if (!params.opener_suppressed) {
1431 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451432 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501433
[email protected]d70bea92013-04-05 04:23:341434 // TODO(brettw): It seems bogus that we have to call this function on the
1435 // newly created object and give it one of its own member variables.
1436 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1437 }
[email protected]bafe6cd2012-05-23 23:09:501438 // Save the created window associated with the route so we can show it
1439 // later.
1440 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1441 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101442 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501443 }
1444
1445 if (delegate_) {
1446 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071447 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131448 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501449 }
1450
1451 if (params.opener_suppressed) {
1452 // When the opener is suppressed, the original renderer cannot access the
1453 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001454 bool was_blocked = false;
1455 if (delegate_) {
1456 gfx::Rect initial_pos;
1457 delegate_->AddNewContents(
1458 this, new_contents, params.disposition, initial_pos,
1459 params.user_gesture, &was_blocked);
1460 }
1461 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211462 OpenURLParams open_params(params.target_url,
1463 Referrer(),
1464 CURRENT_TAB,
1465 PAGE_TRANSITION_LINK,
1466 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301467 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001468 new_contents->OpenURL(open_params);
1469 }
[email protected]bafe6cd2012-05-23 23:09:501470 }
1471}
1472
[email protected]a8504022013-12-04 20:23:511473void WebContentsImpl::CreateNewWidget(int render_process_id,
1474 int route_id,
[email protected]180ef242013-11-07 06:50:461475 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511476 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501477}
1478
[email protected]a8504022013-12-04 20:23:511479void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1480 int route_id) {
1481 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501482}
1483
[email protected]a8504022013-12-04 20:23:511484void WebContentsImpl::CreateNewWidget(int render_process_id,
1485 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501486 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461487 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211488 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511489 // A message to create a new widget can only come from the active process for
1490 // this WebContentsImpl instance. If any other process sends the request,
1491 // it is invalid and the process must be terminated.
1492 if (process->GetID() != render_process_id) {
1493 base::ProcessHandle process_handle =
1494 RenderProcessHost::FromID(render_process_id)->GetHandle();
1495 if (process_handle != base::kNullProcessHandle) {
1496 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391497 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511498 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1499 }
1500 return;
1501 }
1502
[email protected]bafe6cd2012-05-23 23:09:501503 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041504 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261505 created_widgets_.insert(widget_host);
1506
[email protected]cfd80b02014-05-01 17:46:481507 RenderWidgetHostViewBase* widget_view =
1508 static_cast<RenderWidgetHostViewBase*>(
1509 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191510 if (!widget_view)
1511 return;
[email protected]bafe6cd2012-05-23 23:09:501512 if (!is_fullscreen) {
1513 // Popups should not get activated.
1514 widget_view->SetPopupType(popup_type);
1515 }
1516 // Save the created widget associated with the route so we can show it later.
1517 pending_widget_views_[route_id] = widget_view;
1518
1519#if defined(OS_MACOSX)
1520 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1521 // to allow it to survive the trip without being hosted.
1522 base::mac::NSObjectRetain(widget_view->GetNativeView());
1523#endif
1524}
1525
1526void WebContentsImpl::ShowCreatedWindow(int route_id,
1527 WindowOpenDisposition disposition,
1528 const gfx::Rect& initial_pos,
1529 bool user_gesture) {
1530 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001531 if (contents) {
1532 WebContentsDelegate* delegate = GetDelegate();
1533 if (delegate) {
1534 delegate->AddNewContents(
1535 this, contents, disposition, initial_pos, user_gesture, NULL);
1536 }
1537 }
[email protected]bafe6cd2012-05-23 23:09:501538}
1539
1540void WebContentsImpl::ShowCreatedWidget(int route_id,
1541 const gfx::Rect& initial_pos) {
1542 ShowCreatedWidget(route_id, false, initial_pos);
1543}
1544
1545void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1546 ShowCreatedWidget(route_id, true, gfx::Rect());
1547}
1548
1549void WebContentsImpl::ShowCreatedWidget(int route_id,
1550 bool is_fullscreen,
1551 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481552 RenderWidgetHostViewBase* widget_host_view =
1553 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501554 if (!widget_host_view)
1555 return;
[email protected]cfd80b02014-05-01 17:46:481556
1557 RenderWidgetHostView* view = NULL;
1558 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1559 if (guest && guest->embedder_web_contents()) {
1560 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1561 } else {
1562 view = GetRenderWidgetHostView();
1563 }
1564
[email protected]4aebbca2013-09-17 22:26:491565 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311566 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1567 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491568 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1569 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1570 delegate_->ToggleFullscreenModeForTab(this, true);
1571 } else {
[email protected]cfd80b02014-05-01 17:46:481572 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491573 }
[email protected]4aebbca2013-09-17 22:26:491574 FOR_EACH_OBSERVER(WebContentsObserver,
1575 observers_,
1576 DidShowFullscreenWidget(route_id));
1577 if (!widget_host_view->HasFocus())
1578 widget_host_view->Focus();
1579 } else {
[email protected]cfd80b02014-05-01 17:46:481580 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491581 }
[email protected]89054502012-06-03 10:29:241582
1583 RenderWidgetHostImpl* render_widget_host_impl =
1584 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1585 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311586 // Only allow privileged mouse lock for fullscreen render widget, which is
1587 // used to implement Pepper Flash fullscreen.
1588 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501589
1590#if defined(OS_MACOSX)
1591 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1592 // properly embedded (or purposefully ignored) we can release the retain we
1593 // took in CreateNewWidget().
1594 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1595#endif
1596}
1597
1598WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1599 PendingContents::iterator iter = pending_contents_.find(route_id);
1600
1601 // Certain systems can block the creation of new windows. If we didn't succeed
1602 // in creating one, just return NULL.
1603 if (iter == pending_contents_.end()) {
1604 return NULL;
1605 }
1606
1607 WebContentsImpl* new_contents = iter->second;
1608 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101609 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501610
[email protected]d70bea92013-04-05 04:23:341611 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251612 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341613 return new_contents;
1614
[email protected]bafe6cd2012-05-23 23:09:501615 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1616 !new_contents->GetRenderViewHost()->GetView())
1617 return NULL;
1618
1619 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1620 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1621 return new_contents;
1622}
1623
1624RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1625 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1626 if (iter == pending_widget_views_.end()) {
1627 DCHECK(false);
1628 return NULL;
1629 }
1630
1631 RenderWidgetHostView* widget_host_view = iter->second;
1632 pending_widget_views_.erase(route_id);
1633
1634 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1635 if (!widget_host->GetProcess()->HasConnection()) {
1636 // The view has gone away or the renderer crashed. Nothing to do.
1637 return NULL;
1638 }
1639
1640 return widget_host_view;
1641}
1642
[email protected]f13b4202012-06-12 23:53:231643void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091644 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211645 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371646 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231647 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371648 } else {
1649 callback.Run(MediaStreamDevices(),
1650 MEDIA_DEVICE_INVALID_STATE,
1651 scoped_ptr<MediaStreamUI>());
1652 }
[email protected]f13b4202012-06-12 23:53:231653}
1654
[email protected]cc9200432013-07-23 23:02:401655SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1656 SiteInstance* instance) {
1657 return controller_.GetSessionStorageNamespace(instance);
1658}
1659
[email protected]6de7fc482014-06-06 10:46:441660SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1661 return controller_.GetSessionStorageNamespaceMap();
1662}
1663
[email protected]9b159a52013-10-03 17:24:551664FrameTree* WebContentsImpl::GetFrameTree() {
1665 return &frame_tree_;
1666}
1667
[email protected]31a71eaf2014-03-13 01:47:361668void WebContentsImpl::AccessibilityEventReceived(
1669 const std::vector<AXEventNotificationDetails>& details) {
1670 FOR_EACH_OBSERVER(
1671 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1672}
1673
[email protected]edc3af82013-12-12 21:24:071674void WebContentsImpl::OnShowValidationMessage(
1675 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291676 const base::string16& main_text,
1677 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071678 if (delegate_)
1679 delegate_->ShowValidationMessage(
1680 this, anchor_in_root_view, main_text, sub_text);
1681}
1682
1683void WebContentsImpl::OnHideValidationMessage() {
1684 if (delegate_)
1685 delegate_->HideValidationMessage(this);
1686}
1687
1688void WebContentsImpl::OnMoveValidationMessage(
1689 const gfx::Rect& anchor_in_root_view) {
1690 if (delegate_)
1691 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1692}
1693
[email protected]32deec62013-05-15 23:55:041694void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1695 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441696 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041697}
1698
[email protected]b172aee2012-04-10 17:05:261699void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491700 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231701 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491702 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331703}
1704
[email protected]b172aee2012-04-10 17:05:261705void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341706 if (delegate_)
1707 delegate_->ResizeDueToAutoResize(this, new_size);
1708}
1709
[email protected]b172aee2012-04-10 17:05:261710WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201711 if (!delegate_)
1712 return NULL;
[email protected]00c37fc2011-08-02 00:22:501713
[email protected]e5d549d2011-12-28 01:29:201714 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201715 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341716}
1717
[email protected]6b618e62012-08-16 12:59:181718bool WebContentsImpl::Send(IPC::Message* message) {
1719 if (!GetRenderViewHost()) {
1720 delete message;
1721 return false;
1722 }
1723
1724 return GetRenderViewHost()->Send(message);
1725}
1726
[email protected]b172aee2012-04-10 17:05:261727bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501728 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261729 FrameTreeNode* node = frame_tree_.root();
1730
1731 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1732 // specified in the pending entry.
1733 NavigationEntryImpl* pending_entry =
1734 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1735 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1736 pending_entry->frame_tree_node_id() != -1) {
1737 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1738 }
1739
1740 return node->navigator()->NavigateToPendingEntry(
1741 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541742}
[email protected]96d185d2009-04-24 03:28:541743
[email protected]a86c0e962013-12-17 17:10:391744void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1745 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441746 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391747 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441748}
1749
[email protected]20ca0382013-02-28 19:50:071750void WebContentsImpl::AttachInterstitialPage(
1751 InterstitialPageImpl* interstitial_page) {
1752 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211753 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291754
1755 // Cancel any visible dialogs so that they don't interfere with the
1756 // interstitial.
1757 if (dialog_manager_)
1758 dialog_manager_->CancelActiveAndPendingDialogs(this);
1759
[email protected]20ca0382013-02-28 19:50:071760 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1761 DidAttachInterstitialPage());
1762}
1763
1764void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571765 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211766 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071767 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1768 DidDetachInterstitialPage());
1769}
1770
[email protected]b172aee2012-04-10 17:05:261771void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331772 const SiteInstance* site_instance,
1773 int history_length,
1774 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411775 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1776 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211777 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191778 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141779 return;
[email protected]9e1ad4b2011-08-14 16:49:191780 }
[email protected]9f76c1e2012-03-05 15:15:581781 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191782 if (!rvh) {
1783 NOTREACHED();
1784 return;
1785 }
[email protected]9f76c1e2012-03-05 15:15:581786 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191787 NOTREACHED();
1788 return;
1789 }
[email protected]6b618e62012-08-16 12:59:181790 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1791 history_length,
1792 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141793}
1794
[email protected]4fed3702014-04-01 09:08:001795void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171796 RenderFrameHost* focused_frame = GetFocusedFrame();
1797 if (!focused_frame)
1798 return;
1799
[email protected]959be4c2014-04-08 15:01:331800 focused_frame->Send(new FrameMsg_Reload(
1801 focused_frame->GetRoutingID(), ignore_cache));
1802}
1803
1804void WebContentsImpl::Undo() {
1805 RenderFrameHost* focused_frame = GetFocusedFrame();
1806 if (!focused_frame)
1807 return;
1808
1809 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1810 RecordAction(base::UserMetricsAction("Undo"));
1811}
1812
1813void WebContentsImpl::Redo() {
1814 RenderFrameHost* focused_frame = GetFocusedFrame();
1815 if (!focused_frame)
1816 return;
1817 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1818 RecordAction(base::UserMetricsAction("Redo"));
1819}
1820
1821void WebContentsImpl::Cut() {
1822 RenderFrameHost* focused_frame = GetFocusedFrame();
1823 if (!focused_frame)
1824 return;
1825
1826 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1827 RecordAction(base::UserMetricsAction("Cut"));
1828}
1829
1830void WebContentsImpl::Copy() {
1831 RenderFrameHost* focused_frame = GetFocusedFrame();
1832 if (!focused_frame)
1833 return;
1834
1835 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1836 RecordAction(base::UserMetricsAction("Copy"));
1837}
1838
1839void WebContentsImpl::CopyToFindPboard() {
1840#if defined(OS_MACOSX)
1841 RenderFrameHost* focused_frame = GetFocusedFrame();
1842 if (!focused_frame)
1843 return;
1844
1845 // Windows/Linux don't have the concept of a find pasteboard.
1846 focused_frame->Send(
1847 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1848 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1849#endif
1850}
1851
1852void WebContentsImpl::Paste() {
1853 RenderFrameHost* focused_frame = GetFocusedFrame();
1854 if (!focused_frame)
1855 return;
1856
1857 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1858 RecordAction(base::UserMetricsAction("Paste"));
1859}
1860
1861void WebContentsImpl::PasteAndMatchStyle() {
1862 RenderFrameHost* focused_frame = GetFocusedFrame();
1863 if (!focused_frame)
1864 return;
1865
1866 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1867 focused_frame->GetRoutingID()));
1868 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1869}
1870
1871void WebContentsImpl::Delete() {
1872 RenderFrameHost* focused_frame = GetFocusedFrame();
1873 if (!focused_frame)
1874 return;
1875
1876 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1877 RecordAction(base::UserMetricsAction("DeleteSelection"));
1878}
1879
1880void WebContentsImpl::SelectAll() {
1881 RenderFrameHost* focused_frame = GetFocusedFrame();
1882 if (!focused_frame)
1883 return;
1884
1885 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1886 RecordAction(base::UserMetricsAction("SelectAll"));
1887}
1888
1889void WebContentsImpl::Unselect() {
1890 RenderFrameHost* focused_frame = GetFocusedFrame();
1891 if (!focused_frame)
1892 return;
1893
1894 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1895 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171896}
1897
1898void WebContentsImpl::Replace(const base::string16& word) {
1899 RenderFrameHost* focused_frame = GetFocusedFrame();
1900 if (!focused_frame)
1901 return;
1902
[email protected]959be4c2014-04-08 15:01:331903 focused_frame->Send(new InputMsg_Replace(
1904 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171905}
1906
1907void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1908 RenderFrameHost* focused_frame = GetFocusedFrame();
1909 if (!focused_frame)
1910 return;
1911
[email protected]959be4c2014-04-08 15:01:331912 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1913 focused_frame->GetRoutingID(), word));
1914}
1915
1916void WebContentsImpl::NotifyContextMenuClosed(
1917 const CustomContextMenuContext& context) {
1918 RenderFrameHost* focused_frame = GetFocusedFrame();
1919 if (!focused_frame)
1920 return;
1921
1922 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1923 focused_frame->GetRoutingID(), context));
1924}
1925
1926void WebContentsImpl::ExecuteCustomContextMenuCommand(
1927 int action, const CustomContextMenuContext& context) {
1928 RenderFrameHost* focused_frame = GetFocusedFrame();
1929 if (!focused_frame)
1930 return;
1931
1932 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1933 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001934}
1935
[email protected]fc2b46b2014-05-03 16:33:451936gfx::NativeView WebContentsImpl::GetNativeView() {
1937 return view_->GetNativeView();
1938}
1939
1940gfx::NativeView WebContentsImpl::GetContentNativeView() {
1941 return view_->GetContentNativeView();
1942}
1943
1944gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1945 return view_->GetTopLevelNativeWindow();
1946}
1947
1948gfx::Rect WebContentsImpl::GetViewBounds() {
1949 return view_->GetViewBounds();
1950}
1951
1952gfx::Rect WebContentsImpl::GetContainerBounds() {
1953 gfx::Rect rv;
1954 view_->GetContainerBounds(&rv);
1955 return rv;
1956}
1957
1958DropData* WebContentsImpl::GetDropData() {
1959 return view_->GetDropData();
1960}
1961
1962void WebContentsImpl::Focus() {
1963 view_->Focus();
1964}
1965
1966void WebContentsImpl::SetInitialFocus() {
1967 view_->SetInitialFocus();
1968}
1969
1970void WebContentsImpl::StoreFocus() {
1971 view_->StoreFocus();
1972}
1973
1974void WebContentsImpl::RestoreFocus() {
1975 view_->RestoreFocus();
1976}
1977
[email protected]b172aee2012-04-10 17:05:261978void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271979 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211980 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541981 return;
1982 }
[email protected]9f76c1e2012-03-05 15:15:581983 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541984}
1985
[email protected]b172aee2012-04-10 17:05:261986bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211987 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541988}
1989
[email protected]b172aee2012-04-10 17:05:261990InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211991 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221992}
1993
[email protected]b172aee2012-04-10 17:05:261994bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161995 // WebKit creates Document object when MIME type is application/xhtml+xml,
1996 // so we also support this MIME type.
1997 return contents_mime_type_ == "text/html" ||
1998 contents_mime_type_ == "text/xml" ||
1999 contents_mime_type_ == "application/xhtml+xml" ||
2000 contents_mime_type_ == "text/plain" ||
2001 contents_mime_type_ == "text/css" ||
2002 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2003}
2004
[email protected]b172aee2012-04-10 17:05:262005void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592006 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162007 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552008 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012009 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142010 return;
[email protected]c7dd2f62011-07-18 15:57:592011 }
2012
2013 Stop();
2014
2015 // Create the save package and possibly prompt the user for the name to save
2016 // the page as. The user prompt is an asynchronous operation that runs on
2017 // another thread.
2018 save_package_ = new SavePackage(this);
2019 save_package_->GetSaveInfo();
2020}
2021
2022// Used in automated testing to bypass prompting the user for file names.
2023// Instead, the names and paths are hard coded rather than running them through
2024// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342025bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2026 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212027 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592028 // Stop the page from navigating.
2029 Stop();
2030
2031 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212032 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592033}
2034
[email protected]3c71576ce2013-07-23 02:00:012035void WebContentsImpl::SaveFrame(const GURL& url,
2036 const Referrer& referrer) {
2037 if (!GetURL().is_valid())
2038 return;
2039 bool is_main_frame = (url == GetURL());
2040
2041 DownloadManager* dlm =
2042 BrowserContext::GetDownloadManager(GetBrowserContext());
2043 if (!dlm)
2044 return;
2045 int64 post_id = -1;
2046 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272047 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012048 if (entry)
2049 post_id = entry->GetPostID();
2050 }
2051 scoped_ptr<DownloadUrlParameters> params(
2052 DownloadUrlParameters::FromWebContents(this, url));
2053 params->set_referrer(referrer);
2054 params->set_post_id(post_id);
2055 params->set_prefer_cache(true);
2056 if (post_id >= 0)
2057 params->set_method("POST");
2058 params->set_prompt(true);
2059 dlm->DownloadUrl(params.Pass());
2060}
2061
[email protected]b172aee2012-04-10 17:05:262062void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342063 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482064 const base::Callback<void(int64)>& callback) {
2065 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122066}
2067
[email protected]b172aee2012-04-10 17:05:262068const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272069 return contents_mime_type_;
2070}
2071
[email protected]b172aee2012-04-10 17:05:262072bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272073 return notify_disconnection_;
2074}
2075
[email protected]b172aee2012-04-10 17:05:262076void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312077 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182078 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162079}
2080
[email protected]b172aee2012-04-10 17:05:262081void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542082 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182083 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162084}
2085
[email protected]8ff00d72012-10-23 19:12:212086RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272087 return &renderer_preferences_;
2088}
2089
[email protected]e35ccd52012-05-23 16:22:472090void WebContentsImpl::Close() {
2091 Close(GetRenderViewHost());
2092}
2093
[email protected]cf200a562013-05-03 16:24:292094void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462095 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292096 if (browser_plugin_embedder_.get())
2097 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2098 screen_x, screen_y, operation);
2099 if (GetRenderViewHost())
2100 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2101 screen_x, screen_y, operation);
2102}
2103
[email protected]d60f3702013-12-26 16:30:242104void WebContentsImpl::DidGetResourceResponseStart(
2105 const ResourceRequestDetails& details) {
2106 controller_.ssl_manager()->DidStartResourceResponse(details);
2107
2108 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2109 DidGetResourceResponseStart(details));
2110
2111 // TODO(avi): Remove. http://crbug.com/170921
2112 NotificationService::current()->Notify(
2113 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2114 Source<WebContents>(this),
2115 Details<const ResourceRequestDetails>(&details));
2116}
2117
2118void WebContentsImpl::DidGetRedirectForResourceRequest(
2119 RenderViewHost* render_view_host,
2120 const ResourceRedirectDetails& details) {
2121 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2122
2123 FOR_EACH_OBSERVER(
2124 WebContentsObserver,
2125 observers_,
2126 DidGetRedirectForResourceRequest(render_view_host, details));
2127
2128 // TODO(avi): Remove. http://crbug.com/170921
2129 NotificationService::current()->Notify(
2130 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2131 Source<WebContents>(this),
2132 Details<const ResourceRedirectDetails>(&details));
2133}
2134
[email protected]b172aee2012-04-10 17:05:262135void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522136 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582137 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512138 if (delegate_)
2139 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292140 if (browser_plugin_embedder_.get())
2141 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342142}
2143
[email protected]e35ccd52012-05-23 16:22:472144void WebContentsImpl::UserGestureDone() {
2145 OnUserGesture();
2146}
2147
[email protected]b172aee2012-04-10 17:05:262148void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272149 closed_by_user_gesture_ = value;
2150}
2151
[email protected]b172aee2012-04-10 17:05:262152bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272153 return closed_by_user_gesture_;
2154}
2155
[email protected]b172aee2012-04-10 17:05:262156int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592157 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172158 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012159 // Calculate the zoom percent from the factor. Round up to the nearest whole
2160 // number.
[email protected]b75b8292010-10-01 07:28:252161 int percent = static_cast<int>(
[email protected]fce823222014-05-30 16:24:302162 ZoomLevelToZoomFactor(HostZoomMap::GetZoomLevel(this)) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252163 *enable_decrement = percent > minimum_zoom_percent_;
2164 *enable_increment = percent < maximum_zoom_percent_;
2165 return percent;
2166}
2167
[email protected]b172aee2012-04-10 17:05:262168void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502169 if (!delegate_)
2170 return;
2171
[email protected]6286a372013-10-09 04:03:272172 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2173 if (!entry)
[email protected]1788e772010-12-15 16:40:502174 return;
2175
[email protected]6286a372013-10-09 04:03:272176 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122177}
2178
[email protected]b172aee2012-04-10 17:05:262179void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042180 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272181 if (!delegate_)
2182 return;
2183
[email protected]691aa2f2013-05-28 22:52:042184 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272185}
2186
[email protected]b172aee2012-04-10 17:05:262187int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272188 return minimum_zoom_percent_;
2189}
2190
[email protected]b172aee2012-04-10 17:05:262191int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272192 return maximum_zoom_percent_;
2193}
2194
[email protected]b172aee2012-04-10 17:05:262195gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492196 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232197}
2198
[email protected]b172aee2012-04-10 17:05:262199bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052200 if (GetBrowserPluginGuest())
2201 return GetBrowserPluginGuest()->LockMouse(allowed);
2202
[email protected]0bfbf882011-12-22 18:19:272203 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582204 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272205}
2206
[email protected]b172aee2012-04-10 17:05:262207bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442208 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502209}
2210
[email protected]cb805452013-05-22 15:16:212211void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482212 if (!color_chooser_info_.get())
2213 return;
2214 RenderFrameHost* rfh = RenderFrameHost::FromID(
2215 color_chooser_info_->render_process_id,
2216 color_chooser_info_->render_frame_id);
2217 if (!rfh)
2218 return;
2219
2220 rfh->Send(new FrameMsg_DidChooseColorResponse(
2221 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202222}
2223
[email protected]cb805452013-05-22 15:16:212224void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482225 if (!color_chooser_info_.get())
2226 return;
2227 RenderFrameHost* rfh = RenderFrameHost::FromID(
2228 color_chooser_info_->render_process_id,
2229 color_chooser_info_->render_frame_id);
2230 if (!rfh)
2231 return;
2232
2233 rfh->Send(new FrameMsg_DidEndColorChooser(
2234 rfh->GetRoutingID(), color_chooser_info_->identifier));
2235 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202236}
2237
[email protected]41225fe2013-03-29 05:32:022238int WebContentsImpl::DownloadImage(const GURL& url,
2239 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302240 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022241 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582242 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022243 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392244 return id;
2245}
2246
[email protected]5dcaf8e2013-12-28 01:31:422247bool WebContentsImpl::IsSubframe() const {
2248 return is_subframe_;
2249}
2250
[email protected]36ec24f2014-01-09 00:32:082251void WebContentsImpl::Find(int request_id,
2252 const base::string16& search_text,
2253 const blink::WebFindOptions& options) {
2254 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2255}
2256
2257void WebContentsImpl::StopFinding(StopFindAction action) {
2258 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2259}
2260
[email protected]4fe53add2014-04-08 19:53:362261void WebContentsImpl::InsertCSS(const std::string& css) {
2262 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2263 GetMainFrame()->GetRoutingID(), css));
2264}
2265
[email protected]b172aee2012-04-10 17:05:262266bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272267 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172268 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332269 return true;
2270 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272271}
2272
[email protected]b172aee2012-04-10 17:05:262273void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272274 if (delegate_)
2275 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212276}
2277
[email protected]52913802013-12-10 05:52:182278void WebContentsImpl::DidStartProvisionalLoad(
2279 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072280 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182281 const GURL& validated_url,
2282 bool is_error_page,
2283 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262284 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]d974a0a2013-01-10 01:43:572285
[email protected]0d60f0192011-04-14 12:40:102286 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272287 int render_frame_id = render_frame_host->GetRoutingID();
2288 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252289 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072290 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272291 render_frame_id, parent_routing_id, is_main_frame,
2292 validated_url, is_error_page, is_iframe_srcdoc,
2293 render_view_host));
[email protected]400992b2012-06-14 00:03:542294
2295 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182296 FOR_EACH_OBSERVER(
2297 WebContentsObserver,
2298 observers_,
2299 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582300 render_frame_host));
[email protected]400992b2012-06-14 00:03:542301 }
2302}
2303
[email protected]3109fbb72014-01-06 23:57:152304void WebContentsImpl::DidFailProvisionalLoadWithError(
2305 RenderFrameHostImpl* render_frame_host,
2306 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2307 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272308 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262309 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272310 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152311 FOR_EACH_OBSERVER(
2312 WebContentsObserver,
2313 observers_,
[email protected]161eabd2014-03-19 19:47:272314 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152315 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262316 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152317 validated_url,
2318 params.error_code,
2319 params.error_description,
[email protected]161eabd2014-03-19 19:47:272320 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152321}
2322
[email protected]b80624c2014-02-09 02:46:552323void WebContentsImpl::DidFailLoadWithError(
2324 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552325 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552326 int error_code,
2327 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272328 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262329 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272330 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552331 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272332 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262333 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552334}
2335
[email protected]52913802013-12-10 05:52:182336void WebContentsImpl::NotifyChangedNavigationState(
2337 InvalidateTypes changed_flags) {
2338 NotifyNavigationStateChanged(changed_flags);
2339}
2340
[email protected]3691e5cf2014-01-22 10:16:202341void WebContentsImpl::AboutToNavigateRenderFrame(
2342 RenderFrameHostImpl* render_frame_host) {
2343 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272344 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202345 FOR_EACH_OBSERVER(
2346 WebContentsObserver,
2347 observers_,
[email protected]161eabd2014-03-19 19:47:272348 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202349}
2350
2351void WebContentsImpl::DidStartNavigationToPendingEntry(
2352 RenderFrameHostImpl* render_frame_host,
2353 const GURL& url,
2354 NavigationController::ReloadType reload_type) {
2355 // Notify observers about navigation.
2356 FOR_EACH_OBSERVER(
2357 WebContentsObserver,
2358 observers_,
2359 DidStartNavigationToPendingEntry(url, reload_type));
2360}
2361
[email protected]8cb834e2014-03-06 14:23:232362void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2363 const OpenURLParams& params) {
2364 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182365 WebContents* new_contents = OpenURL(params);
2366
2367 if (new_contents) {
2368 // Notify observers.
2369 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2370 DidOpenRequestedURL(new_contents,
2371 params.url,
2372 params.referrer,
2373 params.disposition,
2374 params.transition,
[email protected]8cb834e2014-03-06 14:23:232375 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182376 }
2377}
2378
[email protected]aa62afd2014-04-22 19:22:462379bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2380 if (!delegate_)
2381 return false;
2382 return delegate_->ShouldPreserveAbortedURLs(this);
2383}
2384
[email protected]400992b2012-06-14 00:03:542385void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582386 RenderFrameHostImpl* render_frame_host,
2387 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542388 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582389 FOR_EACH_OBSERVER(
2390 WebContentsObserver,
2391 observers_,
2392 ProvisionalChangeToMainFrameUrl(validated_target_url,
2393 render_frame_host));
[email protected]724159a2010-12-30 01:11:182394}
2395
[email protected]37567b432014-02-12 01:12:222396void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432397 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222398 const base::string16& frame_unique_name,
2399 bool is_main_frame,
2400 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432401 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432402 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272403 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222404 // Notify observers about the commit of the provisional load.
2405 FOR_EACH_OBSERVER(
2406 WebContentsObserver,
2407 observers_,
[email protected]27dd82fd2014-03-03 22:11:432408 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222409 frame_unique_name,
2410 is_main_frame,
2411 url,
2412 transition_type,
2413 render_view_host));
2414}
2415
[email protected]0d0f4c492014-04-02 06:42:572416void WebContentsImpl::DidNavigateMainFramePreCommit(
2417 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2418 // Ensure fullscreen mode is exited before committing the navigation to a
2419 // different page. The next page will not start out assuming it is in
2420 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192421 if (controller_.IsURLInPageNavigation(params.url,
2422 params.was_within_same_page,
2423 NAVIGATION_TYPE_UNKNOWN)) {
2424 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572425 return;
2426 }
2427 if (IsFullscreenForCurrentTab())
2428 GetRenderViewHost()->ExitFullscreen();
2429 DCHECK(!IsFullscreenForCurrentTab());
2430}
2431
[email protected]37567b432014-02-12 01:12:222432void WebContentsImpl::DidNavigateMainFramePostCommit(
2433 const LoadCommittedDetails& details,
2434 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2435 if (details.is_navigation_to_different_page()) {
2436 // Clear the status bubble. This is a workaround for a bug where WebKit
2437 // doesn't let us know that the cursor left an element during a
2438 // transition (this is also why the mouse cursor remains as a hand after
2439 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2440 // clear the bubble when a user navigates to a named anchor in the same
2441 // page.
2442 UpdateTargetURL(details.entry->GetPageID(), GURL());
2443 }
2444
2445 if (!details.is_in_page) {
2446 // Once the main frame is navigated, we're no longer considered to have
2447 // displayed insecure content.
2448 displayed_insecure_content_ = false;
2449 SSLManager::NotifySSLInternalStateChanged(
2450 GetController().GetBrowserContext());
2451 }
2452
2453 // Notify observers about navigation.
2454 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2455 DidNavigateMainFrame(details, params));
2456
2457 if (delegate_) {
2458 delegate_->DidNavigateMainFramePostCommit(this);
2459 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2460 }
2461}
2462
2463void WebContentsImpl::DidNavigateAnyFramePostCommit(
2464 RenderFrameHostImpl* render_frame_host,
2465 const LoadCommittedDetails& details,
2466 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102467 // Now that something has committed, we don't need to track whether the
2468 // initial page has been accessed.
2469 has_accessed_initial_document_ = false;
2470
[email protected]37567b432014-02-12 01:12:222471 // If we navigate off the page, close all JavaScript dialogs.
2472 if (dialog_manager_ && !details.is_in_page)
2473 dialog_manager_->CancelActiveAndPendingDialogs(this);
2474
2475 // Notify observers about navigation.
2476 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2477 DidNavigateAnyFrame(details, params));
2478}
2479
2480void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2481 contents_mime_type_ = mime_type;
2482}
2483
[email protected]277857a2014-06-03 10:38:012484bool WebContentsImpl::CanOverscrollContent() const {
[email protected]37567b432014-02-12 01:12:222485 if (delegate_)
2486 return delegate_->CanOverscrollContent();
2487
2488 return false;
2489}
2490
[email protected]b172aee2012-04-10 17:05:262491void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182492 const GURL& url,
[email protected]70435962011-08-02 20:13:282493 const std::string& security_info,
2494 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182495 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282496 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192497 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182498 cache.Increment();
2499
2500 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082501 int cert_id = 0;
2502 net::CertStatus cert_status = 0;
2503 int security_bits = -1;
2504 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122505 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212506 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122507 &security_bits, &connection_status,
2508 &signed_certificate_timestamp_ids);
2509 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212510 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002511 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2512 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182513
[email protected]b0f724c2013-09-05 04:21:132514 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2515
2516 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2517 DidLoadResourceFromMemoryCache(details));
2518
[email protected]8bfc8272013-09-09 20:10:532519 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2520 scoped_refptr<net::URLRequestContextGetter> request_context(
2521 resource_type == ResourceType::MEDIA ?
2522 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2523 GetRenderProcessHost()->GetID()) :
2524 GetBrowserContext()->GetRequestContextForRenderProcess(
2525 GetRenderProcessHost()->GetID()));
2526 BrowserThread::PostTask(
2527 BrowserThread::IO,
2528 FROM_HERE,
2529 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2530 }
[email protected]724159a2010-12-30 01:11:182531}
2532
[email protected]b172aee2012-04-10 17:05:262533void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392534 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182535 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192536 SSLManager::NotifySSLInternalStateChanged(
2537 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182538}
2539
[email protected]b172aee2012-04-10 17:05:262540void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022541 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582542 LOG(WARNING) << security_origin << " ran insecure content from "
2543 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392544 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412545 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392546 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182547 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412548 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192549 SSLManager::NotifySSLInternalStateChanged(
2550 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182551}
2552
[email protected]501052ff2014-02-21 22:19:072553void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572554 CHECK(render_frame_message_source_);
2555 CHECK(!render_view_message_source_);
2556 RenderFrameHostImpl* rfh =
2557 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2558
[email protected]161eabd2014-03-19 19:47:272559 int render_frame_id = rfh->GetRoutingID();
2560 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572561 FOR_EACH_OBSERVER(WebContentsObserver,
2562 observers_,
[email protected]161eabd2014-03-19 19:47:272563 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182564}
2565
[email protected]b172aee2012-04-10 17:05:262566void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262567 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372568 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122569 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2570 GetRenderProcessHost()->ReceivedBadMessage();
2571 return;
2572 }
[email protected]a1b99262013-12-27 21:56:222573
[email protected]8b3af1e2014-01-24 13:29:122574 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442575 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372576 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422577 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372578
[email protected]61ac9e242014-03-21 20:55:262579 RenderFrameHostImpl* rfh =
2580 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272581 int render_frame_id = rfh->GetRoutingID();
2582 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262583 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252584 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272585 DidFinishLoad(render_frame_id, validated_url,
2586 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312587}
2588
[email protected]960b0372014-05-19 18:01:002589void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2590 RenderFrameHostImpl* rfh =
2591 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2592 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2593
2594 // It is possible to get multiple calls to OnDidStartLoading that don't have
2595 // corresponding calls to OnDidStopLoading:
2596 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2597 // out for a cross-process navigation, and it turns into a placeholder for
2598 // one being rendered in a different process.
2599 // - Also, there might be more than one RenderFrameHost sharing the same
2600 // FrameTreeNode (and thus sharing its ID) each sending a start.
2601 // - But in the future, once clamy@ moves navigation network requests to the
2602 // browser process, there's a good chance that callbacks about starting and
2603 // stopping will all be handled by the browser. When that happens, there
2604 // should no longer be a start/stop call imbalance. TODO(avi): When this
2605 // future arrives, update this code to not allow this case.
2606 DCHECK_GE(loading_frames_in_progress_, 0);
2607 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2608 if (loading_frames_in_progress_ == 0)
2609 DidStartLoading(rfh, to_different_document);
2610 ++loading_frames_in_progress_;
2611 }
2612
2613 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2614 SendLoadProgressChanged();
2615}
2616
2617void WebContentsImpl::OnDidStopLoading() {
2618 RenderFrameHostImpl* rfh =
2619 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2620 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2621
2622 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2623 // Load stopped while we were still tracking load. Make sure we update
2624 // progress based on this frame's completion.
2625 loading_progresses_[render_frame_id] = 1.0;
2626 SendLoadProgressChanged();
2627 // Then we clean-up our states.
2628 if (loading_total_progress_ == 1.0)
2629 ResetLoadProgressState();
2630 }
2631
2632 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2633 // calls DidStopLoading() without a matching DidStartLoading().
2634 if (loading_frames_in_progress_ == 0)
2635 return;
2636 --loading_frames_in_progress_;
2637 if (loading_frames_in_progress_ == 0)
2638 DidStopLoading(rfh);
2639}
2640
2641void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2642 RenderFrameHostImpl* rfh =
2643 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2644 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2645
2646 loading_progresses_[render_frame_id] = load_progress;
2647
2648 // We notify progress change immediately for the first and last updates.
2649 // Also, since the message loop may be pretty busy when a page is loaded, it
2650 // might not execute a posted task in a timely manner so we make sure to
2651 // immediately send progress report if enough time has passed.
2652 base::TimeDelta min_delay =
2653 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2654 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2655 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2656 // If there is a pending task to send progress, it is now obsolete.
2657 loading_weak_factory_.InvalidateWeakPtrs();
2658 SendLoadProgressChanged();
2659 if (loading_total_progress_ == 1.0)
2660 ResetLoadProgressState();
2661 return;
2662 }
2663
2664 if (loading_weak_factory_.HasWeakPtrs())
2665 return;
2666
2667 base::MessageLoop::current()->PostDelayedTask(
2668 FROM_HERE,
2669 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2670 loading_weak_factory_.GetWeakPtr()),
2671 min_delay);
2672}
2673
[email protected]b172aee2012-04-10 17:05:262674void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222675 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2676 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262677}
2678
[email protected]b172aee2012-04-10 17:05:262679void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302680 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262681 minimum_zoom_percent_ = minimum_percent;
2682 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262683}
2684
[email protected]b172aee2012-04-10 17:05:262685void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342686 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432687 if (!delegate_)
2688 return;
2689
[email protected]b9535422012-02-09 01:47:592690 ChildProcessSecurityPolicyImpl* policy =
2691 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222692 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592693 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212694}
2695
[email protected]b172aee2012-04-10 17:05:262696void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2697 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262698 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362699 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432700 if (!delegate_)
2701 return;
2702
[email protected]b9535422012-02-09 01:47:592703 ChildProcessSecurityPolicyImpl* policy =
2704 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322705 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592706 return;
[email protected]8f810632013-06-06 22:33:322707
[email protected]c125e532014-05-10 20:39:062708 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202709}
2710
[email protected]b172aee2012-04-10 17:05:262711void WebContentsImpl::OnFindReply(int request_id,
2712 int number_of_matches,
2713 const gfx::Rect& selection_rect,
2714 int active_match_ordinal,
2715 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432716 if (delegate_) {
2717 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2718 active_match_ordinal, final_update);
2719 }
[email protected]b888919c2011-09-02 00:32:162720}
2721
[email protected]59363fc92012-09-05 03:46:312722#if defined(OS_ANDROID)
2723void WebContentsImpl::OnFindMatchRectsReply(
2724 int version,
2725 const std::vector<gfx::RectF>& rects,
2726 const gfx::RectF& active_rect) {
2727 if (delegate_)
2728 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2729}
[email protected]583418cc2013-01-17 14:01:102730
[email protected]1ff427972013-02-07 21:14:072731void WebContentsImpl::OnOpenDateTimeDialog(
2732 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092733 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2734 GetRenderViewHost(),
2735 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132736 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092737 value.minimum,
2738 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172739 value.step,
2740 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102741}
2742
[email protected]59363fc92012-09-05 03:46:312743#endif
2744
[email protected]f114fa42013-12-06 17:06:442745void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2746 const base::FilePath& path,
2747 bool is_hung) {
2748 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2749
2750 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2751 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2752}
2753
2754void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422755 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442756 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422757 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452758}
2759
[email protected]cfa856d62014-02-22 07:58:402760void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2761 int automation_id) {
2762 DomOperationNotificationDetails details(json_string, automation_id);
2763 NotificationService::current()->Notify(
2764 NOTIFICATION_DOM_OPERATION_RESPONSE,
2765 Source<WebContents>(this),
2766 Details<DomOperationNotificationDetails>(&details));
2767}
2768
[email protected]b172aee2012-04-10 17:05:262769void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2770 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102771 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252772 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102773 AppCacheAccessed(manifest_url, blocked_by_policy));
2774}
2775
[email protected]8bc5ff02013-11-29 06:34:032776void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482777 int color_chooser_id,
2778 SkColor color,
2779 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462780 ColorChooser* new_color_chooser = delegate_ ?
2781 delegate_->OpenColorChooser(this, color, suggestions) :
2782 NULL;
[email protected]820957a2014-01-14 14:56:302783 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212784 return;
[email protected]8ed16472014-04-11 19:02:482785 if (color_chooser_info_.get())
2786 color_chooser_info_->chooser->End();
2787
2788 color_chooser_info_.reset(new ColorChooserInfo(
2789 render_frame_message_source_->GetProcess()->GetID(),
2790 render_frame_message_source_->GetRoutingID(),
2791 new_color_chooser,
2792 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202793}
2794
[email protected]b172aee2012-04-10 17:05:262795void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482796 if (color_chooser_info_ &&
2797 color_chooser_id == color_chooser_info_->identifier)
2798 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202799}
2800
[email protected]b172aee2012-04-10 17:05:262801void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322802 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482803 if (color_chooser_info_ &&
2804 color_chooser_id == color_chooser_info_->identifier)
2805 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202806}
2807
[email protected]d0759f492012-04-19 22:50:502808// This exists for render views that don't have a WebUI, but do have WebUI
2809// bindings enabled.
2810void WebContentsImpl::OnWebUISend(const GURL& source_url,
2811 const std::string& name,
2812 const base::ListValue& args) {
2813 if (delegate_)
2814 delegate_->WebUISend(this, source_url, name, args);
2815}
2816
[email protected]d8415ad92012-08-23 14:40:502817void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442818 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502819 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342820 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162821 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442822 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162823 return;
[email protected]d8415ad92012-08-23 14:40:502824 }
2825
[email protected]8c8fc292012-11-23 18:57:162826 if (!delegate_->RequestPpapiBrokerPermission(
2827 this, url, plugin_path,
2828 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442829 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162830 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442831 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162832 }
[email protected]d8415ad92012-08-23 14:40:502833}
2834
[email protected]ea0309c2013-08-06 19:35:442835void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502836 bool result) {
[email protected]ea0309c2013-08-06 19:35:442837 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502838}
2839
[email protected]c4538072013-03-18 02:17:552840void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372841 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082842 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552843 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392844 // For more info, see comment above classes BrowserPluginEmbedder and
2845 // BrowserPluginGuest.
2846 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142847 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082848 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372849}
2850
[email protected]41225fe2013-03-29 05:32:022851void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392852 int id,
[email protected]749fadd2013-05-15 08:37:482853 int http_status_code,
[email protected]795c28972012-12-06 06:13:392854 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302855 const std::vector<SkBitmap>& bitmaps,
2856 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132857 if (bitmaps.size() != original_bitmap_sizes.size())
2858 return;
2859
[email protected]41225fe2013-03-29 05:32:022860 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2861 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392862 // Currently WebContents notifies us of ANY downloads so that it is
2863 // possible to get here.
2864 return;
2865 }
2866 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302867 iter->second.Run(
2868 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392869 }
[email protected]41225fe2013-03-29 05:32:022870 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392871}
2872
2873void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392874 const std::vector<FaviconURL>& candidates) {
2875 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292876 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392877}
2878
[email protected]1dd0bb752014-02-01 01:16:262879void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2880 bool has_video,
2881 bool has_audio) {
2882// Chrome OS does its own detection of audio and video.
2883#if !defined(OS_CHROMEOS)
2884 scoped_ptr<PowerSaveBlocker> blocker;
2885 if (has_video) {
2886 blocker = PowerSaveBlocker::Create(
2887 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2888#if defined(OS_ANDROID)
2889 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2890 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2891#endif
2892 } else if (has_audio) {
2893 blocker = PowerSaveBlocker::Create(
2894 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2895 }
2896
2897 if (blocker) {
[email protected]96307312014-05-04 01:00:192898 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262899 blocker.release();
2900 }
2901#endif // !defined(OS_CHROMEOS)
2902}
2903
2904void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062905 // Chrome OS does its own detection of audio and video.
2906#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192907 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2908 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062909#endif // !defined(OS_CHROMEOS)
2910}
2911
[email protected]50279492014-05-05 23:24:292912void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152913 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292914 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152915}
[email protected]d9030b82013-07-19 08:26:062916
[email protected]e67ebf32013-02-13 11:07:192917void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:072918 if (delegate_)
2919 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:192920}
2921
[email protected]17e286e2013-03-01 23:29:392922void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2923 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2924 BeforeFormRepostWarningShow());
2925}
2926
[email protected]ec6c05f2013-10-23 18:41:572927
2928void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2929 Activate();
2930 if (delegate_)
2931 delegate_->ShowRepostFormWarningDialog(this);
2932}
2933
[email protected]b4c84012014-04-28 19:51:102934bool WebContentsImpl::HasAccessedInitialDocument() {
2935 return has_accessed_initial_document_;
2936}
2937
[email protected]96d185d2009-04-24 03:28:542938// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592939// loading, or done loading.
2940void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2941 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092942 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262943 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542944 if (is_loading == is_loading_)
2945 return;
2946
2947 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262948 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2949 base::string16());
[email protected]96d185d2009-04-24 03:28:542950 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562951 upload_size_ = 0;
2952 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542953 }
2954
[email protected]fa944cb82013-11-15 17:51:212955 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542956
2957 is_loading_ = is_loading;
2958 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:032959 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:542960
[email protected]6ebdc9b2010-09-27 16:55:572961 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092962 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212963 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542964
[email protected]eab61442013-11-14 18:35:482965 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592966 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482967 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2968 "URL", url);
[email protected]91621872013-10-08 04:04:592969 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2970 DidStartLoading(render_view_host));
2971 } else {
[email protected]eab61442013-11-14 18:35:482972 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2973 "URL", url);
[email protected]91621872013-10-08 04:04:592974 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2975 DidStopLoading(render_view_host));
2976 }
[email protected]66798902013-10-01 18:40:162977
2978 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212979 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2980 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542981 if (details)
[email protected]8ff00d72012-10-23 19:12:212982 det = Details<LoadNotificationDetails>(details);
2983 NotificationService::current()->Notify(
2984 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542985}
2986
[email protected]959be4c2014-04-08 15:01:332987void WebContentsImpl::SelectRange(const gfx::Point& start,
2988 const gfx::Point& end) {
2989 RenderFrameHost* focused_frame = GetFocusedFrame();
2990 if (!focused_frame)
2991 return;
2992
2993 focused_frame->Send(
2994 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
2995}
2996
[email protected]b172aee2012-04-10 17:05:262997void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462998 // If we are creating a RVH for a restored controller, then we need to make
2999 // sure the RenderView starts with a next_page_id_ larger than the number
3000 // of restored entries. This must be called before the RenderView starts
3001 // navigating (to avoid a race between the browser updating max_page_id and
3002 // the renderer updating next_page_id_). Because of this, we only call this
3003 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563004 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583005 if (max_restored_page_id >
3006 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3007 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3008 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323009}
3010
[email protected]b172aee2012-04-10 17:05:263011bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263012 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323013 // For file URLs without a title, use the pathname instead. In the case of a
3014 // synthesized title, we don't want the update to count toward the "one set
3015 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263016 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323017 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513018 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243019 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323020 explicit_set = false; // Don't count synthetic titles toward the set limit.
3021 } else {
[email protected]8af69c6c2014-03-03 19:05:313022 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323023 explicit_set = true;
3024 }
3025
[email protected]987fc3a2011-05-26 14:18:093026 // If a page is created via window.open and never navigated,
3027 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553028 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093029 if (entry) {
[email protected]36fc0392011-12-25 03:59:513030 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093031 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323032
[email protected]36fc0392011-12-25 03:59:513033 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093034 } else {
3035 if (page_title_when_no_navigation_entry_ == final_title)
3036 return false; // Nothing changed, don't bother.
3037
3038 page_title_when_no_navigation_entry_ = final_title;
3039 }
[email protected]420ae012009-04-24 05:16:323040
[email protected]420ae012009-04-24 05:16:323041 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233042 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323043
[email protected]66798902013-10-01 18:40:163044 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533045 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163046
3047 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213048 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463049 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213050 NotificationService::current()->Notify(
3051 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3052 Source<WebContents>(this),
3053 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043054
[email protected]420ae012009-04-24 05:16:323055 return true;
3056}
3057
[email protected]960b0372014-05-19 18:01:003058void WebContentsImpl::SendLoadProgressChanged() {
3059 loading_last_progress_update_ = base::TimeTicks::Now();
3060 double progress = 0.0;
3061 int frame_count = 0;
3062
3063 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3064 it != loading_progresses_.end();
3065 ++it) {
3066 progress += it->second;
3067 ++frame_count;
3068 }
3069 if (frame_count == 0)
3070 return;
3071 progress /= frame_count;
3072 DCHECK(progress <= 1.0);
3073
3074 if (progress <= loading_total_progress_)
3075 return;
3076 loading_total_progress_ = progress;
3077
3078 if (delegate_)
3079 delegate_->LoadProgressChanged(this, progress);
3080}
3081
3082void WebContentsImpl::ResetLoadProgressState() {
3083 loading_progresses_.clear();
3084 loading_total_progress_ = 0.0;
3085 loading_weak_factory_.InvalidateWeakPtrs();
3086 loading_last_progress_update_ = base::TimeTicks();
3087}
3088
[email protected]7b712ee22013-10-03 00:57:283089void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
3090 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323091 // After sending out a swap notification, we need to send a disconnect
3092 // notification so that clients that pick up a pointer to |this| can NULL the
3093 // pointer. See Bug 1230284.
3094 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113095 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283096 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113097
3098 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283099 std::pair<RenderViewHost*, RenderViewHost*> details =
3100 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213101 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283102 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213103 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283104 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393105
3106 // Ensure that the associated embedder gets cleared after a RenderViewHost
3107 // gets swapped, so we don't reuse the same embedder next time a
3108 // RenderViewHost is attached to this WebContents.
3109 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323110}
3111
[email protected]da7a7182013-09-06 08:11:113112// TODO(avi): Remove this entire function because this notification is already
3113// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263114void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323115 if (!notify_disconnection_)
3116 return;
3117
3118 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213119 NotificationService::current()->Notify(
3120 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3121 Source<WebContents>(this),
3122 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323123}
3124
[email protected]cbb1ef592013-06-05 19:49:463125void WebContentsImpl::NotifyNavigationEntryCommitted(
3126 const LoadCommittedDetails& load_details) {
3127 FOR_EACH_OBSERVER(
3128 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3129}
3130
[email protected]f114fa42013-12-06 17:06:443131bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3132 const IPC::Message& message) {
3133 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313134}
3135
[email protected]c31a84802014-04-03 15:55:493136const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3137 return GetLastCommittedURL();
3138}
3139
[email protected]b849847b2013-12-10 21:57:583140void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3141 // Note this is only for subframes, the notification for the main frame
3142 // happens in RenderViewCreated.
3143 FOR_EACH_OBSERVER(WebContentsObserver,
3144 observers_,
3145 RenderFrameCreated(render_frame_host));
3146}
3147
3148void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193149 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583150 FOR_EACH_OBSERVER(WebContentsObserver,
3151 observers_,
3152 RenderFrameDeleted(render_frame_host));
3153}
3154
[email protected]a09d53ce2014-01-31 00:46:423155void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303156 if (delegate_)
3157 delegate_->WorkerCrashed(this);
3158}
3159
[email protected]a09d53ce2014-01-31 00:46:423160void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3161 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103162 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423163 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103164 if (GetBrowserPluginGuest()) {
3165 WebContentsViewGuest* view_guest =
3166 static_cast<WebContentsViewGuest*>(GetView());
3167 context_menu_params = view_guest->ConvertContextMenuParams(params);
3168 }
3169 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423170 return;
3171
[email protected]077e704b2014-05-23 19:24:103172 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3173 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423174}
3175
[email protected]87de04b02014-04-08 22:14:493176void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013177 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493178 const base::string16& message,
3179 const base::string16& default_prompt,
3180 const GURL& frame_url,
3181 JavaScriptMessageType javascript_message_type,
3182 IPC::Message* reply_msg) {
3183 // Suppress JavaScript dialogs when requested. Also suppress messages when
3184 // showing an interstitial as it's shown over the previous page and we don't
3185 // want the hidden page's dialogs to interfere with the interstitial.
3186 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013187 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493188 IsSwappedOut() ||
3189 ShowingInterstitialPage() ||
3190 !delegate_ ||
3191 delegate_->ShouldSuppressDialogs() ||
3192 !delegate_->GetJavaScriptDialogManager();
3193
3194 if (!suppress_this_message) {
3195 std::string accept_lang = GetContentClient()->browser()->
3196 GetAcceptLangs(GetBrowserContext());
3197 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3198 dialog_manager_->RunJavaScriptDialog(
3199 this,
3200 frame_url.GetOrigin(),
3201 accept_lang,
3202 javascript_message_type,
3203 message,
3204 default_prompt,
3205 base::Bind(&WebContentsImpl::OnDialogClosed,
3206 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013207 render_frame_host->GetProcess()->GetID(),
3208 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493209 reply_msg,
3210 false),
3211 &suppress_this_message);
3212 }
3213
3214 if (suppress_this_message) {
3215 // If we are suppressing messages, just reply as if the user immediately
3216 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013217 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3218 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283219 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493220 }
3221
3222 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3223 // http://crbug.com/288961 ). The only safe thing to do here is return.
3224}
3225
3226void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013227 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493228 const base::string16& message,
3229 bool is_reload,
3230 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013231 RenderFrameHostImpl* rfhi =
3232 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493233 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013234 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493235 if (delegate_)
3236 delegate_->WillRunBeforeUnloadConfirm();
3237
3238 bool suppress_this_message =
3239 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3240 !delegate_ ||
3241 delegate_->ShouldSuppressDialogs() ||
3242 !delegate_->GetJavaScriptDialogManager();
3243 if (suppress_this_message) {
3244 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3245 return;
3246 }
3247
3248 is_showing_before_unload_dialog_ = true;
3249 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3250 dialog_manager_->RunBeforeUnloadDialog(
3251 this, message, is_reload,
3252 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013253 render_frame_host->GetProcess()->GetID(),
3254 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283255 false));
[email protected]87de04b02014-04-08 22:14:493256}
3257
[email protected]a86c0e962013-12-17 17:10:393258WebContents* WebContentsImpl::GetAsWebContents() {
3259 return this;
3260}
3261
[email protected]7912e822014-04-16 02:37:033262bool WebContentsImpl::IsNeverVisible() {
3263 if (!delegate_)
3264 return false;
3265 return delegate_->IsNeverVisible(this);
3266}
3267
[email protected]5a3bdf52012-05-24 15:12:573268RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3269 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323270}
3271
[email protected]8ff00d72012-10-23 19:12:213272RendererPreferences WebContentsImpl::GetRendererPrefs(
3273 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463274 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513275}
3276
[email protected]b172aee2012-04-10 17:05:263277gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173278 if (delegate_)
3279 return delegate_->GetRootWindowResizerRect();
3280 return gfx::Rect();
3281}
3282
[email protected]7a846df2012-09-20 19:17:393283void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273284 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393285 browser_plugin_embedder_.reset();
3286}
3287
[email protected]b172aee2012-04-10 17:05:263288void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443289 // Don't send notifications if we are just creating a swapped-out RVH for
3290 // the opener chain. These won't be used for view-source or WebUI, so it's
3291 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243292 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443293 return;
3294
[email protected]86f98a22013-03-20 14:35:003295 if (delegate_)
3296 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083297
[email protected]8ff00d72012-10-23 19:12:213298 NotificationService::current()->Notify(
3299 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3300 Source<WebContents>(this),
3301 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323302
3303 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353304 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213305 if (GetRenderManager()->pending_web_ui())
3306 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323307
[email protected]6286a372013-10-09 04:03:273308 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333309 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323310 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183311 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583312 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323313 }
[email protected]0666aef2009-05-13 19:48:083314
[email protected]60780f412013-02-25 16:34:103315 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263316
3317 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253318 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583319
3320 // We tell the observers now instead of when the main RenderFrameHostImpl is
3321 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3322 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363323 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583324 FOR_EACH_OBSERVER(
3325 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323326}
3327
[email protected]b172aee2012-04-10 17:05:263328void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523329 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323330 // Don't notify the world, since this came from a renderer in the
3331 // background.
3332 return;
3333 }
3334
[email protected]da7a7182013-09-06 08:11:113335 notify_disconnection_ = true;
3336 // TODO(avi): Remove. http://crbug.com/170921
3337 NotificationService::current()->Notify(
3338 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3339 Source<WebContents>(this),
3340 NotificationService::NoDetails());
3341
[email protected]be1f56ab2011-12-22 06:55:313342 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233343 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303344
3345 // Restore the focus to the tab (otherwise the focus will be on the top
3346 // window).
[email protected]484ae5912010-09-29 19:16:143347 if (was_crashed && !FocusLocationBarByDefault() &&
3348 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063349 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143350 }
[email protected]32ded2212011-11-10 18:51:433351
[email protected]d8c660432011-12-22 20:51:253352 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323353}
3354
[email protected]ec6a7eb2013-04-22 17:34:223355void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3356 base::TerminationStatus status,
3357 int error_code) {
[email protected]151a63d2011-12-20 22:32:523358 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323359 // The pending page's RenderViewHost is gone.
3360 return;
3361 }
3362
[email protected]2fcdcc32014-03-05 02:14:073363 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3364 // renderer may not have made a clean exit.
3365 if (IsFullscreenForCurrentTab())
3366 ToggleFullscreenMode(false);
3367
[email protected]698191dc2014-02-25 01:06:133368 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3369 if (dialog_manager_)
3370 dialog_manager_->CancelActiveAndPendingDialogs(this);
3371
[email protected]e3b10d12014-03-28 16:06:093372 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323373 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233374 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453375
[email protected]960b0372014-05-19 18:01:003376 // Reset the loading progress. TODO(avi): What does it mean to have a
3377 // "renderer crash" when there is more than one renderer process serving a
3378 // webpage? Once this function is called at a more granular frame level, we
3379 // probably will need to more granularly reset the state here.
3380 ResetLoadProgressState();
3381 loading_frames_in_progress_ = 0;
3382
[email protected]d8c660432011-12-22 20:51:253383 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273384 observers_,
[email protected]58d5cfe2013-07-10 02:40:523385 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323386}
3387
[email protected]b172aee2012-04-10 17:05:263388void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253389 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063390}
3391
[email protected]b172aee2012-04-10 17:05:263392void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3393 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043394 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153395 // Ensure that this state update comes from either the active RVH or one of
3396 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413397 // TODO(nasko): This should go through RenderFrameHost.
3398 // TODO(creis): We can't update state for cross-process subframes until we
3399 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3400 if (rvh != GetRenderViewHost() &&
3401 !GetRenderManager()->IsRVHOnSwappedOutList(
3402 static_cast<RenderViewHostImpl*>(rvh)))
3403 return;
[email protected]420ae012009-04-24 05:16:323404
3405 // We must be prepared to handle state updates for any page, these occur
3406 // when the user is scrolling and entering form data, as well as when we're
3407 // leaving a page, in which case our state may have already been moved to
3408 // the next page. The navigation controller will look up the appropriate
3409 // NavigationEntry and update it when it is notified via the delegate.
3410
3411 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583412 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323413 if (entry_index < 0)
3414 return;
[email protected]10f417c52011-12-28 21:04:233415 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323416
[email protected]691aa2f2013-05-28 22:52:043417 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323418 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043419 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323420 controller_.NotifyEntryChanged(entry, entry_index);
3421}
3422
[email protected]b172aee2012-04-10 17:05:263423void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513424 if (delegate_)
3425 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323426}
3427
[email protected]b172aee2012-04-10 17:05:263428void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103429#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293430 // The UI may be in an event-tracking loop, such as between the
3431 // mouse-down and mouse-up in text selection or a button click.
3432 // Defer the close until after tracking is complete, so that we
3433 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293434 // TODO(shess): This could get more fine-grained. For instance,
3435 // closing a tab in another window while selecting text in the
3436 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103437 if (view_->IsEventTracking()) {
3438 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293439 return;
3440 }
[email protected]60780f412013-02-25 16:34:103441#endif
[email protected]07707302009-11-06 00:50:293442
[email protected]420ae012009-04-24 05:16:323443 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523444 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513445 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323446}
3447
[email protected]66bbadaf2014-03-28 16:25:543448void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573449 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3450 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573451}
3452
[email protected]b172aee2012-04-10 17:05:263453void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513454 if (delegate_ && delegate_->IsPopupOrPanel(this))
3455 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323456}
3457
[email protected]e3b10d12014-03-28 16:06:093458void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3459 bool to_different_document) {
3460 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3461 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323462}
3463
[email protected]723971b2014-02-12 11:08:253464void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323465 scoped_ptr<LoadNotificationDetails> details;
3466
[email protected]9595fd82013-04-19 21:28:493467 // Use the last committed entry rather than the active one, in case a
3468 // pending entry has been created.
3469 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203470 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493471
[email protected]420ae012009-04-24 05:16:323472 // An entry may not exist for a stop when loading an initial blank page or
3473 // if an iframe injected by script into a blank page finishes loading.
3474 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203475 base::TimeDelta elapsed =
3476 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323477
3478 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513479 entry->GetVirtualURL(),
3480 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323481 elapsed,
3482 &controller_,
3483 controller_.GetCurrentEntryIndex()));
3484 }
3485
[email protected]e3b10d12014-03-28 16:06:093486 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3487 details.get());
[email protected]420ae012009-04-24 05:16:323488}
3489
[email protected]b172aee2012-04-10 17:05:263490void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163491 controller_.DiscardNonCommittedEntries();
3492
3493 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213494 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163495}
3496
[email protected]59167c22013-06-03 18:07:323497void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103498 has_accessed_initial_document_ = true;
3499
[email protected]d1371bf8e2014-04-19 03:26:243500 // We may have left a failed browser-initiated navigation in the address bar
3501 // to let the user edit it and try again. Clear it now that content might
3502 // show up underneath it.
3503 if (!IsLoading() && controller_.GetPendingEntry())
3504 controller_.DiscardPendingEntry();
3505
[email protected]59167c22013-06-03 18:07:323506 // Update the URL display.
3507 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3508}
3509
[email protected]3f19f1a2014-05-02 05:23:273510void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3511 if (opener_) {
3512 // Clear our opener so that future cross-process navigations don't have an
3513 // opener assigned.
3514 RemoveDestructionObserver(opener_);
3515 opener_ = NULL;
3516 }
3517
3518 // Notify all swapped out RenderViewHosts for this tab. This is important
3519 // in case we go back to them, or if another window in those processes tries
3520 // to access window.opener.
3521 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3522}
3523
[email protected]39f2f9252014-05-03 00:54:013524void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293525 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093526 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293527 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093528
3529 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213530 NotificationService::current()->Notify(
3531 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3532 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293533 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083534}
3535
[email protected]ef3adfc2014-05-11 00:04:543536void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3537 int32 page_id,
3538 const base::string16& title,
3539 base::i18n::TextDirection title_direction) {
3540 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3541
3542 // If we have a title, that's a pretty good indication that we've started
3543 // getting useful data.
3544 SetNotWaitingForResponse();
3545
3546 // Try to find the navigation entry, which might not be the current one.
3547 // For example, it might be from a pending RVH for the pending entry.
3548 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3549 rvh->GetSiteInstance(), page_id);
3550
3551 // We can handle title updates when we don't have an entry in
3552 // UpdateTitleForEntry, but only if the update is from the current RVH.
3553 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3554 if (!entry && rvh != GetRenderViewHost())
3555 return;
3556
3557 // TODO(evan): make use of title_direction.
3558 // http://code.google.com/p/chromium/issues/detail?id=27094
3559 if (!UpdateTitleForEntry(entry, title))
3560 return;
3561
3562 // Broadcast notifications when the UI should be updated.
3563 if (entry == controller_.GetEntryAtOffset(0))
3564 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3565}
3566
3567void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3568 const std::string& encoding) {
3569 SetEncoding(encoding);
3570}
3571
[email protected]39f2f9252014-05-03 00:54:013572void WebContentsImpl::DocumentAvailableInMainFrame(
3573 RenderViewHost* render_view_host) {
3574 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3575 DocumentAvailableInMainFrame());
3576}
[email protected]e1c3a552012-05-04 20:51:323577void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3578 // Tell the active RenderViewHost to run unload handlers and close, as long
3579 // as the request came from a RenderViewHost in the same BrowsingInstance.
3580 // In most cases, we receive this from a swapped out RenderViewHost.
3581 // It is possible to receive it from one that has just been swapped in,
3582 // in which case we might as well deliver the message anyway.
3583 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3584 GetRenderViewHost()->ClosePage();
3585}
3586
[email protected]f546640b2012-05-15 00:03:493587void WebContentsImpl::RouteMessageEvent(
3588 RenderViewHost* rvh,
3589 const ViewMsg_PostMessage_Params& params) {
3590 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363591 // came from a RenderViewHost in the same BrowsingInstance or if this
3592 // WebContents is dedicated to a browser plugin guest.
3593 // Note: This check means that an embedder could theoretically receive a
3594 // postMessage from anyone (not just its own guests). However, this is
3595 // probably not a risk for apps since other pages won't have references
3596 // to App windows.
3597 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3598 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493599 return;
3600
3601 ViewMsg_PostMessage_Params new_params(params);
3602
[email protected]0bc7f3542013-10-21 15:05:533603 if (!params.message_port_ids.empty()) {
3604 MessagePortMessageFilter* message_port_message_filter =
3605 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3606 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093607 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3608 params.message_port_ids,
3609 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533610 }
3611
[email protected]f546640b2012-05-15 00:03:493612 // If there is a source_routing_id, translate it to the routing ID for
3613 // the equivalent swapped out RVH in the target process. If we need
3614 // to create a swapped out RVH for the source tab, we create its opener
3615 // chain as well, since those will also be accessible to the target page.
3616 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3617 // Try to look up the WebContents for the source page.
3618 WebContentsImpl* source_contents = NULL;
3619 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3620 rvh->GetProcess()->GetID(), params.source_routing_id);
3621 if (source_rvh) {
3622 source_contents = static_cast<WebContentsImpl*>(
3623 source_rvh->GetDelegate()->GetAsWebContents());
3624 }
3625
3626 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363627 if (GetBrowserPluginGuest()) {
3628 // We create a swapped out RenderView for the embedder in the guest's
3629 // render process but we intentionally do not expose the embedder's
3630 // opener chain to it.
3631 new_params.source_routing_id =
3632 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3633 } else {
3634 new_params.source_routing_id =
3635 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3636 }
[email protected]f546640b2012-05-15 00:03:493637 } else {
3638 // We couldn't find it, so don't pass a source frame.
3639 new_params.source_routing_id = MSG_ROUTING_NONE;
3640 }
3641 }
3642
3643 // In most cases, we receive this from a swapped out RenderViewHost.
3644 // It is possible to receive it from one that has just been swapped in,
3645 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183646 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493647}
3648
[email protected]a796f202012-05-30 14:14:253649bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263650 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253651 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263652 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253653 if (!delegate_)
3654 return false;
3655 return delegate_->AddMessageToConsole(this, level, message, line_no,
3656 source_id);
3657}
3658
[email protected]b172aee2012-04-10 17:05:263659WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273660 // We want to base the page config off of the actual URL, rather than the
3661 // virtual URL.
3662 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3663 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003664 GURL url = controller_.GetActiveEntry()
3665 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153666
[email protected]fa944cb82013-11-15 17:51:213667 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323668}
3669
[email protected]0eba810b2012-10-18 03:19:363670int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213671 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413672 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3673 true, true);
[email protected]0eba810b2012-10-18 03:19:363674}
3675
[email protected]b172aee2012-04-10 17:05:263676void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273677 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253678 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223679
[email protected]ea114722012-03-12 01:11:253680 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173681 if (rdh) // NULL in unittests.
3682 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253683}
3684
[email protected]b172aee2012-04-10 17:05:263685void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443686 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253687 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443688}
3689
[email protected]b172aee2012-04-10 17:05:263690void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563691 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263692 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153693 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523694 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153695 return;
3696
[email protected]9f76c1e2012-03-05 15:15:583697 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3698
[email protected]e5fc1632011-08-08 07:51:533699 // Ignore renderer unresponsive event if debugger is attached to the tab
3700 // since the event may be a result of the renderer sitting on a breakpoint.
3701 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363702 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533703 return;
3704
[email protected]2e9d79f2013-08-16 05:45:563705 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323706 // Hang occurred while firing the beforeunload/unload handler.
3707 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583708 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323709
[email protected]fa944cb82013-11-15 17:51:213710 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323711 return;
3712
3713 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563714 // nothing we can do to recover. If the hang is in the beforeunload handler,
3715 // pretend the beforeunload listeners have all fired and allow the delegate
3716 // to continue closing; the user will not have the option of cancelling the
3717 // close. Otherwise, pretend the unload listeners have all fired and close
3718 // the tab.
3719 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463720 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563721 delegate_->BeforeUnloadFired(this, true, &close);
3722 }
3723 if (close)
3724 Close(rvh);
[email protected]420ae012009-04-24 05:16:323725 return;
3726 }
3727
[email protected]9f76c1e2012-03-05 15:15:583728 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473729 return;
3730
[email protected]6934a702011-12-20 00:04:513731 if (delegate_)
3732 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323733}
3734
[email protected]b172aee2012-04-10 17:05:263735void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513736 if (delegate_)
3737 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323738}
3739
[email protected]b172aee2012-04-10 17:05:263740void WebContentsImpl::LoadStateChanged(
3741 const GURL& url,
3742 const net::LoadStateWithParam& load_state,
3743 uint64 upload_position,
3744 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323745 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563746 upload_position_ = upload_position;
3747 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503748 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213749 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303750 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213751 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323752 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463753 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213754 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463755 }
[email protected]420ae012009-04-24 05:16:323756}
3757
[email protected]b172aee2012-04-10 17:05:263758void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553759 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323760 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123761 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3762 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513763 if (delegate_)
3764 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093765 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323766}
3767
[email protected]58d5cfe2013-07-10 02:40:523768void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543769 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233770 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223771 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543772}
3773
[email protected]b172aee2012-04-10 17:05:263774void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103775 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213776 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263777 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3778 // here during container initialization and normal window size will be set
3779 // later. In case of tab duplication this resizing to 0x0 prevents setting
3780 // normal size later so just ignore it.
3781 if (!size.IsEmpty())
3782 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323783}
3784
[email protected]af905902013-10-01 21:38:513785void WebContentsImpl::CancelModalDialogsForRenderManager() {
3786 // We need to cancel modal dialogs when doing a process swap, since the load
3787 // deferrer would prevent us from swapping out.
3788 if (dialog_manager_)
3789 dialog_manager_->CancelActiveAndPendingDialogs(this);
3790}
3791
[email protected]7b712ee22013-10-03 00:57:283792void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3793 RenderViewHost* new_host) {
3794 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083795
3796 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003797 if (delegate_)
3798 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393799
[email protected]7b712ee22013-10-03 00:57:283800 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543801}
3802
[email protected]14392a52012-05-02 20:28:443803int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3804 SiteInstance* instance) {
3805 if (!opener_)
3806 return MSG_ROUTING_NONE;
3807
3808 // Recursively create RenderViews for anything else in the opener chain.
3809 return opener_->CreateOpenerRenderViews(instance);
3810}
3811
3812int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3813 int opener_route_id = MSG_ROUTING_NONE;
3814
3815 // If this tab has an opener, ensure it has a RenderView in the given
3816 // SiteInstance as well.
3817 if (opener_)
3818 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3819
[email protected]45a22ad2013-02-21 03:25:003820 // If any of the renderers (current, pending, or swapped out) for this
3821 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213822 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3823 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373824
[email protected]fa944cb82013-11-15 17:51:213825 if (GetRenderManager()->pending_render_view_host() &&
3826 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3827 instance)
3828 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003829
[email protected]fa944cb82013-11-15 17:51:213830 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373831 instance);
3832 if (rvh)
3833 return rvh->GetRoutingID();
3834
[email protected]14392a52012-05-02 20:28:443835 // Create a swapped out RenderView in the given SiteInstance if none exists,
3836 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413837 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3838 true, true);
[email protected]14392a52012-05-02 20:28:443839}
3840
[email protected]b172aee2012-04-10 17:05:263841NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193842 return GetController();
[email protected]3a3d47472010-07-15 21:03:543843}
3844
[email protected]b172aee2012-04-10 17:05:263845WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563846 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323847}
3848
[email protected]10f417c52011-12-28 21:04:233849NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263850 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323851 return controller_.GetLastCommittedEntry();
3852}
3853
[email protected]b172aee2012-04-10 17:05:263854bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163855 RenderViewHost* render_view_host,
3856 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043857 int proxy_routing_id,
[email protected]6ab9d682014-05-22 03:48:593858 bool for_main_frame) {
[email protected]e11f0e92013-06-12 15:12:033859 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443860 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483861 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163862 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3863 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3864 // case this because RWH is still a base class of RenderViewHost, and child
3865 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]6ab9d682014-05-22 03:48:593866 if (!for_main_frame) {
[email protected]bffc8302014-01-23 20:52:163867 RenderWidgetHostViewChildFrame* rwh_view_child =
3868 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:163869 rwh_view = rwh_view_child;
3870 } else {
3871 rwh_view = view_->CreateViewForWidget(render_view_host);
3872 }
[email protected]1a98a932009-11-17 00:12:523873
[email protected]420ae012009-04-24 05:16:323874 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443875 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213876 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323877
[email protected]74ce1ad2011-12-16 21:51:463878 // Make sure we use the correct starting page_id in the new RenderView.
3879 UpdateMaxPageIDIfNecessary(render_view_host);
3880 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583881 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463882
[email protected]9f76c1e2012-03-05 15:15:583883 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263884 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493885 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043886 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:493887 max_page_id,
3888 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523889 return false;
[email protected]14392a52012-05-02 20:28:443890 }
[email protected]a4127722011-04-27 23:13:523891
[email protected]a220b5932013-09-21 03:47:443892#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503893 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3894 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443895 if (rwh_view) {
3896 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3897 render_widget_host->WasResized();
3898 }
[email protected]f8233cc2011-05-31 20:24:503899#endif
3900
[email protected]420ae012009-04-24 05:16:323901 return true;
3902}
3903
[email protected]7d244f12013-08-22 21:41:513904#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453905
[email protected]155c7f22013-12-09 17:07:183906base::android::ScopedJavaLocalRef<jobject>
3907WebContentsImpl::GetJavaWebContents() {
3908 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3909
3910 WebContentsAndroid* web_contents_android =
3911 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3912 if (!web_contents_android) {
3913 web_contents_android = new WebContentsAndroid(this);
3914 SetUserData(kWebContentsAndroidKey, web_contents_android);
3915 }
3916 return web_contents_android->GetJavaObject();
3917}
3918
[email protected]7d244f12013-08-22 21:41:513919bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3920 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163921 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:043922 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:593923 true);
[email protected]7d244f12013-08-22 21:41:513924}
[email protected]fc2b46b2014-05-03 16:33:453925
3926#elif defined(OS_MACOSX)
3927
3928void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
3929 view_->SetAllowOverlappingViews(overlapping);
3930}
3931
3932bool WebContentsImpl::GetAllowOverlappingViews() {
3933 return view_->GetAllowOverlappingViews();
3934}
3935
3936void WebContentsImpl::SetOverlayView(WebContents* overlay,
3937 const gfx::Point& offset) {
3938 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
3939 offset);
3940}
3941
3942void WebContentsImpl::RemoveOverlayView() {
3943 view_->RemoveOverlayView();
3944}
3945
[email protected]7d244f12013-08-22 21:41:513946#endif
3947
[email protected]6fba26d2014-04-29 09:38:283948void WebContentsImpl::OnDialogClosed(int render_process_id,
3949 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:263950 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493951 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263952 bool success,
[email protected]fcf75d42013-12-03 20:11:263953 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:283954 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3955 render_frame_id);
[email protected]87de04b02014-04-08 22:14:493956 last_dialog_suppressed_ = dialog_was_suppressed;
3957
[email protected]beb440c2009-11-06 04:08:543958 if (is_showing_before_unload_dialog_ && !success) {
3959 // If a beforeunload dialog is canceled, we need to stop the throbber from
3960 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:283961 if (rfh)
3962 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353963 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103964
[email protected]6d65a462013-06-21 21:29:123965 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3966 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543967 }
[email protected]87de04b02014-04-08 22:14:493968
[email protected]beb440c2009-11-06 04:08:543969 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:283970 if (rfh) {
3971 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3972 dialog_was_suppressed);
3973 } else {
3974 // Don't leak the sync IPC reply if the RFH or process is gone.
3975 delete reply_msg;
3976 }
[email protected]beb440c2009-11-06 04:08:543977}
3978
[email protected]b172aee2012-04-10 17:05:263979void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:543980 if (encoding == last_reported_encoding_)
3981 return;
3982 last_reported_encoding_ = encoding;
3983
3984 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123985 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103986}
[email protected]f45d2a72010-03-08 23:28:353987
[email protected]b172aee2012-04-10 17:05:263988void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:483989 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443990 // Can be NULL during tests.
3991 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:453992 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:363993}
[email protected]9f76c1e2012-03-05 15:15:583994
[email protected]1ac10dca2013-08-20 20:47:043995bool WebContentsImpl::IsHidden() {
3996 return capturer_count_ == 0 && !should_normally_be_visible_;
3997}
3998
[email protected]b0936d22013-11-28 06:47:363999RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214000 return frame_tree_.root()->render_manager();
4001}
4002
[email protected]b172aee2012-04-10 17:05:264003RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584004 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4005}
[email protected]7900bfdb2012-05-24 19:31:244006
[email protected]f8497342013-02-05 22:15:024007BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394008 return browser_plugin_guest_.get();
4009}
4010
[email protected]738f57a2013-06-29 21:06:544011void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4012 CHECK(!browser_plugin_guest_);
4013 browser_plugin_guest_.reset(guest);
4014}
4015
[email protected]f8497342013-02-05 22:15:024016BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394017 return browser_plugin_embedder_.get();
4018}
[email protected]8ff00d72012-10-23 19:12:214019
[email protected]d9030b82013-07-19 08:26:064020void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194021 RenderFrameHost* render_frame_host) {
4022 STLDeleteValues(&power_save_blockers_[render_frame_host]);
4023 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:064024}
4025
4026void WebContentsImpl::ClearAllPowerSaveBlockers() {
4027 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
4028 i != power_save_blockers_.end(); ++i)
4029 STLDeleteValues(&power_save_blockers_[i->first]);
4030 power_save_blockers_.clear();
4031}
4032
[email protected]fc2b46b2014-05-03 16:33:454033gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214034 gfx::Size size;
4035 if (delegate_)
4036 size = delegate_->GetSizeForNewRenderView(this);
4037 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454038 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214039 return size;
4040}
4041
[email protected]9b159a52013-10-03 17:24:554042void WebContentsImpl::OnFrameRemoved(
4043 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:584044 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:554045 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:584046 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:554047}
4048
[email protected]222f5822014-02-05 23:40:494049void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4050 if (!delegate_)
4051 return;
4052 const gfx::Size new_size = GetPreferredSize();
4053 if (new_size != old_size)
4054 delegate_->UpdatePreferredSize(this, new_size);
4055}
4056
[email protected]8ff00d72012-10-23 19:12:214057} // namespace content