blob: 728b454e9d45003f565d4a16d06b24ab878c12ea [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]29998f92014-06-15 03:12:1439#include "content/browser/media/midi_dispatcher_host.h"
[email protected]0bc7f3542013-10-21 15:05:5340#include "content/browser/message_port_message_filter.h"
41#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0642#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3043#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5044#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3245#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5046#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4847#include "content/browser/renderer_host/render_widget_host_view_base.h"
[email protected]01f83f92014-06-17 14:41:5448#include "content/browser/screen_orientation/screen_orientation_dispatcher_host.h"
[email protected]b6583592012-01-25 19:52:3349#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1150#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5851#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0352#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5653#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1454#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4255#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4456#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0257#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1758#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5159#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0260#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3661#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1162#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2863#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4464#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3665#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1766#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1467#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4668#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1569#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0070#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2771#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0072#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3773#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1474#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3275#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3476#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3877#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4278#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2579#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2180#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4881#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5482#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4983#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2084#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0385#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5786#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1687#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2988#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5389#include "net/http/http_cache.h"
90#include "net/http/http_transaction_factory.h"
91#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3492#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5693#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0194#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4195#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5296#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1897#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3198
[email protected]583418cc2013-01-17 14:01:1099#if defined(OS_ANDROID)
[email protected]23f41fd2014-06-21 05:29:17100#include "content/browser/android/content_view_core_impl.h"
[email protected]583418cc2013-01-17 14:01:10101#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:45102#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:18103#include "content/browser/web_contents/web_contents_android.h"
[email protected]74ebfb12013-06-07 20:48:00104#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10105#endif
106
[email protected]f66df822012-05-18 16:52:17107#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50108#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57109#endif
[email protected]3e45ba92009-02-20 21:09:00110
[email protected]420ae012009-04-24 05:16:32111// Cross-Site Navigations
112//
[email protected]b172aee2012-04-10 17:05:26113// If a WebContentsImpl is told to navigate to a different web site (as
114// determined by SiteInstance), it will replace its current RenderViewHost with
115// a new RenderViewHost dedicated to the new SiteInstance. This works as
116// follows:
[email protected]420ae012009-04-24 05:16:32117//
[email protected]fc6c1872013-10-03 01:22:35118// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46119// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32120// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35121// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32122// run in the current RVH.
123// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35124// that it has a pending cross-site request. We will check this on the IO
125// thread when deciding how to handle the response.
126// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46127// cancel all the pending logic. Otherwise we allow the pending RVH to send
128// the navigation request to its renderer.
129// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35130// main resource load on the pending RVH. It creates a
131// CrossSiteResourceHandler to check whether a process swap is needed when
132// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46133// - When RDH receives a response, the BufferedResourceHandler determines
134// whether it is a download. If so, it sends a message to the new renderer
135// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26136// pending RVH remains until the next DidNavigate event for this
137// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32138// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35139// download, the CrossSiteResourceHandler checks whether a process swap is
140// needed (either because CrossSiteRequestManager has state for it or because
141// a transfer was needed for a redirect).
142// - If so, CrossSiteResourceHandler pauses the response to first run the old
143// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36144// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
145// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35146// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
147// to a new process is needed, based on the stored pending_nav_params_. (This
148// is independent of whether we started out with a cross-process navigation.)
149// - If not, it just tells the ResourceDispatcherHost to resume the response
150// to its current RenderViewHost.
151// - If so, it cancels the current pending RenderViewHost and sets up a new
152// navigation using RequestTransferURL. When the transferred request
153// arrives in the ResourceDispatcherHost, we transfer the response and
154// resume it.
[email protected]420ae012009-04-24 05:16:32155// - The pending renderer sends a FrameNavigate message that invokes the
156// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46157// pending RVH.
[email protected]b0936d22013-11-28 06:47:36158// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15159// the user goes back. The process only stays live if another tab is using
160// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32161
[email protected]8ff00d72012-10-23 19:12:21162namespace content {
[email protected]420ae012009-04-24 05:16:32163namespace {
164
[email protected]960b0372014-05-19 18:01:00165const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
166
167// This matches what Blink's ProgressTracker has traditionally used for a
168// minimum progress value.
169const double kMinimumLoadingProgress = 0.1;
170
[email protected]82114f52012-03-20 22:53:41171const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05172
[email protected]155c7f22013-12-09 17:07:18173#if defined(OS_ANDROID)
174const char kWebContentsAndroidKey[] = "web_contents_android";
175#endif // OS_ANDROID
176
[email protected]e4abd3b42013-11-12 18:28:47177base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46178g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
179
[email protected]988ed7132014-03-31 16:25:58180static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39181 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29182 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30183 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02184 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58185 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02186 ++g_next_image_download_id,
187 url,
188 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30189 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02190 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39191}
192
[email protected]8bfc8272013-09-09 20:10:53193void NotifyCacheOnIO(
194 scoped_refptr<net::URLRequestContextGetter> request_context,
195 const GURL& url,
196 const std::string& http_method) {
197 request_context->GetURLRequestContext()->http_transaction_factory()->
198 GetCache()->OnExternalCacheHit(url, http_method);
199}
200
[email protected]9b159a52013-10-03 17:24:55201// Helper function for retrieving all the sites in a frame tree.
202bool CollectSites(BrowserContext* context,
203 std::set<GURL>* sites,
204 FrameTreeNode* node) {
205 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
206 return true;
207}
208
[email protected]a86c0e962013-12-17 17:10:39209bool ForEachFrameInternal(
210 const base::Callback<void(RenderFrameHost*)>& on_frame,
211 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41212 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39213 return true;
214}
215
216void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
217 IPC::Message* message_copy = new IPC::Message(*message);
218 message_copy->set_routing_id(rfh->GetRoutingID());
219 rfh->Send(message_copy);
220}
221
[email protected]948481d2014-06-11 18:32:22222void AddRenderWidgetHostViewToSet(std::set<RenderWidgetHostView*>* set,
223 RenderFrameHost* rfh) {
224 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
225 ->frame_tree_node()
226 ->render_manager()
227 ->GetRenderWidgetHostView();
228 set->insert(rwhv);
[email protected]de3c5d82014-05-28 22:12:59229}
230
[email protected]420ae012009-04-24 05:16:32231} // namespace
232
[email protected]54944cde2012-12-09 09:24:59233WebContents* WebContents::Create(const WebContents::CreateParams& params) {
[email protected]2188b012013-08-01 21:49:15234 return WebContentsImpl::CreateWithOpener(
235 params, static_cast<WebContentsImpl*>(params.opener));
[email protected]d1198fd2012-08-13 22:50:19236}
237
238WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59239 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30240 const SessionStorageNamespaceMap& session_storage_namespace_map) {
[email protected]54944cde2012-12-09 09:24:59241 WebContentsImpl* new_contents = new WebContentsImpl(
242 params.browser_context, NULL);
[email protected]fdac6ade2013-07-20 01:06:30243
244 for (SessionStorageNamespaceMap::const_iterator it =
245 session_storage_namespace_map.begin();
246 it != session_storage_namespace_map.end();
247 ++it) {
248 new_contents->GetController()
249 .SetSessionStorageNamespace(it->first, it->second.get());
250 }
251
[email protected]54944cde2012-12-09 09:24:59252 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19253 return new_contents;
[email protected]a81343d232011-12-27 07:39:20254}
[email protected]746d3052012-05-22 15:15:47255
[email protected]e4abd3b42013-11-12 18:28:47256void WebContentsImpl::AddCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46257 g_created_callbacks.Get().push_back(callback);
258}
259
[email protected]e4abd3b42013-11-12 18:28:47260void WebContentsImpl::RemoveCreatedCallback(const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46261 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
262 if (g_created_callbacks.Get().at(i).Equals(callback)) {
263 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
264 return;
265 }
266 }
267}
268
[email protected]299d7f12012-05-23 05:31:15269WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) {
[email protected]746d3052012-05-22 15:15:47270 return rvh->GetDelegate()->GetAsWebContents();
271}
272
[email protected]a86c0e962013-12-17 17:10:39273WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
274 RenderFrameHostImpl* rfh_impl = static_cast<RenderFrameHostImpl*>(rfh);
275 if (!rfh_impl)
276 return NULL;
277 return rfh_impl->delegate()->GetAsWebContents();
278}
279
[email protected]7fff43e2013-05-21 20:21:10280// WebContentsImpl::DestructionObserver ----------------------------------------
281
282class WebContentsImpl::DestructionObserver : public WebContentsObserver {
283 public:
284 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
285 : WebContentsObserver(watched_contents),
286 owner_(owner) {
287 }
288
289 // WebContentsObserver:
[email protected]12a46832014-05-09 13:35:58290 virtual void WebContentsDestroyed() OVERRIDE {
291 owner_->OnWebContentsDestroyed(
292 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10293 }
294
295 private:
296 WebContentsImpl* owner_;
297
298 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
299};
300
[email protected]8ed16472014-04-11 19:02:48301WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
302 int render_frame_id,
303 ColorChooser* chooser,
304 int identifier)
305 : render_process_id(render_process_id),
306 render_frame_id(render_frame_id),
307 chooser(chooser),
308 identifier(identifier) {
309}
310
311WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
312}
313
[email protected]b172aee2012-04-10 17:05:26314// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32315
[email protected]b172aee2012-04-10 17:05:26316WebContentsImpl::WebContentsImpl(
[email protected]8ff00d72012-10-23 19:12:21317 BrowserContext* browser_context,
[email protected]d1198fd2012-08-13 22:50:19318 WebContentsImpl* opener)
[email protected]b680ad22009-04-15 23:19:42319 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22320 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57321 render_view_host_delegate_view_(NULL),
[email protected]14392a52012-05-02 20:28:44322 opener_(opener),
[email protected]c7c0d822014-04-16 20:19:49323 created_with_opener_(!!opener),
[email protected]2ceee8f2014-01-14 18:02:08324#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41325 accessible_parent_(NULL),
326#endif
[email protected]6ea6bdf2013-12-06 13:35:01327 frame_tree_(new NavigatorImpl(&controller_, this),
328 this, this, this, this),
[email protected]d5f942ba2008-09-26 19:30:34329 is_loading_(false),
[email protected]6dfed692014-05-22 04:18:03330 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23331 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
332 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34333 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26334 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]960b0372014-05-19 18:01:00335 loading_total_progress_(0.0),
336 loading_weak_factory_(this),
337 loading_frames_in_progress_(0),
[email protected]094e5b22009-09-25 04:23:56338 upload_size_(0),
339 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47340 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10341 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55342 capturer_count_(0),
343 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57344 is_being_destroyed_(false),
345 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15346 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01347 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02348 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38349 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21350 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
351 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]bab38af2014-03-30 17:37:29352 totalPinchGestureAmount_(0),
353 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44354 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42355 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03356 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49357 is_subframe_(false),
[email protected]e85165c642014-06-10 14:34:31358 touch_emulation_enabled_(false),
[email protected]87de04b02014-04-08 22:14:49359 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46360 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
361 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55362 frame_tree_.SetFrameRemoveListener(
363 base::Bind(&WebContentsImpl::OnFrameRemoved,
364 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35365}
initial.commit09911bf2008-07-26 23:55:29366
[email protected]b172aee2012-04-10 17:05:26367WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32368 is_being_destroyed_ = true;
369
[email protected]21b41c7e892014-02-28 01:52:24370 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
371 // shutdown and be deleted as well.
372 frame_tree_.ForEach(
373 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
374
[email protected]d9030b82013-07-19 08:26:06375 ClearAllPowerSaveBlockers();
376
[email protected]b24b68a2012-09-24 21:57:26377 for (std::set<RenderWidgetHostImpl*>::iterator iter =
378 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
379 (*iter)->DetachDelegate();
380 }
381 created_widgets_.clear();
382
[email protected]3ab9cb82011-06-03 18:02:07383 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15384 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11385 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07386
[email protected]8ed16472014-04-11 19:02:48387 if (color_chooser_info_.get())
388 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20389
[email protected]420ae012009-04-24 05:16:32390 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32391
[email protected]ca13a442012-04-17 14:00:12392 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21393 NotificationService::current()->Notify(
394 NOTIFICATION_WEB_CONTENTS_DESTROYED,
395 Source<WebContents>(this),
396 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32397
[email protected]df0c843f2014-05-23 20:37:23398 // Destroy all frame tree nodes except for the root; this notifies observers.
399 frame_tree_.ResetForMainFrameSwap();
400 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59401
[email protected]df0c843f2014-05-23 20:37:23402 // Manually call the observer methods for the root frame tree node.
403 RenderFrameHostManager* root = GetRenderManager();
404 if (root->pending_frame_host()) {
[email protected]f273ee52013-10-18 16:05:27405 FOR_EACH_OBSERVER(WebContentsObserver,
406 observers_,
[email protected]df0c843f2014-05-23 20:37:23407 RenderFrameDeleted(root->pending_frame_host()));
[email protected]f273ee52013-10-18 16:05:27408 }
[email protected]df0c843f2014-05-23 20:37:23409 FOR_EACH_OBSERVER(WebContentsObserver,
410 observers_,
411 RenderFrameDeleted(root->current_frame_host()));
[email protected]f273ee52013-10-18 16:05:27412
[email protected]df0c843f2014-05-23 20:37:23413 if (root->pending_render_view_host()) {
414 FOR_EACH_OBSERVER(WebContentsObserver,
415 observers_,
416 RenderViewDeleted(root->pending_render_view_host()));
417 }
[email protected]c06c58c2014-03-12 20:31:59418
[email protected]f273ee52013-10-18 16:05:27419 FOR_EACH_OBSERVER(WebContentsObserver,
420 observers_,
[email protected]df0c843f2014-05-23 20:37:23421 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27422
[email protected]2db9bd72012-04-13 20:20:56423 FOR_EACH_OBSERVER(WebContentsObserver,
424 observers_,
[email protected]12a46832014-05-09 13:35:58425 WebContentsDestroyed());
426
427 FOR_EACH_OBSERVER(WebContentsObserver,
428 observers_,
429 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08430
[email protected]6934a702011-12-20 00:04:51431 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10432
433 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
434 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42435}
436
[email protected]d1198fd2012-08-13 22:50:19437WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59438 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19439 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03440 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59441 WebContentsImpl* new_contents = new WebContentsImpl(
[email protected]50d326e2014-05-20 17:59:06442 params.browser_context, params.opener_suppressed ? NULL : opener);
[email protected]d1198fd2012-08-13 22:50:19443
[email protected]4858e432014-06-23 18:14:17444 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06445 // This makes |new_contents| act as a guest.
446 // For more info, see comment above class BrowserPluginGuest.
[email protected]4858e432014-06-23 18:14:17447 BrowserPluginGuest::Create(params.guest_delegate->GetGuestInstanceID(),
[email protected]83100cd2014-05-10 11:50:06448 new_contents,
[email protected]4858e432014-06-23 18:14:17449 params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06450 // We are instantiating a WebContents for browser plugin. Set its subframe
451 // bit to true.
452 new_contents->is_subframe_ = true;
453 }
[email protected]54944cde2012-12-09 09:24:59454 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19455 return new_contents;
456}
457
[email protected]b0936d22013-11-28 06:47:36458RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21459 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28460}
461
[email protected]7bb761892012-07-20 09:32:47462bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
463 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44464 return OnMessageReceived(render_view_host, NULL, message);
465}
466
467bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
468 RenderFrameHost* render_frame_host,
469 const IPC::Message& message) {
470 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56471 if (GetWebUI() &&
472 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17473 return true;
[email protected]d2353452012-01-19 19:53:56474 }
[email protected]f82d57b52011-04-27 19:13:17475
[email protected]d8c660432011-12-22 20:51:25476 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
477 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33478 if (render_frame_host) {
479 while ((observer = it.GetNext()) != NULL)
480 if (observer->OnMessageReceived(message, render_frame_host))
481 return true;
482 } else {
483 while ((observer = it.GetNext()) != NULL)
484 if (observer->OnMessageReceived(message))
485 return true;
486 }
[email protected]403415a2011-01-10 18:57:53487
[email protected]1d62cf72014-02-07 21:31:57488 // Message handlers should be aware of which
489 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
490 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43491 if (render_frame_host) {
492 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
493 render_frame_host->GetRenderViewHost(), message))
494 return true;
[email protected]1d62cf72014-02-07 21:31:57495 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43496 } else {
497 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
498 render_view_host, message))
499 return true;
[email protected]1d62cf72014-02-07 21:31:57500 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43501 }
[email protected]1d62cf72014-02-07 21:31:57502
[email protected]724159a2010-12-30 01:11:18503 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33504 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]f114fa42013-12-06 17:06:44505 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
506 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40507 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
508 OnDomOperationResponse)
[email protected]e7104762014-06-20 19:17:25509 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeBrandColor,
510 OnBrandColorChanged)
[email protected]8ed16472014-04-11 19:02:48511 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
512 OnDocumentLoadedInFrame)
513 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]960b0372014-05-19 18:01:00514 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStartLoading, OnDidStartLoading)
515 IPC_MESSAGE_HANDLER(FrameHostMsg_DidStopLoading, OnDidStopLoading)
516 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeLoadProgress,
517 OnDidChangeLoadProgress)
[email protected]8ed16472014-04-11 19:02:48518 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
519 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
520 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
521 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19522 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
523 OnMediaPlayingNotification)
524 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
525 OnMediaPausedNotification)
[email protected]724159a2010-12-30 01:11:18526 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
527 OnDidLoadResourceFromMemoryCache)
528 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
529 OnDidDisplayInsecureContent)
530 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
531 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25532 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26533 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21534 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20535 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
536 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16537 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10538 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50539 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50540 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
541 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55542 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
543 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02544 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]9f268072013-11-07 00:02:15546 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
547 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07548 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
549 OnShowValidationMessage)
550 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
551 OnHideValidationMessage)
552 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
553 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48554#if defined(OS_ANDROID)
555 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
556 OnFindMatchRectsReply)
557 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
558 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48559#endif
[email protected]724159a2010-12-30 01:11:18560 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33561 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44562 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57563 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18564
[email protected]724159a2010-12-30 01:11:18565 return handled;
566}
567
[email protected]b172aee2012-04-10 17:05:26568void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18569 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21570 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43571 if (delegate_)
572 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18573}
574
[email protected]d1198fd2012-08-13 22:50:19575NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56576 return controller_;
577}
578
[email protected]d1198fd2012-08-13 22:50:19579const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56580 return controller_;
581}
582
[email protected]8ff00d72012-10-23 19:12:21583BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55584 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30585}
586
[email protected]b172aee2012-04-10 17:05:26587const GURL& WebContentsImpl::GetURL() 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]36fc0392011-12-25 03:59:51590 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31591}
592
[email protected]a093ce02013-07-22 20:53:14593const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24594 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32595 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24596 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
597}
598
599const GURL& WebContentsImpl::GetLastCommittedURL() const {
600 // We may not have a navigation entry yet.
601 NavigationEntry* entry = controller_.GetLastCommittedEntry();
602 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
603}
604
[email protected]8ff00d72012-10-23 19:12:21605WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31606 return delegate_;
607}
608
[email protected]8ff00d72012-10-23 19:12:21609void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31610 // TODO(cbentzel): remove this debugging code?
611 if (delegate == delegate_)
612 return;
613 if (delegate_)
614 delegate_->Detach(this);
615 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08616 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31617 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08618 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00619 if (view_)
[email protected]e85165c642014-06-10 14:34:31620 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08621 }
[email protected]be1f56ab2011-12-22 06:55:31622}
623
[email protected]8ff00d72012-10-23 19:12:21624RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21625 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41626 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16627}
628
[email protected]60eca4eb2013-12-06 00:02:16629RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41630 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16631}
632
[email protected]9c9343b2014-03-08 02:56:07633RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
634 if (!frame_tree_.GetFocusedFrame())
635 return NULL;
636 return frame_tree_.GetFocusedFrame()->current_frame_host();
637}
638
[email protected]a86c0e962013-12-17 17:10:39639void WebContentsImpl::ForEachFrame(
640 const base::Callback<void(RenderFrameHost*)>& on_frame) {
641 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
642}
643
644void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
645 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
646 delete message;
647}
648
[email protected]b172aee2012-04-10 17:05:26649RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21650 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31651}
652
[email protected]6b618e62012-08-16 12:59:18653int WebContentsImpl::GetRoutingID() const {
654 if (!GetRenderViewHost())
655 return MSG_ROUTING_NONE;
656
657 return GetRenderViewHost()->GetRoutingID();
658}
659
[email protected]44470a22013-01-24 01:21:54660int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
661 return fullscreen_widget_routing_id_;
662}
663
[email protected]b172aee2012-04-10 17:05:26664RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21665 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31666}
667
[email protected]4aebbca2013-09-17 22:26:49668RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
669 const {
670 RenderWidgetHost* const widget_host =
671 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
672 GetFullscreenWidgetRoutingID());
673 return widget_host ? widget_host->GetView() : NULL;
674}
675
[email protected]8ff00d72012-10-23 19:12:21676WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31677 return view_.get();
678}
679
[email protected]8ff00d72012-10-23 19:12:21680WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56681 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03682 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
683 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22684 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58685 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22686 web_ui->SetController(controller);
687 return web_ui;
688 }
689
690 delete web_ui;
691 return NULL;
692}
693
[email protected]8ff00d72012-10-23 19:12:21694WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21695 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
696 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31697}
698
[email protected]8ff00d72012-10-23 19:12:21699WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21700 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34701}
702
[email protected]86ef6a392012-05-11 22:03:11703void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22704 if (GetUserAgentOverride() == override)
705 return;
706
707 renderer_preferences_.user_agent_override = override;
708
709 // Send the new override string to the renderer.
710 RenderViewHost* host = GetRenderViewHost();
711 if (host)
712 host->SyncRendererPrefs();
713
714 // Reload the page if a load is currently in progress to avoid having
715 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27716 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22717 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
718 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53719
720 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
721 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11722}
723
724const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22725 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11726}
727
[email protected]2ceee8f2014-01-14 18:02:08728#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41729void WebContentsImpl::SetParentNativeViewAccessible(
730gfx::NativeViewAccessible accessible_parent) {
731 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45732 if (GetRenderViewHost())
733 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41734}
735#endif
736
[email protected]fcf75d42013-12-03 20:11:26737const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55738 // Transient entries take precedence. They are used for interstitial pages
739 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23740 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08741 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21742 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30743 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23744 if (entry) {
[email protected]b5cca982011-05-26 04:42:08745 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23746 }
[email protected]fa944cb82013-11-15 17:51:21747 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
748 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58749 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54750 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32751 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54752 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35753 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26754 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54755 if (!title.empty())
756 return title;
757 }
758 }
759
760 // We use the title for the last committed entry rather than a pending
761 // navigation entry. For example, when the user types in a URL, we want to
762 // keep the old page's title until the new load has committed and we get a new
763 // title.
[email protected]96d185d2009-04-24 03:28:54764 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32765
[email protected]9eeafc012013-11-25 23:49:47766 // We make an exception for initial navigations.
767 if (controller_.IsInitialNavigation()) {
768 // We only want to use the title from the visible entry in one of two cases:
769 // 1. There's already a committed entry for an initial navigation, in which
770 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
771 // 2. The pending entry has been explicitly assigned a title to display.
772 //
773 // If there's no last committed entry and no assigned title, we should fall
774 // back to |page_title_when_no_navigation_entry_| rather than showing the
775 // URL.
776 if (entry ||
777 (controller_.GetVisibleEntry() &&
778 !controller_.GetVisibleEntry()->GetTitle().empty())) {
779 entry = controller_.GetVisibleEntry();
780 }
781 }
[email protected]59167c22013-06-03 18:07:32782
[email protected]45d0ef7f2011-01-05 13:46:23783 if (entry) {
[email protected]b5cca982011-05-26 04:42:08784 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23785 }
[email protected]987fc3a2011-05-26 14:18:09786
787 // |page_title_when_no_navigation_entry_| is finally used
788 // if no title cannot be retrieved.
789 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54790}
791
[email protected]b172aee2012-04-10 17:05:26792int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46793 return GetMaxPageIDForSiteInstance(GetSiteInstance());
794}
795
[email protected]b172aee2012-04-10 17:05:26796int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
797 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33798 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
799 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46800
[email protected]b6583592012-01-25 19:52:33801 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34802}
803
[email protected]b172aee2012-04-10 17:05:26804void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46805 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
806}
807
[email protected]b172aee2012-04-10 17:05:26808void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33809 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46810 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33811 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34812}
813
[email protected]ec6c05f2013-10-23 18:41:57814void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
815 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
816 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57817}
818
[email protected]b172aee2012-04-10 17:05:26819SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21820 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54821}
822
[email protected]b172aee2012-04-10 17:05:26823SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21824 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
825 GetRenderManager()->pending_render_view_host() :
826 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58827 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38828}
829
[email protected]b172aee2012-04-10 17:05:26830bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31831 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49832}
833
[email protected]6dfed692014-05-22 04:18:03834bool WebContentsImpl::IsLoadingToDifferentDocument() const {
835 return is_loading_ && is_load_to_different_document_;
836}
837
[email protected]b172aee2012-04-10 17:05:26838bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:03839 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:31840}
841
[email protected]b172aee2012-04-10 17:05:26842const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31843 return load_state_;
844}
845
[email protected]fcf75d42013-12-03 20:11:26846const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31847 return load_state_host_;
848}
849
[email protected]b172aee2012-04-10 17:05:26850uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31851 return upload_size_;
852}
853
[email protected]b172aee2012-04-10 17:05:26854uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31855 return upload_position_;
856}
857
[email protected]1ae93fb2013-06-14 03:38:56858std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56859 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39860 frame_tree_.ForEach(base::Bind(&CollectSites,
861 base::Unretained(GetBrowserContext()),
862 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56863 return sites;
864}
865
[email protected]b172aee2012-04-10 17:05:26866const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54867 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31868}
869
[email protected]b172aee2012-04-10 17:05:26870bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31871 return displayed_insecure_content_;
872}
873
[email protected]222f5822014-02-05 23:40:49874void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25875 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55876 ++capturer_count_;
877 DVLOG(1) << "There are now " << capturer_count_
878 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49879
880 // Note: This provides a hint to upstream code to size the views optimally
881 // for quality (e.g., to avoid scaling).
882 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
883 preferred_size_for_capture_ = capture_size;
884 OnPreferredSizeChanged(preferred_size_);
885 }
[email protected]54597982013-02-06 01:59:55886}
887
888void WebContentsImpl::DecrementCapturerCount() {
889 --capturer_count_;
890 DVLOG(1) << "There are now " << capturer_count_
891 << " capturing(s) of WebContentsImpl@" << this;
892 DCHECK_LE(0, capturer_count_);
893
[email protected]5a652232013-02-12 06:15:25894 if (is_being_destroyed_)
895 return;
896
[email protected]222f5822014-02-05 23:40:49897 if (capturer_count_ == 0) {
898 const gfx::Size old_size = preferred_size_for_capture_;
899 preferred_size_for_capture_ = gfx::Size();
900 OnPreferredSizeChanged(old_size);
901 }
902
[email protected]1ac10dca2013-08-20 20:47:04903 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55904 DVLOG(1) << "Executing delayed WasHidden().";
905 WasHidden();
906 }
[email protected]be1f56ab2011-12-22 06:55:31907}
908
[email protected]f2bd40812013-07-20 04:30:44909int WebContentsImpl::GetCapturerCount() const {
910 return capturer_count_;
911}
912
[email protected]b172aee2012-04-10 17:05:26913bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31914 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
915 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
916 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49917}
918
[email protected]b172aee2012-04-10 17:05:26919void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
920 int error_code) {
[email protected]443b80e2010-12-14 00:42:23921 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34922 return;
923
[email protected]443b80e2010-12-14 00:42:23924 crashed_status_ = status;
925 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21926 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34927}
928
[email protected]b172aee2012-04-10 17:05:26929base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31930 return crashed_status_;
931}
932
[email protected]b172aee2012-04-10 17:05:26933bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31934 return is_being_destroyed_;
935}
936
[email protected]b172aee2012-04-10 17:05:26937void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34938 if (delegate_)
939 delegate_->NavigationStateChanged(this, changed_flags);
940}
941
[email protected]9a890452014-02-13 22:21:02942base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
943 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33944}
945
[email protected]9e2e4632012-07-27 16:38:41946void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54947 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:59948
[email protected]948481d2014-06-11 18:32:22949 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
950 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:59951 iter != widgets.end();
952 iter++) {
[email protected]948481d2014-06-11 18:32:22953 if (*iter) {
954 (*iter)->Show();
[email protected]789e9152009-08-04 21:59:43955#if defined(OS_MACOSX)
[email protected]948481d2014-06-11 18:32:22956 (*iter)->SetActive(true);
[email protected]789e9152009-08-04 21:59:43957#endif
[email protected]de3c5d82014-05-28 22:12:59958 }
[email protected]789e9152009-08-04 21:59:43959 }
[email protected]96d185d2009-04-24 03:28:54960
[email protected]9a890452014-02-13 22:21:02961 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38962
[email protected]b9769d82012-02-10 00:23:59963 // The resize rect might have changed while this was inactive -- send the new
964 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58965 RenderViewHostImpl* rvh =
966 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59967 if (rvh) {
968 rvh->ResizeRectChanged(GetRootWindowResizerRect());
969 }
[email protected]96d185d2009-04-24 03:28:54970
[email protected]c0d9d5672013-10-09 07:38:03971 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
972
[email protected]54597982013-02-06 01:59:55973 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31974}
975
[email protected]b172aee2012-04-10 17:05:26976void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55977 // If there are entities capturing screenshots or video (e.g., mirroring),
978 // don't activate the "disable rendering" optimization.
979 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52980 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55981 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26982 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52983 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33984 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52985 // calls us).
[email protected]948481d2014-06-11 18:32:22986 std::set<RenderWidgetHostView*> widgets = GetRenderWidgetHostViewsInTree();
987 for (std::set<RenderWidgetHostView*>::iterator iter = widgets.begin();
[email protected]de3c5d82014-05-28 22:12:59988 iter != widgets.end();
989 iter++) {
[email protected]948481d2014-06-11 18:32:22990 if (*iter)
991 (*iter)->Hide();
[email protected]de3c5d82014-05-28 22:12:59992 }
[email protected]96d185d2009-04-24 03:28:54993 }
994
[email protected]c0d9d5672013-10-09 07:38:03995 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
996
[email protected]54597982013-02-06 01:59:55997 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37998}
999
[email protected]b172aee2012-04-10 17:05:261000bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311001 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:271002 return WillNotifyDisconnection() &&
1003 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:581004 !static_cast<RenderViewHostImpl*>(
1005 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311006}
1007
[email protected]1c3f80bd2014-04-08 23:02:061008void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1009 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1010 for_cross_site_transition);
1011}
1012
[email protected]b172aee2012-04-10 17:05:261013void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211014 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401015 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271016}
1017
[email protected]b172aee2012-04-10 17:05:261018WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441019 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451020 // We pass our own opener so that the cloned page can access it if it was
1021 // before.
[email protected]54944cde2012-12-09 09:24:591022 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451023 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591024 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191025 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221026 FOR_EACH_OBSERVER(WebContentsObserver,
1027 observers_,
1028 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271029 return tc;
1030}
1031
[email protected]14392a52012-05-02 20:28:441032void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211033 const NotificationSource& source,
1034 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441035 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211036 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1037 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031038 RenderWidgetHostView* view = host->GetView();
1039 if (view == GetFullscreenRenderWidgetHostView()) {
1040 // We cannot just call view_->RestoreFocus() here. On some platforms,
1041 // attempting to focus the currently-invisible WebContentsView will be
1042 // flat-out ignored. Therefore, this boolean is used to track whether
1043 // we will request focus after the fullscreen widget has been
1044 // destroyed.
1045 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1046 } else {
1047 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1048 i != pending_widget_views_.end(); ++i) {
1049 if (host->GetView() == i->second) {
1050 pending_widget_views_.erase(i);
1051 break;
1052 }
[email protected]bafe6cd2012-05-23 23:09:501053 }
1054 }
1055 break;
1056 }
[email protected]14392a52012-05-02 20:28:441057 default:
1058 NOTREACHED();
1059 }
1060}
1061
[email protected]ec6c05f2013-10-23 18:41:571062WebContents* WebContentsImpl::GetWebContents() {
1063 return this;
1064}
1065
[email protected]54944cde2012-12-09 09:24:591066void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211067 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361068 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211069 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431070 should_normally_be_visible_ = !params.initially_hidden;
1071
[email protected]fa944cb82013-11-15 17:51:211072 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041073 params.browser_context, params.site_instance, params.routing_id,
1074 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191075
[email protected]fc2b46b2014-05-03 16:33:451076 WebContentsViewDelegate* delegate =
1077 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1078
1079 if (browser_plugin_guest_) {
1080 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1081 this, delegate, &render_view_host_delegate_view_));
1082
1083 WebContentsViewGuest* rv = new WebContentsViewGuest(
1084 this, browser_plugin_guest_.get(), platform_view.Pass(),
1085 render_view_host_delegate_view_);
1086 render_view_host_delegate_view_ = rv;
1087 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191088 } else {
[email protected]fc2b46b2014-05-03 16:33:451089 // Regular WebContentsView.
1090 view_.reset(CreateWebContentsView(
1091 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191092 }
[email protected]fc2b46b2014-05-03 16:33:451093 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191094 CHECK(view_.get());
1095
[email protected]ed245db2012-12-18 08:00:451096 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591097 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191098
1099 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101100 if (opener_)
1101 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191102
1103 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211104 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1105 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101106
1107 geolocation_dispatcher_host_.reset(new GeolocationDispatcherHost(this));
[email protected]29998f92014-06-15 03:12:141108 midi_dispatcher_host_.reset(new MidiDispatcherHost(this));
[email protected]f28ef9a32014-05-12 16:36:101109
[email protected]01f83f92014-06-17 14:41:541110 screen_orientation_dispatcher_host_.reset(
1111 new ScreenOrientationDispatcherHost(this));
1112
[email protected]c7654a232013-06-12 21:04:441113#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101114 date_time_chooser_.reset(new DateTimeChooserAndroid());
1115#endif
[email protected]d1198fd2012-08-13 22:50:191116}
1117
[email protected]7fff43e2013-05-21 20:21:101118void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1119 RemoveDestructionObserver(web_contents);
1120
[email protected]14392a52012-05-02 20:28:441121 // Clear the opener if it has been closed.
1122 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441123 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511124 return;
[email protected]14392a52012-05-02 20:28:441125 }
[email protected]ceee8cd2013-03-08 04:59:511126 // Clear a pending contents that has been closed before being shown.
1127 for (PendingContents::iterator iter = pending_contents_.begin();
1128 iter != pending_contents_.end();
1129 ++iter) {
1130 if (iter->second != web_contents)
1131 continue;
1132 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511133 return;
1134 }
1135 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441136}
1137
[email protected]7fff43e2013-05-21 20:21:101138void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1139 if (!ContainsKey(destruction_observers_, web_contents)) {
1140 destruction_observers_[web_contents] =
1141 new DestructionObserver(this, web_contents);
1142 }
1143}
1144
1145void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1146 DestructionObservers::iterator iter =
1147 destruction_observers_.find(web_contents);
1148 if (iter != destruction_observers_.end()) {
1149 delete destruction_observers_[web_contents];
1150 destruction_observers_.erase(iter);
1151 }
1152}
1153
[email protected]b172aee2012-04-10 17:05:261154void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311155 observers_.AddObserver(observer);
1156}
1157
[email protected]b172aee2012-04-10 17:05:261158void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311159 observers_.RemoveObserver(observer);
1160}
1161
[email protected]948481d2014-06-11 18:32:221162std::set<RenderWidgetHostView*>
1163WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1164 std::set<RenderWidgetHostView*> set;
1165 if (ShowingInterstitialPage()) {
1166 set.insert(GetRenderWidgetHostView());
1167 } else {
1168 ForEachFrame(
1169 base::Bind(&AddRenderWidgetHostViewToSet, base::Unretained(&set)));
1170 }
[email protected]de3c5d82014-05-28 22:12:591171 return set;
1172}
1173
[email protected]b172aee2012-04-10 17:05:261174void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341175 if (delegate_)
1176 delegate_->ActivateContents(this);
1177}
1178
[email protected]b172aee2012-04-10 17:05:261179void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121180 if (delegate_)
1181 delegate_->DeactivateContents(this);
1182}
1183
[email protected]b172aee2012-04-10 17:05:261184void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481185 if (delegate_)
1186 delegate_->LostCapture();
1187}
1188
[email protected]b24b68a2012-09-24 21:57:261189void WebContentsImpl::RenderWidgetDeleted(
1190 RenderWidgetHostImpl* render_widget_host) {
1191 if (is_being_destroyed_) {
1192 // |created_widgets_| might have been destroyed.
1193 return;
1194 }
1195
1196 std::set<RenderWidgetHostImpl*>::iterator iter =
1197 created_widgets_.find(render_widget_host);
1198 if (iter != created_widgets_.end())
1199 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541200
1201 if (render_widget_host &&
1202 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491203 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1204 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541205 FOR_EACH_OBSERVER(WebContentsObserver,
1206 observers_,
1207 DidDestroyFullscreenWidget(
1208 fullscreen_widget_routing_id_));
1209 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031210 if (fullscreen_widget_had_focus_at_shutdown_)
1211 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541212 }
[email protected]b24b68a2012-09-24 21:57:261213}
1214
[email protected]b172aee2012-04-10 17:05:261215bool WebContentsImpl::PreHandleKeyboardEvent(
1216 const NativeWebKeyboardEvent& event,
1217 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481218 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131219 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481220}
1221
[email protected]b172aee2012-04-10 17:05:261222void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]63954792011-07-11 04:17:481223 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131224 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481225}
1226
[email protected]d92026ef2014-03-03 21:04:131227bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461228 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191229#if !defined(OS_MACOSX)
1230 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1231 // isn't done for two reasons:
1232 // -the OS already has a gesture to do this through pinch-zoom
1233 // -if a user starts an inertial scroll, let's go, and presses control
1234 // (i.e. control+tab) then the OS's buffered scroll events will come in
1235 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521236 if (delegate_ &&
1237 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551238 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1239 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1240 // gestures, which are regrettably easy to trigger accidentally.
1241 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521242 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1243 return true;
1244 }
[email protected]bccc4472013-04-18 16:37:191245#endif
[email protected]fb3f066e2013-02-12 19:12:521246 return false;
1247}
1248
[email protected]04bce562014-01-30 05:34:541249bool WebContentsImpl::PreHandleGestureEvent(
1250 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031251 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541252}
1253
[email protected]bab38af2014-03-30 17:37:291254bool WebContentsImpl::HandleGestureEvent(
1255 const blink::WebGestureEvent& event) {
1256 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1257 // Use them to implement browser zoom, as for HandleWheelEvent above.
1258 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
[email protected]8ec812e32014-06-03 21:53:331259 event.sourceDevice == blink::WebGestureDeviceTouchpad) {
[email protected]bab38af2014-03-30 17:37:291260 // The scale difference necessary to trigger a zoom action. Derived from
1261 // experimentation to find a value that feels reasonable.
1262 const float kZoomStepValue = 0.6f;
1263
1264 // Find the (absolute) thresholds on either side of the current zoom factor,
1265 // then convert those to actual numbers to trigger a zoom in or out.
1266 // This logic deliberately makes the range around the starting zoom value
1267 // for the gesture twice as large as the other ranges (i.e., the notches are
1268 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1269 // so that it's easier to get back to your starting point than it is to
1270 // overshoot.
1271 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1272 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1273 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1274 : -backStep;
1275 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1276 : backStep;
1277
[email protected]fb546cb2014-04-28 14:09:371278 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291279 if (totalPinchGestureAmount_ > zoomInThreshold) {
1280 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461281 if (delegate_)
1282 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291283 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1284 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461285 if (delegate_)
1286 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291287 }
1288 return true;
1289 }
1290
1291 return false;
1292}
1293
[email protected]2ceee8f2014-01-14 18:02:081294#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411295gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1296 return accessible_parent_;
1297}
1298#endif
1299
[email protected]b172aee2012-04-10 17:05:261300void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431301 if (delegate_)
1302 delegate_->HandleMouseDown();
1303}
1304
[email protected]b172aee2012-04-10 17:05:261305void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481306 if (delegate_)
1307 delegate_->HandleMouseUp();
1308}
1309
[email protected]590a634e2012-07-19 16:38:231310void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481311 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231312 delegate_->HandlePointerActivate();
1313}
1314
1315void WebContentsImpl::HandleGestureBegin() {
1316 if (delegate_)
1317 delegate_->HandleGestureBegin();
1318}
1319
1320void WebContentsImpl::HandleGestureEnd() {
1321 if (delegate_)
1322 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481323}
1324
[email protected]b172aee2012-04-10 17:05:261325void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491326 // This method is being called to enter or leave renderer-initiated fullscreen
1327 // mode. Either way, make sure any existing fullscreen widget is shut down
1328 // first.
1329 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1330 if (widget_view)
1331 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1332
[email protected]8a5e0ca2011-08-25 06:30:471333 if (delegate_)
1334 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371335
1336 FOR_EACH_OBSERVER(WebContentsObserver,
1337 observers_,
1338 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471339}
1340
[email protected]b172aee2012-04-10 17:05:261341bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381342 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121343}
1344
[email protected]a9c81f02012-06-01 00:15:441345void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1346 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371347 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441348 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371349 } else {
1350 GotResponseToLockMouseRequest(false);
1351 }
1352}
1353
[email protected]b172aee2012-04-10 17:05:261354void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371355 if (delegate_)
1356 delegate_->LostMouseLock();
1357}
1358
[email protected]bafe6cd2012-05-23 23:09:501359void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201360 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501361 int route_id,
[email protected]227692c52013-05-31 22:43:041362 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131363 const ViewHostMsg_CreateWindow_Params& params,
1364 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501365 // We usually create the new window in the same BrowsingInstance (group of
1366 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551367 // if the opener is being suppressed (in a non-guest), we create a new
1368 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251369 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551370
[email protected]04cbd3d2013-12-04 04:58:201371 // If the opener is to be suppressed, the new window can be in any process.
1372 // Since routing ids are process specific, we must not have one passed in
1373 // as argument here.
1374 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1375
[email protected]bafe6cd2012-05-23 23:09:501376 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551377 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571378 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501379 GetSiteInstance();
1380
[email protected]04cbd3d2013-12-04 04:58:201381 // A message to create a new window can only come from the active process for
1382 // this WebContentsImpl instance. If any other process sends the request,
1383 // it is invalid and the process must be terminated.
1384 if (GetRenderProcessHost()->GetID() != render_process_id) {
1385 base::ProcessHandle process_handle =
1386 RenderProcessHost::FromID(render_process_id)->GetHandle();
1387 if (process_handle != base::kNullProcessHandle) {
1388 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391389 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201390 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1391 }
1392 return;
1393 }
1394
[email protected]d1198fd2012-08-13 22:50:191395 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341396 //
1397 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301398 const std::string& partition_id =
1399 GetContentClient()->browser()->
1400 GetStoragePartitionIdForSite(GetBrowserContext(),
1401 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461402 StoragePartition* partition = BrowserContext::GetStoragePartition(
1403 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411404 DOMStorageContextWrapper* dom_storage_context =
1405 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191406 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1407 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1408 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371409
1410 if (delegate_ &&
1411 !delegate_->ShouldCreateWebContents(this,
1412 route_id,
1413 params.window_container_type,
1414 params.frame_name,
1415 params.target_url,
1416 partition_id,
1417 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011418 if (route_id != MSG_ROUTING_NONE &&
1419 !RenderViewHost::FromID(render_process_id, route_id)) {
1420 // If the embedder didn't create a WebContents for this route, we need to
1421 // delete the RenderView that had already been created.
1422 Send(new ViewMsg_Close(route_id));
1423 }
[email protected]dd6730412013-08-14 15:03:371424 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1425 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1426 main_frame_route_id);
1427 return;
1428 }
1429
1430 // Create the new web contents. This will automatically create the new
1431 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461432 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591433 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041434 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]50d326e2014-05-20 17:59:061435 create_params.opener = this;
1436 create_params.opener_suppressed = params.opener_suppressed;
1437 if (params.disposition == NEW_BACKGROUND_TAB)
1438 create_params.initially_hidden = true;
1439
[email protected]4858e432014-06-23 18:14:171440 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551441 if (!is_guest) {
1442 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451443 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171444 new_contents = static_cast<WebContentsImpl*>(
1445 WebContents::Create(create_params));
1446 } else {
1447 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551448 }
[email protected]50d326e2014-05-20 17:59:061449 new_contents->GetController().SetSessionStorageNamespace(
1450 partition_id,
1451 session_storage_namespace);
[email protected]3d1dc3a2014-05-17 17:17:261452 new_contents->RenderViewCreated(new_contents->GetRenderViewHost());
[email protected]d1198fd2012-08-13 22:50:191453
[email protected]c4538072013-03-18 02:17:551454 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341455 // will be shown immediately).
1456 if (!params.opener_suppressed) {
1457 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451458 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501459
[email protected]d70bea92013-04-05 04:23:341460 // TODO(brettw): It seems bogus that we have to call this function on the
1461 // newly created object and give it one of its own member variables.
1462 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1463 }
[email protected]bafe6cd2012-05-23 23:09:501464 // Save the created window associated with the route so we can show it
1465 // later.
1466 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1467 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101468 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501469 }
1470
1471 if (delegate_) {
1472 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071473 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131474 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501475 }
1476
1477 if (params.opener_suppressed) {
1478 // When the opener is suppressed, the original renderer cannot access the
1479 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001480 bool was_blocked = false;
1481 if (delegate_) {
1482 gfx::Rect initial_pos;
1483 delegate_->AddNewContents(
1484 this, new_contents, params.disposition, initial_pos,
1485 params.user_gesture, &was_blocked);
1486 }
1487 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211488 OpenURLParams open_params(params.target_url,
1489 Referrer(),
1490 CURRENT_TAB,
1491 PAGE_TRANSITION_LINK,
1492 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301493 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001494 new_contents->OpenURL(open_params);
1495 }
[email protected]bafe6cd2012-05-23 23:09:501496 }
1497}
1498
[email protected]a8504022013-12-04 20:23:511499void WebContentsImpl::CreateNewWidget(int render_process_id,
1500 int route_id,
[email protected]180ef242013-11-07 06:50:461501 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511502 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501503}
1504
[email protected]a8504022013-12-04 20:23:511505void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1506 int route_id) {
1507 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501508}
1509
[email protected]a8504022013-12-04 20:23:511510void WebContentsImpl::CreateNewWidget(int render_process_id,
1511 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501512 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461513 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211514 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511515 // A message to create a new widget can only come from the active process for
1516 // this WebContentsImpl instance. If any other process sends the request,
1517 // it is invalid and the process must be terminated.
1518 if (process->GetID() != render_process_id) {
1519 base::ProcessHandle process_handle =
1520 RenderProcessHost::FromID(render_process_id)->GetHandle();
1521 if (process_handle != base::kNullProcessHandle) {
1522 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391523 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511524 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1525 }
1526 return;
1527 }
1528
[email protected]bafe6cd2012-05-23 23:09:501529 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041530 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261531 created_widgets_.insert(widget_host);
1532
[email protected]cfd80b02014-05-01 17:46:481533 RenderWidgetHostViewBase* widget_view =
1534 static_cast<RenderWidgetHostViewBase*>(
1535 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191536 if (!widget_view)
1537 return;
[email protected]bafe6cd2012-05-23 23:09:501538 if (!is_fullscreen) {
1539 // Popups should not get activated.
1540 widget_view->SetPopupType(popup_type);
1541 }
1542 // Save the created widget associated with the route so we can show it later.
1543 pending_widget_views_[route_id] = widget_view;
1544
1545#if defined(OS_MACOSX)
1546 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1547 // to allow it to survive the trip without being hosted.
1548 base::mac::NSObjectRetain(widget_view->GetNativeView());
1549#endif
1550}
1551
1552void WebContentsImpl::ShowCreatedWindow(int route_id,
1553 WindowOpenDisposition disposition,
1554 const gfx::Rect& initial_pos,
1555 bool user_gesture) {
1556 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001557 if (contents) {
1558 WebContentsDelegate* delegate = GetDelegate();
1559 if (delegate) {
1560 delegate->AddNewContents(
1561 this, contents, disposition, initial_pos, user_gesture, NULL);
1562 }
1563 }
[email protected]bafe6cd2012-05-23 23:09:501564}
1565
1566void WebContentsImpl::ShowCreatedWidget(int route_id,
1567 const gfx::Rect& initial_pos) {
1568 ShowCreatedWidget(route_id, false, initial_pos);
1569}
1570
1571void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1572 ShowCreatedWidget(route_id, true, gfx::Rect());
1573}
1574
1575void WebContentsImpl::ShowCreatedWidget(int route_id,
1576 bool is_fullscreen,
1577 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481578 RenderWidgetHostViewBase* widget_host_view =
1579 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501580 if (!widget_host_view)
1581 return;
[email protected]cfd80b02014-05-01 17:46:481582
1583 RenderWidgetHostView* view = NULL;
1584 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1585 if (guest && guest->embedder_web_contents()) {
1586 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1587 } else {
1588 view = GetRenderWidgetHostView();
1589 }
1590
[email protected]4aebbca2013-09-17 22:26:491591 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311592 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:031593 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:311594 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491595 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1596 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1597 delegate_->ToggleFullscreenModeForTab(this, true);
1598 } else {
[email protected]cfd80b02014-05-01 17:46:481599 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491600 }
[email protected]4aebbca2013-09-17 22:26:491601 FOR_EACH_OBSERVER(WebContentsObserver,
1602 observers_,
1603 DidShowFullscreenWidget(route_id));
1604 if (!widget_host_view->HasFocus())
1605 widget_host_view->Focus();
1606 } else {
[email protected]cfd80b02014-05-01 17:46:481607 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491608 }
[email protected]89054502012-06-03 10:29:241609
1610 RenderWidgetHostImpl* render_widget_host_impl =
1611 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1612 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311613 // Only allow privileged mouse lock for fullscreen render widget, which is
1614 // used to implement Pepper Flash fullscreen.
1615 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501616
1617#if defined(OS_MACOSX)
1618 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1619 // properly embedded (or purposefully ignored) we can release the retain we
1620 // took in CreateNewWidget().
1621 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1622#endif
1623}
1624
1625WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1626 PendingContents::iterator iter = pending_contents_.find(route_id);
1627
1628 // Certain systems can block the creation of new windows. If we didn't succeed
1629 // in creating one, just return NULL.
1630 if (iter == pending_contents_.end()) {
1631 return NULL;
1632 }
1633
1634 WebContentsImpl* new_contents = iter->second;
1635 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101636 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501637
[email protected]d70bea92013-04-05 04:23:341638 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:251639 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:341640 return new_contents;
1641
[email protected]bafe6cd2012-05-23 23:09:501642 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1643 !new_contents->GetRenderViewHost()->GetView())
1644 return NULL;
1645
1646 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1647 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1648 return new_contents;
1649}
1650
1651RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1652 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1653 if (iter == pending_widget_views_.end()) {
1654 DCHECK(false);
1655 return NULL;
1656 }
1657
1658 RenderWidgetHostView* widget_host_view = iter->second;
1659 pending_widget_views_.erase(route_id);
1660
1661 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1662 if (!widget_host->GetProcess()->HasConnection()) {
1663 // The view has gone away or the renderer crashed. Nothing to do.
1664 return NULL;
1665 }
1666
1667 return widget_host_view;
1668}
1669
[email protected]f13b4202012-06-12 23:53:231670void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091671 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211672 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371673 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231674 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371675 } else {
1676 callback.Run(MediaStreamDevices(),
1677 MEDIA_DEVICE_INVALID_STATE,
1678 scoped_ptr<MediaStreamUI>());
1679 }
[email protected]f13b4202012-06-12 23:53:231680}
1681
[email protected]cc9200432013-07-23 23:02:401682SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1683 SiteInstance* instance) {
1684 return controller_.GetSessionStorageNamespace(instance);
1685}
1686
[email protected]6de7fc482014-06-06 10:46:441687SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
1688 return controller_.GetSessionStorageNamespaceMap();
1689}
1690
[email protected]9b159a52013-10-03 17:24:551691FrameTree* WebContentsImpl::GetFrameTree() {
1692 return &frame_tree_;
1693}
1694
[email protected]31a71eaf2014-03-13 01:47:361695void WebContentsImpl::AccessibilityEventReceived(
1696 const std::vector<AXEventNotificationDetails>& details) {
1697 FOR_EACH_OBSERVER(
1698 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1699}
1700
[email protected]edc3af82013-12-12 21:24:071701void WebContentsImpl::OnShowValidationMessage(
1702 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291703 const base::string16& main_text,
1704 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071705 if (delegate_)
1706 delegate_->ShowValidationMessage(
1707 this, anchor_in_root_view, main_text, sub_text);
1708}
1709
1710void WebContentsImpl::OnHideValidationMessage() {
1711 if (delegate_)
1712 delegate_->HideValidationMessage(this);
1713}
1714
1715void WebContentsImpl::OnMoveValidationMessage(
1716 const gfx::Rect& anchor_in_root_view) {
1717 if (delegate_)
1718 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1719}
1720
[email protected]32deec62013-05-15 23:55:041721void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1722 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441723 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041724}
1725
[email protected]e85165c642014-06-10 14:34:311726void WebContentsImpl::OnTouchEmulationEnabled(bool enabled) {
1727 touch_emulation_enabled_ = enabled;
1728 if (view_)
1729 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
1730}
1731
[email protected]b172aee2012-04-10 17:05:261732void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491733 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231734 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491735 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331736}
1737
[email protected]b172aee2012-04-10 17:05:261738void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341739 if (delegate_)
1740 delegate_->ResizeDueToAutoResize(this, new_size);
1741}
1742
[email protected]b172aee2012-04-10 17:05:261743WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201744 if (!delegate_)
1745 return NULL;
[email protected]00c37fc2011-08-02 00:22:501746
[email protected]e5d549d2011-12-28 01:29:201747 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201748 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341749}
1750
[email protected]6b618e62012-08-16 12:59:181751bool WebContentsImpl::Send(IPC::Message* message) {
1752 if (!GetRenderViewHost()) {
1753 delete message;
1754 return false;
1755 }
1756
1757 return GetRenderViewHost()->Send(message);
1758}
1759
[email protected]b172aee2012-04-10 17:05:261760bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501761 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261762 FrameTreeNode* node = frame_tree_.root();
1763
1764 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1765 // specified in the pending entry.
1766 NavigationEntryImpl* pending_entry =
1767 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1768 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1769 pending_entry->frame_tree_node_id() != -1) {
1770 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1771 }
1772
1773 return node->navigator()->NavigateToPendingEntry(
1774 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541775}
[email protected]96d185d2009-04-24 03:28:541776
[email protected]a86c0e962013-12-17 17:10:391777void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1778 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441779 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391780 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441781}
1782
[email protected]20ca0382013-02-28 19:50:071783void WebContentsImpl::AttachInterstitialPage(
1784 InterstitialPageImpl* interstitial_page) {
1785 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211786 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291787
1788 // Cancel any visible dialogs so that they don't interfere with the
1789 // interstitial.
1790 if (dialog_manager_)
1791 dialog_manager_->CancelActiveAndPendingDialogs(this);
1792
[email protected]20ca0382013-02-28 19:50:071793 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1794 DidAttachInterstitialPage());
1795}
1796
1797void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571798 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211799 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071800 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1801 DidDetachInterstitialPage());
1802}
1803
[email protected]b172aee2012-04-10 17:05:261804void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331805 const SiteInstance* site_instance,
1806 int history_length,
1807 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411808 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1809 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211810 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191811 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141812 return;
[email protected]9e1ad4b2011-08-14 16:49:191813 }
[email protected]9f76c1e2012-03-05 15:15:581814 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191815 if (!rvh) {
1816 NOTREACHED();
1817 return;
1818 }
[email protected]9f76c1e2012-03-05 15:15:581819 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191820 NOTREACHED();
1821 return;
1822 }
[email protected]6b618e62012-08-16 12:59:181823 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1824 history_length,
1825 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141826}
1827
[email protected]4fed3702014-04-01 09:08:001828void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171829 RenderFrameHost* focused_frame = GetFocusedFrame();
1830 if (!focused_frame)
1831 return;
1832
[email protected]959be4c2014-04-08 15:01:331833 focused_frame->Send(new FrameMsg_Reload(
1834 focused_frame->GetRoutingID(), ignore_cache));
1835}
1836
1837void WebContentsImpl::Undo() {
1838 RenderFrameHost* focused_frame = GetFocusedFrame();
1839 if (!focused_frame)
1840 return;
1841
1842 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1843 RecordAction(base::UserMetricsAction("Undo"));
1844}
1845
1846void WebContentsImpl::Redo() {
1847 RenderFrameHost* focused_frame = GetFocusedFrame();
1848 if (!focused_frame)
1849 return;
1850 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1851 RecordAction(base::UserMetricsAction("Redo"));
1852}
1853
1854void WebContentsImpl::Cut() {
1855 RenderFrameHost* focused_frame = GetFocusedFrame();
1856 if (!focused_frame)
1857 return;
1858
1859 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1860 RecordAction(base::UserMetricsAction("Cut"));
1861}
1862
1863void WebContentsImpl::Copy() {
1864 RenderFrameHost* focused_frame = GetFocusedFrame();
1865 if (!focused_frame)
1866 return;
1867
1868 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1869 RecordAction(base::UserMetricsAction("Copy"));
1870}
1871
1872void WebContentsImpl::CopyToFindPboard() {
1873#if defined(OS_MACOSX)
1874 RenderFrameHost* focused_frame = GetFocusedFrame();
1875 if (!focused_frame)
1876 return;
1877
1878 // Windows/Linux don't have the concept of a find pasteboard.
1879 focused_frame->Send(
1880 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1881 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1882#endif
1883}
1884
1885void WebContentsImpl::Paste() {
1886 RenderFrameHost* focused_frame = GetFocusedFrame();
1887 if (!focused_frame)
1888 return;
1889
1890 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1891 RecordAction(base::UserMetricsAction("Paste"));
1892}
1893
1894void WebContentsImpl::PasteAndMatchStyle() {
1895 RenderFrameHost* focused_frame = GetFocusedFrame();
1896 if (!focused_frame)
1897 return;
1898
1899 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1900 focused_frame->GetRoutingID()));
1901 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1902}
1903
1904void WebContentsImpl::Delete() {
1905 RenderFrameHost* focused_frame = GetFocusedFrame();
1906 if (!focused_frame)
1907 return;
1908
1909 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1910 RecordAction(base::UserMetricsAction("DeleteSelection"));
1911}
1912
1913void WebContentsImpl::SelectAll() {
1914 RenderFrameHost* focused_frame = GetFocusedFrame();
1915 if (!focused_frame)
1916 return;
1917
1918 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1919 RecordAction(base::UserMetricsAction("SelectAll"));
1920}
1921
1922void WebContentsImpl::Unselect() {
1923 RenderFrameHost* focused_frame = GetFocusedFrame();
1924 if (!focused_frame)
1925 return;
1926
1927 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1928 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171929}
1930
1931void WebContentsImpl::Replace(const base::string16& word) {
1932 RenderFrameHost* focused_frame = GetFocusedFrame();
1933 if (!focused_frame)
1934 return;
1935
[email protected]959be4c2014-04-08 15:01:331936 focused_frame->Send(new InputMsg_Replace(
1937 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171938}
1939
1940void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1941 RenderFrameHost* focused_frame = GetFocusedFrame();
1942 if (!focused_frame)
1943 return;
1944
[email protected]959be4c2014-04-08 15:01:331945 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1946 focused_frame->GetRoutingID(), word));
1947}
1948
1949void WebContentsImpl::NotifyContextMenuClosed(
1950 const CustomContextMenuContext& context) {
1951 RenderFrameHost* focused_frame = GetFocusedFrame();
1952 if (!focused_frame)
1953 return;
1954
1955 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1956 focused_frame->GetRoutingID(), context));
1957}
1958
1959void WebContentsImpl::ExecuteCustomContextMenuCommand(
1960 int action, const CustomContextMenuContext& context) {
1961 RenderFrameHost* focused_frame = GetFocusedFrame();
1962 if (!focused_frame)
1963 return;
1964
1965 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1966 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001967}
1968
[email protected]fc2b46b2014-05-03 16:33:451969gfx::NativeView WebContentsImpl::GetNativeView() {
1970 return view_->GetNativeView();
1971}
1972
1973gfx::NativeView WebContentsImpl::GetContentNativeView() {
1974 return view_->GetContentNativeView();
1975}
1976
1977gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1978 return view_->GetTopLevelNativeWindow();
1979}
1980
1981gfx::Rect WebContentsImpl::GetViewBounds() {
1982 return view_->GetViewBounds();
1983}
1984
1985gfx::Rect WebContentsImpl::GetContainerBounds() {
1986 gfx::Rect rv;
1987 view_->GetContainerBounds(&rv);
1988 return rv;
1989}
1990
1991DropData* WebContentsImpl::GetDropData() {
1992 return view_->GetDropData();
1993}
1994
1995void WebContentsImpl::Focus() {
[email protected]0b431992014-06-24 00:08:031996 RenderWidgetHostView* const fullscreen_view =
1997 GetFullscreenRenderWidgetHostView();
1998 if (fullscreen_view)
1999 fullscreen_view->Focus();
2000 else
2001 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452002}
2003
2004void WebContentsImpl::SetInitialFocus() {
[email protected]0b431992014-06-24 00:08:032005 RenderWidgetHostView* const fullscreen_view =
2006 GetFullscreenRenderWidgetHostView();
2007 if (fullscreen_view)
2008 fullscreen_view->Focus();
2009 else
2010 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452011}
2012
2013void WebContentsImpl::StoreFocus() {
[email protected]0b431992014-06-24 00:08:032014 if (!GetFullscreenRenderWidgetHostView())
2015 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452016}
2017
2018void WebContentsImpl::RestoreFocus() {
[email protected]0b431992014-06-24 00:08:032019 RenderWidgetHostView* const fullscreen_view =
2020 GetFullscreenRenderWidgetHostView();
2021 if (fullscreen_view)
2022 fullscreen_view->Focus();
2023 else
2024 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452025}
2026
[email protected]b172aee2012-04-10 17:05:262027void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272028 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212029 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542030 return;
2031 }
[email protected]0b431992014-06-24 00:08:032032 RenderWidgetHostView* const fullscreen_view =
2033 GetFullscreenRenderWidgetHostView();
2034 if (fullscreen_view) {
2035 fullscreen_view->Focus();
2036 return;
2037 }
[email protected]9f76c1e2012-03-05 15:15:582038 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542039}
2040
[email protected]b172aee2012-04-10 17:05:262041bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212042 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542043}
2044
[email protected]b172aee2012-04-10 17:05:262045InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212046 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222047}
2048
[email protected]b172aee2012-04-10 17:05:262049bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162050 // WebKit creates Document object when MIME type is application/xhtml+xml,
2051 // so we also support this MIME type.
2052 return contents_mime_type_ == "text/html" ||
2053 contents_mime_type_ == "text/xml" ||
2054 contents_mime_type_ == "application/xhtml+xml" ||
2055 contents_mime_type_ == "text/plain" ||
2056 contents_mime_type_ == "text/css" ||
2057 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2058}
2059
[email protected]b172aee2012-04-10 17:05:262060void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592061 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162062 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552063 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012064 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142065 return;
[email protected]c7dd2f62011-07-18 15:57:592066 }
2067
2068 Stop();
2069
2070 // Create the save package and possibly prompt the user for the name to save
2071 // the page as. The user prompt is an asynchronous operation that runs on
2072 // another thread.
2073 save_package_ = new SavePackage(this);
2074 save_package_->GetSaveInfo();
2075}
2076
2077// Used in automated testing to bypass prompting the user for file names.
2078// Instead, the names and paths are hard coded rather than running them through
2079// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342080bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2081 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212082 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592083 // Stop the page from navigating.
2084 Stop();
2085
2086 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212087 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592088}
2089
[email protected]3c71576ce2013-07-23 02:00:012090void WebContentsImpl::SaveFrame(const GURL& url,
2091 const Referrer& referrer) {
2092 if (!GetURL().is_valid())
2093 return;
2094 bool is_main_frame = (url == GetURL());
2095
2096 DownloadManager* dlm =
2097 BrowserContext::GetDownloadManager(GetBrowserContext());
2098 if (!dlm)
2099 return;
2100 int64 post_id = -1;
2101 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272102 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012103 if (entry)
2104 post_id = entry->GetPostID();
2105 }
2106 scoped_ptr<DownloadUrlParameters> params(
2107 DownloadUrlParameters::FromWebContents(this, url));
2108 params->set_referrer(referrer);
2109 params->set_post_id(post_id);
2110 params->set_prefer_cache(true);
2111 if (post_id >= 0)
2112 params->set_method("POST");
2113 params->set_prompt(true);
2114 dlm->DownloadUrl(params.Pass());
2115}
2116
[email protected]b172aee2012-04-10 17:05:262117void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342118 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482119 const base::Callback<void(int64)>& callback) {
2120 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122121}
2122
[email protected]b172aee2012-04-10 17:05:262123const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272124 return contents_mime_type_;
2125}
2126
[email protected]b172aee2012-04-10 17:05:262127bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272128 return notify_disconnection_;
2129}
2130
[email protected]b172aee2012-04-10 17:05:262131void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312132 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182133 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162134}
2135
[email protected]b172aee2012-04-10 17:05:262136void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542137 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182138 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162139}
2140
[email protected]8ff00d72012-10-23 19:12:212141RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272142 return &renderer_preferences_;
2143}
2144
[email protected]e35ccd52012-05-23 16:22:472145void WebContentsImpl::Close() {
2146 Close(GetRenderViewHost());
2147}
2148
[email protected]cf200a562013-05-03 16:24:292149void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462150 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292151 if (browser_plugin_embedder_.get())
2152 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2153 screen_x, screen_y, operation);
2154 if (GetRenderViewHost())
2155 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2156 screen_x, screen_y, operation);
2157}
2158
[email protected]d60f3702013-12-26 16:30:242159void WebContentsImpl::DidGetResourceResponseStart(
2160 const ResourceRequestDetails& details) {
2161 controller_.ssl_manager()->DidStartResourceResponse(details);
2162
2163 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2164 DidGetResourceResponseStart(details));
2165
2166 // TODO(avi): Remove. http://crbug.com/170921
2167 NotificationService::current()->Notify(
2168 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2169 Source<WebContents>(this),
2170 Details<const ResourceRequestDetails>(&details));
2171}
2172
2173void WebContentsImpl::DidGetRedirectForResourceRequest(
2174 RenderViewHost* render_view_host,
2175 const ResourceRedirectDetails& details) {
2176 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2177
2178 FOR_EACH_OBSERVER(
2179 WebContentsObserver,
2180 observers_,
2181 DidGetRedirectForResourceRequest(render_view_host, details));
2182
2183 // TODO(avi): Remove. http://crbug.com/170921
2184 NotificationService::current()->Notify(
2185 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2186 Source<WebContents>(this),
2187 Details<const ResourceRedirectDetails>(&details));
2188}
2189
[email protected]b172aee2012-04-10 17:05:262190void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522191 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582192 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512193 if (delegate_)
2194 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292195 if (browser_plugin_embedder_.get())
2196 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342197}
2198
[email protected]e35ccd52012-05-23 16:22:472199void WebContentsImpl::UserGestureDone() {
2200 OnUserGesture();
2201}
2202
[email protected]b172aee2012-04-10 17:05:262203void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272204 closed_by_user_gesture_ = value;
2205}
2206
[email protected]b172aee2012-04-10 17:05:262207bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272208 return closed_by_user_gesture_;
2209}
2210
[email protected]b172aee2012-04-10 17:05:262211int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592212 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172213 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012214 // Calculate the zoom percent from the factor. Round up to the nearest whole
2215 // number.
[email protected]b75b8292010-10-01 07:28:252216 int percent = static_cast<int>(
[email protected]fce823222014-05-30 16:24:302217 ZoomLevelToZoomFactor(HostZoomMap::GetZoomLevel(this)) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252218 *enable_decrement = percent > minimum_zoom_percent_;
2219 *enable_increment = percent < maximum_zoom_percent_;
2220 return percent;
2221}
2222
[email protected]b172aee2012-04-10 17:05:262223void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502224 if (!delegate_)
2225 return;
2226
[email protected]6286a372013-10-09 04:03:272227 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2228 if (!entry)
[email protected]1788e772010-12-15 16:40:502229 return;
2230
[email protected]6286a372013-10-09 04:03:272231 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122232}
2233
[email protected]b172aee2012-04-10 17:05:262234void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042235 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272236 if (!delegate_)
2237 return;
2238
[email protected]691aa2f2013-05-28 22:52:042239 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272240}
2241
[email protected]b172aee2012-04-10 17:05:262242int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272243 return minimum_zoom_percent_;
2244}
2245
[email protected]b172aee2012-04-10 17:05:262246int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272247 return maximum_zoom_percent_;
2248}
2249
[email protected]b172aee2012-04-10 17:05:262250gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492251 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232252}
2253
[email protected]b172aee2012-04-10 17:05:262254bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052255 if (GetBrowserPluginGuest())
2256 return GetBrowserPluginGuest()->LockMouse(allowed);
2257
[email protected]0bfbf882011-12-22 18:19:272258 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582259 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272260}
2261
[email protected]b172aee2012-04-10 17:05:262262bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442263 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502264}
2265
[email protected]cb805452013-05-22 15:16:212266void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482267 if (!color_chooser_info_.get())
2268 return;
2269 RenderFrameHost* rfh = RenderFrameHost::FromID(
2270 color_chooser_info_->render_process_id,
2271 color_chooser_info_->render_frame_id);
2272 if (!rfh)
2273 return;
2274
2275 rfh->Send(new FrameMsg_DidChooseColorResponse(
2276 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202277}
2278
[email protected]cb805452013-05-22 15:16:212279void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482280 if (!color_chooser_info_.get())
2281 return;
2282 RenderFrameHost* rfh = RenderFrameHost::FromID(
2283 color_chooser_info_->render_process_id,
2284 color_chooser_info_->render_frame_id);
2285 if (!rfh)
2286 return;
2287
2288 rfh->Send(new FrameMsg_DidEndColorChooser(
2289 rfh->GetRoutingID(), color_chooser_info_->identifier));
2290 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202291}
2292
[email protected]41225fe2013-03-29 05:32:022293int WebContentsImpl::DownloadImage(const GURL& url,
2294 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302295 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022296 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582297 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022298 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392299 return id;
2300}
2301
[email protected]5dcaf8e2013-12-28 01:31:422302bool WebContentsImpl::IsSubframe() const {
2303 return is_subframe_;
2304}
2305
[email protected]36ec24f2014-01-09 00:32:082306void WebContentsImpl::Find(int request_id,
2307 const base::string16& search_text,
2308 const blink::WebFindOptions& options) {
2309 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2310}
2311
2312void WebContentsImpl::StopFinding(StopFindAction action) {
2313 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2314}
2315
[email protected]4fe53add2014-04-08 19:53:362316void WebContentsImpl::InsertCSS(const std::string& css) {
2317 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2318 GetMainFrame()->GetRoutingID(), css));
2319}
2320
[email protected]b172aee2012-04-10 17:05:262321bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272322 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]8e09c7af2014-06-10 11:46:172323 if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332324 return true;
2325 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272326}
2327
[email protected]b172aee2012-04-10 17:05:262328void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272329 if (delegate_)
2330 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212331}
2332
[email protected]52913802013-12-10 05:52:182333void WebContentsImpl::DidStartProvisionalLoad(
2334 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072335 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182336 const GURL& validated_url,
2337 bool is_error_page,
2338 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262339 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]d974a0a2013-01-10 01:43:572340
[email protected]0d60f0192011-04-14 12:40:102341 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272342 int render_frame_id = render_frame_host->GetRoutingID();
2343 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252344 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072345 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272346 render_frame_id, parent_routing_id, is_main_frame,
2347 validated_url, is_error_page, is_iframe_srcdoc,
2348 render_view_host));
[email protected]400992b2012-06-14 00:03:542349
2350 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182351 FOR_EACH_OBSERVER(
2352 WebContentsObserver,
2353 observers_,
2354 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582355 render_frame_host));
[email protected]400992b2012-06-14 00:03:542356 }
2357}
2358
[email protected]3109fbb72014-01-06 23:57:152359void WebContentsImpl::DidFailProvisionalLoadWithError(
2360 RenderFrameHostImpl* render_frame_host,
2361 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2362 GURL validated_url(params.url);
[email protected]61ac9e242014-03-21 20:55:262363 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]860234a2014-07-01 00:35:312364 FOR_EACH_OBSERVER(WebContentsObserver,
2365 observers_,
2366 DidFailProvisionalLoad(render_frame_host,
2367 is_main_frame,
2368 validated_url,
2369 params.error_code,
2370 params.error_description));
[email protected]3109fbb72014-01-06 23:57:152371}
2372
[email protected]b80624c2014-02-09 02:46:552373void WebContentsImpl::DidFailLoadWithError(
2374 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552375 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552376 int error_code,
2377 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272378 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262379 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272380 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552381 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272382 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262383 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552384}
2385
[email protected]52913802013-12-10 05:52:182386void WebContentsImpl::NotifyChangedNavigationState(
2387 InvalidateTypes changed_flags) {
2388 NotifyNavigationStateChanged(changed_flags);
2389}
2390
[email protected]3691e5cf2014-01-22 10:16:202391void WebContentsImpl::AboutToNavigateRenderFrame(
2392 RenderFrameHostImpl* render_frame_host) {
2393 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272394 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202395 FOR_EACH_OBSERVER(
2396 WebContentsObserver,
2397 observers_,
[email protected]161eabd2014-03-19 19:47:272398 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202399}
2400
2401void WebContentsImpl::DidStartNavigationToPendingEntry(
2402 RenderFrameHostImpl* render_frame_host,
2403 const GURL& url,
2404 NavigationController::ReloadType reload_type) {
2405 // Notify observers about navigation.
2406 FOR_EACH_OBSERVER(
2407 WebContentsObserver,
2408 observers_,
2409 DidStartNavigationToPendingEntry(url, reload_type));
2410}
2411
[email protected]8cb834e2014-03-06 14:23:232412void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2413 const OpenURLParams& params) {
2414 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182415 WebContents* new_contents = OpenURL(params);
2416
2417 if (new_contents) {
2418 // Notify observers.
2419 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2420 DidOpenRequestedURL(new_contents,
2421 params.url,
2422 params.referrer,
2423 params.disposition,
2424 params.transition,
[email protected]8cb834e2014-03-06 14:23:232425 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182426 }
2427}
2428
[email protected]aa62afd2014-04-22 19:22:462429bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2430 if (!delegate_)
2431 return false;
2432 return delegate_->ShouldPreserveAbortedURLs(this);
2433}
2434
[email protected]400992b2012-06-14 00:03:542435void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582436 RenderFrameHostImpl* render_frame_host,
2437 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542438 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582439 FOR_EACH_OBSERVER(
2440 WebContentsObserver,
2441 observers_,
2442 ProvisionalChangeToMainFrameUrl(validated_target_url,
2443 render_frame_host));
[email protected]724159a2010-12-30 01:11:182444}
2445
[email protected]37567b432014-02-12 01:12:222446void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432447 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222448 bool is_main_frame,
2449 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432450 PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:222451 // Notify observers about the commit of the provisional load.
2452 FOR_EACH_OBSERVER(
2453 WebContentsObserver,
2454 observers_,
[email protected]860234a2014-07-01 00:35:312455 DidCommitProvisionalLoadForFrame(
2456 render_frame_host, is_main_frame, url, transition_type));
[email protected]37567b432014-02-12 01:12:222457}
2458
[email protected]0d0f4c492014-04-02 06:42:572459void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:232460 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:572461 // Ensure fullscreen mode is exited before committing the navigation to a
2462 // different page. The next page will not start out assuming it is in
2463 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:232464 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:192465 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572466 return;
2467 }
2468 if (IsFullscreenForCurrentTab())
2469 GetRenderViewHost()->ExitFullscreen();
2470 DCHECK(!IsFullscreenForCurrentTab());
2471}
2472
[email protected]37567b432014-02-12 01:12:222473void WebContentsImpl::DidNavigateMainFramePostCommit(
2474 const LoadCommittedDetails& details,
2475 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2476 if (details.is_navigation_to_different_page()) {
2477 // Clear the status bubble. This is a workaround for a bug where WebKit
2478 // doesn't let us know that the cursor left an element during a
2479 // transition (this is also why the mouse cursor remains as a hand after
2480 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2481 // clear the bubble when a user navigates to a named anchor in the same
2482 // page.
2483 UpdateTargetURL(details.entry->GetPageID(), GURL());
2484 }
2485
2486 if (!details.is_in_page) {
2487 // Once the main frame is navigated, we're no longer considered to have
2488 // displayed insecure content.
2489 displayed_insecure_content_ = false;
2490 SSLManager::NotifySSLInternalStateChanged(
2491 GetController().GetBrowserContext());
2492 }
2493
2494 // Notify observers about navigation.
2495 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2496 DidNavigateMainFrame(details, params));
2497
[email protected]e85165c642014-06-10 14:34:312498 if (delegate_)
[email protected]37567b432014-02-12 01:12:222499 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:312500 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:222501}
2502
2503void WebContentsImpl::DidNavigateAnyFramePostCommit(
2504 RenderFrameHostImpl* render_frame_host,
2505 const LoadCommittedDetails& details,
2506 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102507 // Now that something has committed, we don't need to track whether the
2508 // initial page has been accessed.
2509 has_accessed_initial_document_ = false;
2510
[email protected]37567b432014-02-12 01:12:222511 // If we navigate off the page, close all JavaScript dialogs.
2512 if (dialog_manager_ && !details.is_in_page)
2513 dialog_manager_->CancelActiveAndPendingDialogs(this);
2514
2515 // Notify observers about navigation.
2516 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2517 DidNavigateAnyFrame(details, params));
2518}
2519
2520void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2521 contents_mime_type_ = mime_type;
2522}
2523
[email protected]277857a2014-06-03 10:38:012524bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:312525 // Disable overscroll when touch emulation is on. See crbug.com/369938.
2526 if (touch_emulation_enabled_)
2527 return false;
2528
[email protected]37567b432014-02-12 01:12:222529 if (delegate_)
2530 return delegate_->CanOverscrollContent();
2531
2532 return false;
2533}
2534
[email protected]e7104762014-06-20 19:17:252535void WebContentsImpl::OnBrandColorChanged(SkColor brand_color) {
2536 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2537 DidChangeBrandColor(brand_color));
2538}
2539
[email protected]b172aee2012-04-10 17:05:262540void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182541 const GURL& url,
[email protected]70435962011-08-02 20:13:282542 const std::string& security_info,
2543 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182544 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282545 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192546 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182547 cache.Increment();
2548
2549 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082550 int cert_id = 0;
2551 net::CertStatus cert_status = 0;
2552 int security_bits = -1;
2553 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122554 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212555 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122556 &security_bits, &connection_status,
2557 &signed_certificate_timestamp_ids);
2558 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212559 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002560 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2561 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182562
[email protected]b0f724c2013-09-05 04:21:132563 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2564
2565 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2566 DidLoadResourceFromMemoryCache(details));
2567
[email protected]8bfc8272013-09-09 20:10:532568 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2569 scoped_refptr<net::URLRequestContextGetter> request_context(
2570 resource_type == ResourceType::MEDIA ?
2571 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2572 GetRenderProcessHost()->GetID()) :
2573 GetBrowserContext()->GetRequestContextForRenderProcess(
2574 GetRenderProcessHost()->GetID()));
2575 BrowserThread::PostTask(
2576 BrowserThread::IO,
2577 FROM_HERE,
2578 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2579 }
[email protected]724159a2010-12-30 01:11:182580}
2581
[email protected]b172aee2012-04-10 17:05:262582void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392583 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182584 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192585 SSLManager::NotifySSLInternalStateChanged(
2586 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182587}
2588
[email protected]b172aee2012-04-10 17:05:262589void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022590 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582591 LOG(WARNING) << security_origin << " ran insecure content from "
2592 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392593 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412594 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392595 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182596 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412597 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192598 SSLManager::NotifySSLInternalStateChanged(
2599 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182600}
2601
[email protected]501052ff2014-02-21 22:19:072602void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572603 CHECK(render_frame_message_source_);
2604 CHECK(!render_view_message_source_);
2605 RenderFrameHostImpl* rfh =
2606 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2607
[email protected]161eabd2014-03-19 19:47:272608 int render_frame_id = rfh->GetRoutingID();
2609 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572610 FOR_EACH_OBSERVER(WebContentsObserver,
2611 observers_,
[email protected]161eabd2014-03-19 19:47:272612 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182613}
2614
[email protected]b172aee2012-04-10 17:05:262615void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262616 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372617 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122618 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2619 GetRenderProcessHost()->ReceivedBadMessage();
2620 return;
2621 }
[email protected]a1b99262013-12-27 21:56:222622
[email protected]8b3af1e2014-01-24 13:29:122623 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442624 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372625 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422626 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372627
[email protected]61ac9e242014-03-21 20:55:262628 RenderFrameHostImpl* rfh =
2629 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272630 int render_frame_id = rfh->GetRoutingID();
2631 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262632 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252633 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272634 DidFinishLoad(render_frame_id, validated_url,
2635 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312636}
2637
[email protected]960b0372014-05-19 18:01:002638void WebContentsImpl::OnDidStartLoading(bool to_different_document) {
2639 RenderFrameHostImpl* rfh =
2640 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2641 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2642
2643 // It is possible to get multiple calls to OnDidStartLoading that don't have
2644 // corresponding calls to OnDidStopLoading:
2645 // - With "swappedout://" URLs, this happens when a RenderView gets swapped
2646 // out for a cross-process navigation, and it turns into a placeholder for
2647 // one being rendered in a different process.
2648 // - Also, there might be more than one RenderFrameHost sharing the same
2649 // FrameTreeNode (and thus sharing its ID) each sending a start.
2650 // - But in the future, once clamy@ moves navigation network requests to the
2651 // browser process, there's a good chance that callbacks about starting and
2652 // stopping will all be handled by the browser. When that happens, there
2653 // should no longer be a start/stop call imbalance. TODO(avi): When this
2654 // future arrives, update this code to not allow this case.
2655 DCHECK_GE(loading_frames_in_progress_, 0);
2656 if (loading_progresses_.find(render_frame_id) == loading_progresses_.end()) {
2657 if (loading_frames_in_progress_ == 0)
2658 DidStartLoading(rfh, to_different_document);
2659 ++loading_frames_in_progress_;
2660 }
2661
2662 loading_progresses_[render_frame_id] = kMinimumLoadingProgress;
2663 SendLoadProgressChanged();
2664}
2665
2666void WebContentsImpl::OnDidStopLoading() {
2667 RenderFrameHostImpl* rfh =
2668 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2669 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2670
2671 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) {
2672 // Load stopped while we were still tracking load. Make sure we update
2673 // progress based on this frame's completion.
2674 loading_progresses_[render_frame_id] = 1.0;
2675 SendLoadProgressChanged();
2676 // Then we clean-up our states.
2677 if (loading_total_progress_ == 1.0)
2678 ResetLoadProgressState();
2679 }
2680
2681 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes
2682 // calls DidStopLoading() without a matching DidStartLoading().
2683 if (loading_frames_in_progress_ == 0)
2684 return;
2685 --loading_frames_in_progress_;
2686 if (loading_frames_in_progress_ == 0)
2687 DidStopLoading(rfh);
2688}
2689
2690void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) {
2691 RenderFrameHostImpl* rfh =
2692 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2693 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id();
2694
2695 loading_progresses_[render_frame_id] = load_progress;
2696
2697 // We notify progress change immediately for the first and last updates.
2698 // Also, since the message loop may be pretty busy when a page is loaded, it
2699 // might not execute a posted task in a timely manner so we make sure to
2700 // immediately send progress report if enough time has passed.
2701 base::TimeDelta min_delay =
2702 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
2703 if (load_progress == 1.0 || loading_last_progress_update_.is_null() ||
2704 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay) {
2705 // If there is a pending task to send progress, it is now obsolete.
2706 loading_weak_factory_.InvalidateWeakPtrs();
2707 SendLoadProgressChanged();
2708 if (loading_total_progress_ == 1.0)
2709 ResetLoadProgressState();
2710 return;
2711 }
2712
2713 if (loading_weak_factory_.HasWeakPtrs())
2714 return;
2715
2716 base::MessageLoop::current()->PostDelayedTask(
2717 FROM_HERE,
2718 base::Bind(&WebContentsImpl::SendLoadProgressChanged,
2719 loading_weak_factory_.GetWeakPtr()),
2720 min_delay);
2721}
2722
[email protected]b172aee2012-04-10 17:05:262723void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222724 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2725 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262726}
2727
[email protected]b172aee2012-04-10 17:05:262728void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:302729 int maximum_percent) {
[email protected]216813952011-05-19 22:21:262730 minimum_zoom_percent_ = minimum_percent;
2731 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:262732}
2733
[email protected]b172aee2012-04-10 17:05:262734void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342735 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432736 if (!delegate_)
2737 return;
2738
[email protected]b9535422012-02-09 01:47:592739 ChildProcessSecurityPolicyImpl* policy =
2740 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222741 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592742 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212743}
2744
[email protected]b172aee2012-04-10 17:05:262745void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2746 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262747 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362748 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432749 if (!delegate_)
2750 return;
2751
[email protected]b9535422012-02-09 01:47:592752 ChildProcessSecurityPolicyImpl* policy =
2753 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322754 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592755 return;
[email protected]8f810632013-06-06 22:33:322756
[email protected]c125e532014-05-10 20:39:062757 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202758}
2759
[email protected]b172aee2012-04-10 17:05:262760void WebContentsImpl::OnFindReply(int request_id,
2761 int number_of_matches,
2762 const gfx::Rect& selection_rect,
2763 int active_match_ordinal,
2764 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432765 if (delegate_) {
2766 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2767 active_match_ordinal, final_update);
2768 }
[email protected]b888919c2011-09-02 00:32:162769}
2770
[email protected]59363fc92012-09-05 03:46:312771#if defined(OS_ANDROID)
2772void WebContentsImpl::OnFindMatchRectsReply(
2773 int version,
2774 const std::vector<gfx::RectF>& rects,
2775 const gfx::RectF& active_rect) {
2776 if (delegate_)
2777 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2778}
[email protected]583418cc2013-01-17 14:01:102779
[email protected]1ff427972013-02-07 21:14:072780void WebContentsImpl::OnOpenDateTimeDialog(
2781 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092782 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2783 GetRenderViewHost(),
2784 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132785 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092786 value.minimum,
2787 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172788 value.step,
2789 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102790}
2791
[email protected]59363fc92012-09-05 03:46:312792#endif
2793
[email protected]f114fa42013-12-06 17:06:442794void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2795 const base::FilePath& path,
2796 bool is_hung) {
2797 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2798
2799 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2800 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2801}
2802
2803void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422804 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442805 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422806 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452807}
2808
[email protected]cfa856d62014-02-22 07:58:402809void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2810 int automation_id) {
2811 DomOperationNotificationDetails details(json_string, automation_id);
2812 NotificationService::current()->Notify(
2813 NOTIFICATION_DOM_OPERATION_RESPONSE,
2814 Source<WebContents>(this),
2815 Details<DomOperationNotificationDetails>(&details));
2816}
2817
[email protected]b172aee2012-04-10 17:05:262818void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2819 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102820 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252821 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102822 AppCacheAccessed(manifest_url, blocked_by_policy));
2823}
2824
[email protected]8bc5ff02013-11-29 06:34:032825void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482826 int color_chooser_id,
2827 SkColor color,
2828 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462829 ColorChooser* new_color_chooser = delegate_ ?
2830 delegate_->OpenColorChooser(this, color, suggestions) :
2831 NULL;
[email protected]820957a2014-01-14 14:56:302832 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212833 return;
[email protected]8ed16472014-04-11 19:02:482834 if (color_chooser_info_.get())
2835 color_chooser_info_->chooser->End();
2836
2837 color_chooser_info_.reset(new ColorChooserInfo(
2838 render_frame_message_source_->GetProcess()->GetID(),
2839 render_frame_message_source_->GetRoutingID(),
2840 new_color_chooser,
2841 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202842}
2843
[email protected]b172aee2012-04-10 17:05:262844void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482845 if (color_chooser_info_ &&
2846 color_chooser_id == color_chooser_info_->identifier)
2847 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202848}
2849
[email protected]b172aee2012-04-10 17:05:262850void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322851 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482852 if (color_chooser_info_ &&
2853 color_chooser_id == color_chooser_info_->identifier)
2854 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202855}
2856
[email protected]d0759f492012-04-19 22:50:502857// This exists for render views that don't have a WebUI, but do have WebUI
2858// bindings enabled.
2859void WebContentsImpl::OnWebUISend(const GURL& source_url,
2860 const std::string& name,
2861 const base::ListValue& args) {
2862 if (delegate_)
2863 delegate_->WebUISend(this, source_url, name, args);
2864}
2865
[email protected]d8415ad92012-08-23 14:40:502866void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442867 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502868 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342869 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162870 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442871 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162872 return;
[email protected]d8415ad92012-08-23 14:40:502873 }
2874
[email protected]8c8fc292012-11-23 18:57:162875 if (!delegate_->RequestPpapiBrokerPermission(
2876 this, url, plugin_path,
2877 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442878 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162879 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442880 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162881 }
[email protected]d8415ad92012-08-23 14:40:502882}
2883
[email protected]ea0309c2013-08-06 19:35:442884void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502885 bool result) {
[email protected]ea0309c2013-08-06 19:35:442886 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502887}
2888
[email protected]c4538072013-03-18 02:17:552889void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372890 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082891 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552892 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392893 // For more info, see comment above classes BrowserPluginEmbedder and
2894 // BrowserPluginGuest.
2895 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142896 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082897 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372898}
2899
[email protected]41225fe2013-03-29 05:32:022900void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392901 int id,
[email protected]749fadd2013-05-15 08:37:482902 int http_status_code,
[email protected]795c28972012-12-06 06:13:392903 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302904 const std::vector<SkBitmap>& bitmaps,
2905 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132906 if (bitmaps.size() != original_bitmap_sizes.size())
2907 return;
2908
[email protected]41225fe2013-03-29 05:32:022909 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2910 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392911 // Currently WebContents notifies us of ANY downloads so that it is
2912 // possible to get here.
2913 return;
2914 }
2915 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302916 iter->second.Run(
2917 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392918 }
[email protected]41225fe2013-03-29 05:32:022919 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392920}
2921
2922void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392923 const std::vector<FaviconURL>& candidates) {
2924 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292925 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392926}
2927
[email protected]1dd0bb752014-02-01 01:16:262928void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2929 bool has_video,
2930 bool has_audio) {
2931// Chrome OS does its own detection of audio and video.
2932#if !defined(OS_CHROMEOS)
2933 scoped_ptr<PowerSaveBlocker> blocker;
2934 if (has_video) {
2935 blocker = PowerSaveBlocker::Create(
2936 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2937#if defined(OS_ANDROID)
2938 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2939 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2940#endif
2941 } else if (has_audio) {
2942 blocker = PowerSaveBlocker::Create(
2943 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2944 }
2945
2946 if (blocker) {
[email protected]96307312014-05-04 01:00:192947 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262948 blocker.release();
2949 }
2950#endif // !defined(OS_CHROMEOS)
2951}
2952
2953void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062954 // Chrome OS does its own detection of audio and video.
2955#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192956 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2957 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062958#endif // !defined(OS_CHROMEOS)
2959}
2960
[email protected]50279492014-05-05 23:24:292961void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152962 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292963 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152964}
[email protected]d9030b82013-07-19 08:26:062965
[email protected]e67ebf32013-02-13 11:07:192966void WebContentsImpl::DidChangeVisibleSSLState() {
[email protected]25af6ec2014-06-06 19:35:072967 if (delegate_)
2968 delegate_->VisibleSSLStateChanged(this);
[email protected]e67ebf32013-02-13 11:07:192969}
2970
[email protected]17e286e2013-03-01 23:29:392971void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2972 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2973 BeforeFormRepostWarningShow());
2974}
2975
[email protected]ec6c05f2013-10-23 18:41:572976
2977void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2978 Activate();
2979 if (delegate_)
2980 delegate_->ShowRepostFormWarningDialog(this);
2981}
2982
[email protected]b4c84012014-04-28 19:51:102983bool WebContentsImpl::HasAccessedInitialDocument() {
2984 return has_accessed_initial_document_;
2985}
2986
[email protected]96d185d2009-04-24 03:28:542987// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592988// loading, or done loading.
2989void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2990 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092991 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262992 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542993 if (is_loading == is_loading_)
2994 return;
2995
2996 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262997 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2998 base::string16());
[email protected]96d185d2009-04-24 03:28:542999 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:563000 upload_size_ = 0;
3001 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:543002 }
3003
[email protected]fa944cb82013-11-15 17:51:213004 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:543005
3006 is_loading_ = is_loading;
3007 waiting_for_response_ = is_loading;
[email protected]6dfed692014-05-22 04:18:033008 is_load_to_different_document_ = to_different_document;
[email protected]96d185d2009-04-24 03:28:543009
[email protected]6ebdc9b2010-09-27 16:55:573010 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:093011 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:213012 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:543013
[email protected]eab61442013-11-14 18:35:483014 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:593015 if (is_loading) {
[email protected]eab61442013-11-14 18:35:483016 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
3017 "URL", url);
[email protected]91621872013-10-08 04:04:593018 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3019 DidStartLoading(render_view_host));
3020 } else {
[email protected]eab61442013-11-14 18:35:483021 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
3022 "URL", url);
[email protected]91621872013-10-08 04:04:593023 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3024 DidStopLoading(render_view_host));
3025 }
[email protected]66798902013-10-01 18:40:163026
3027 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213028 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3029 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:543030 if (details)
[email protected]8ff00d72012-10-23 19:12:213031 det = Details<LoadNotificationDetails>(details);
3032 NotificationService::current()->Notify(
3033 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:543034}
3035
[email protected]959be4c2014-04-08 15:01:333036void WebContentsImpl::SelectRange(const gfx::Point& start,
3037 const gfx::Point& end) {
3038 RenderFrameHost* focused_frame = GetFocusedFrame();
3039 if (!focused_frame)
3040 return;
3041
3042 focused_frame->Send(
3043 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
3044}
3045
[email protected]b172aee2012-04-10 17:05:263046void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463047 // If we are creating a RVH for a restored controller, then we need to make
3048 // sure the RenderView starts with a next_page_id_ larger than the number
3049 // of restored entries. This must be called before the RenderView starts
3050 // navigating (to avoid a race between the browser updating max_page_id and
3051 // the renderer updating next_page_id_). Because of this, we only call this
3052 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563053 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583054 if (max_restored_page_id >
3055 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3056 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3057 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323058}
3059
[email protected]b172aee2012-04-10 17:05:263060bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263061 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323062 // For file URLs without a title, use the pathname instead. In the case of a
3063 // synthesized title, we don't want the update to count toward the "one set
3064 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263065 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323066 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513067 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243068 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323069 explicit_set = false; // Don't count synthetic titles toward the set limit.
3070 } else {
[email protected]8af69c6c2014-03-03 19:05:313071 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323072 explicit_set = true;
3073 }
3074
[email protected]987fc3a2011-05-26 14:18:093075 // If a page is created via window.open and never navigated,
3076 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553077 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093078 if (entry) {
[email protected]36fc0392011-12-25 03:59:513079 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093080 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323081
[email protected]36fc0392011-12-25 03:59:513082 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093083 } else {
3084 if (page_title_when_no_navigation_entry_ == final_title)
3085 return false; // Nothing changed, don't bother.
3086
3087 page_title_when_no_navigation_entry_ = final_title;
3088 }
[email protected]420ae012009-04-24 05:16:323089
[email protected]420ae012009-04-24 05:16:323090 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233091 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323092
[email protected]66798902013-10-01 18:40:163093 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533094 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163095
3096 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213097 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463098 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213099 NotificationService::current()->Notify(
3100 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3101 Source<WebContents>(this),
3102 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043103
[email protected]420ae012009-04-24 05:16:323104 return true;
3105}
3106
[email protected]960b0372014-05-19 18:01:003107void WebContentsImpl::SendLoadProgressChanged() {
3108 loading_last_progress_update_ = base::TimeTicks::Now();
3109 double progress = 0.0;
3110 int frame_count = 0;
3111
3112 for (LoadingProgressMap::iterator it = loading_progresses_.begin();
3113 it != loading_progresses_.end();
3114 ++it) {
3115 progress += it->second;
3116 ++frame_count;
3117 }
3118 if (frame_count == 0)
3119 return;
3120 progress /= frame_count;
3121 DCHECK(progress <= 1.0);
3122
3123 if (progress <= loading_total_progress_)
3124 return;
3125 loading_total_progress_ = progress;
3126
3127 if (delegate_)
3128 delegate_->LoadProgressChanged(this, progress);
3129}
3130
3131void WebContentsImpl::ResetLoadProgressState() {
3132 loading_progresses_.clear();
3133 loading_total_progress_ = 0.0;
3134 loading_weak_factory_.InvalidateWeakPtrs();
3135 loading_last_progress_update_ = base::TimeTicks();
3136}
3137
[email protected]02d7b6e2014-06-24 21:01:503138void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3139 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323140 // After sending out a swap notification, we need to send a disconnect
3141 // notification so that clients that pick up a pointer to |this| can NULL the
3142 // pointer. See Bug 1230284.
3143 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113144 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283145 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113146
3147 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283148 std::pair<RenderViewHost*, RenderViewHost*> details =
3149 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213150 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283151 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213152 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283153 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393154
3155 // Ensure that the associated embedder gets cleared after a RenderViewHost
3156 // gets swapped, so we don't reuse the same embedder next time a
3157 // RenderViewHost is attached to this WebContents.
3158 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323159}
3160
[email protected]02d7b6e2014-06-24 21:01:503161void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3162 RenderFrameHost* new_host) {
3163 FOR_EACH_OBSERVER(WebContentsObserver,
3164 observers_,
3165 RenderFrameHostChanged(old_host, new_host));
3166}
3167
[email protected]da7a7182013-09-06 08:11:113168// TODO(avi): Remove this entire function because this notification is already
3169// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263170void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323171 if (!notify_disconnection_)
3172 return;
3173
3174 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213175 NotificationService::current()->Notify(
3176 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3177 Source<WebContents>(this),
3178 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323179}
3180
[email protected]cbb1ef592013-06-05 19:49:463181void WebContentsImpl::NotifyNavigationEntryCommitted(
3182 const LoadCommittedDetails& load_details) {
3183 FOR_EACH_OBSERVER(
3184 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3185}
3186
[email protected]f114fa42013-12-06 17:06:443187bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3188 const IPC::Message& message) {
3189 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313190}
3191
[email protected]c31a84802014-04-03 15:55:493192const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3193 return GetLastCommittedURL();
3194}
3195
[email protected]b849847b2013-12-10 21:57:583196void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3197 // Note this is only for subframes, the notification for the main frame
3198 // happens in RenderViewCreated.
3199 FOR_EACH_OBSERVER(WebContentsObserver,
3200 observers_,
3201 RenderFrameCreated(render_frame_host));
3202}
3203
3204void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193205 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583206 FOR_EACH_OBSERVER(WebContentsObserver,
3207 observers_,
3208 RenderFrameDeleted(render_frame_host));
3209}
3210
[email protected]a09d53ce2014-01-31 00:46:423211void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303212 if (delegate_)
3213 delegate_->WorkerCrashed(this);
3214}
3215
[email protected]a09d53ce2014-01-31 00:46:423216void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3217 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103218 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423219 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103220 if (GetBrowserPluginGuest()) {
3221 WebContentsViewGuest* view_guest =
3222 static_cast<WebContentsViewGuest*>(GetView());
3223 context_menu_params = view_guest->ConvertContextMenuParams(params);
3224 }
3225 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423226 return;
3227
[email protected]077e704b2014-05-23 19:24:103228 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3229 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423230}
3231
[email protected]87de04b02014-04-08 22:14:493232void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013233 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493234 const base::string16& message,
3235 const base::string16& default_prompt,
3236 const GURL& frame_url,
3237 JavaScriptMessageType javascript_message_type,
3238 IPC::Message* reply_msg) {
3239 // Suppress JavaScript dialogs when requested. Also suppress messages when
3240 // showing an interstitial as it's shown over the previous page and we don't
3241 // want the hidden page's dialogs to interfere with the interstitial.
3242 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013243 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493244 IsSwappedOut() ||
3245 ShowingInterstitialPage() ||
3246 !delegate_ ||
3247 delegate_->ShouldSuppressDialogs() ||
3248 !delegate_->GetJavaScriptDialogManager();
3249
3250 if (!suppress_this_message) {
3251 std::string accept_lang = GetContentClient()->browser()->
3252 GetAcceptLangs(GetBrowserContext());
3253 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3254 dialog_manager_->RunJavaScriptDialog(
3255 this,
3256 frame_url.GetOrigin(),
3257 accept_lang,
3258 javascript_message_type,
3259 message,
3260 default_prompt,
3261 base::Bind(&WebContentsImpl::OnDialogClosed,
3262 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013263 render_frame_host->GetProcess()->GetID(),
3264 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493265 reply_msg,
3266 false),
3267 &suppress_this_message);
3268 }
3269
3270 if (suppress_this_message) {
3271 // If we are suppressing messages, just reply as if the user immediately
3272 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013273 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3274 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283275 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493276 }
3277
3278 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3279 // http://crbug.com/288961 ). The only safe thing to do here is return.
3280}
3281
3282void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013283 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493284 const base::string16& message,
3285 bool is_reload,
3286 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013287 RenderFrameHostImpl* rfhi =
3288 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493289 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013290 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493291 if (delegate_)
3292 delegate_->WillRunBeforeUnloadConfirm();
3293
3294 bool suppress_this_message =
3295 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3296 !delegate_ ||
3297 delegate_->ShouldSuppressDialogs() ||
3298 !delegate_->GetJavaScriptDialogManager();
3299 if (suppress_this_message) {
3300 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3301 return;
3302 }
3303
3304 is_showing_before_unload_dialog_ = true;
3305 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3306 dialog_manager_->RunBeforeUnloadDialog(
3307 this, message, is_reload,
3308 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013309 render_frame_host->GetProcess()->GetID(),
3310 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283311 false));
[email protected]87de04b02014-04-08 22:14:493312}
3313
[email protected]a86c0e962013-12-17 17:10:393314WebContents* WebContentsImpl::GetAsWebContents() {
3315 return this;
3316}
3317
[email protected]7912e822014-04-16 02:37:033318bool WebContentsImpl::IsNeverVisible() {
3319 if (!delegate_)
3320 return false;
3321 return delegate_->IsNeverVisible(this);
3322}
3323
[email protected]5a3bdf52012-05-24 15:12:573324RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3325 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323326}
3327
[email protected]8ff00d72012-10-23 19:12:213328RendererPreferences WebContentsImpl::GetRendererPrefs(
3329 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463330 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513331}
3332
[email protected]b172aee2012-04-10 17:05:263333gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173334 if (delegate_)
3335 return delegate_->GetRootWindowResizerRect();
3336 return gfx::Rect();
3337}
3338
[email protected]7a846df2012-09-20 19:17:393339void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273340 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393341 browser_plugin_embedder_.reset();
3342}
3343
[email protected]b172aee2012-04-10 17:05:263344void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443345 // Don't send notifications if we are just creating a swapped-out RVH for
3346 // the opener chain. These won't be used for view-source or WebUI, so it's
3347 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243348 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443349 return;
3350
[email protected]86f98a22013-03-20 14:35:003351 if (delegate_)
[email protected]e85165c642014-06-10 14:34:313352 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083353
[email protected]8ff00d72012-10-23 19:12:213354 NotificationService::current()->Notify(
3355 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3356 Source<WebContents>(this),
3357 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323358
3359 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353360 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213361 if (GetRenderManager()->pending_web_ui())
3362 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323363
[email protected]6286a372013-10-09 04:03:273364 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333365 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323366 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183367 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583368 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323369 }
[email protected]0666aef2009-05-13 19:48:083370
[email protected]60780f412013-02-25 16:34:103371 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263372
3373 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253374 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583375
3376 // We tell the observers now instead of when the main RenderFrameHostImpl is
3377 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3378 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363379 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583380 FOR_EACH_OBSERVER(
3381 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323382}
3383
[email protected]b172aee2012-04-10 17:05:263384void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523385 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323386 // Don't notify the world, since this came from a renderer in the
3387 // background.
3388 return;
3389 }
3390
[email protected]da7a7182013-09-06 08:11:113391 notify_disconnection_ = true;
3392 // TODO(avi): Remove. http://crbug.com/170921
3393 NotificationService::current()->Notify(
3394 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3395 Source<WebContents>(this),
3396 NotificationService::NoDetails());
3397
[email protected]be1f56ab2011-12-22 06:55:313398 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233399 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303400
3401 // Restore the focus to the tab (otherwise the focus will be on the top
3402 // window).
[email protected]484ae5912010-09-29 19:16:143403 if (was_crashed && !FocusLocationBarByDefault() &&
3404 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063405 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143406 }
[email protected]32ded2212011-11-10 18:51:433407
[email protected]d8c660432011-12-22 20:51:253408 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323409}
3410
[email protected]ec6a7eb2013-04-22 17:34:223411void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3412 base::TerminationStatus status,
3413 int error_code) {
[email protected]151a63d2011-12-20 22:32:523414 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323415 // The pending page's RenderViewHost is gone.
3416 return;
3417 }
3418
[email protected]2fcdcc32014-03-05 02:14:073419 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3420 // renderer may not have made a clean exit.
3421 if (IsFullscreenForCurrentTab())
3422 ToggleFullscreenMode(false);
3423
[email protected]698191dc2014-02-25 01:06:133424 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3425 if (dialog_manager_)
3426 dialog_manager_->CancelActiveAndPendingDialogs(this);
3427
[email protected]e3b10d12014-03-28 16:06:093428 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323429 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233430 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453431
[email protected]960b0372014-05-19 18:01:003432 // Reset the loading progress. TODO(avi): What does it mean to have a
3433 // "renderer crash" when there is more than one renderer process serving a
3434 // webpage? Once this function is called at a more granular frame level, we
3435 // probably will need to more granularly reset the state here.
3436 ResetLoadProgressState();
3437 loading_frames_in_progress_ = 0;
3438
[email protected]d8c660432011-12-22 20:51:253439 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273440 observers_,
[email protected]58d5cfe2013-07-10 02:40:523441 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323442}
3443
[email protected]b172aee2012-04-10 17:05:263444void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253445 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063446}
3447
[email protected]b172aee2012-04-10 17:05:263448void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3449 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043450 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153451 // Ensure that this state update comes from either the active RVH or one of
3452 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413453 // TODO(nasko): This should go through RenderFrameHost.
3454 // TODO(creis): We can't update state for cross-process subframes until we
3455 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3456 if (rvh != GetRenderViewHost() &&
3457 !GetRenderManager()->IsRVHOnSwappedOutList(
3458 static_cast<RenderViewHostImpl*>(rvh)))
3459 return;
[email protected]420ae012009-04-24 05:16:323460
3461 // We must be prepared to handle state updates for any page, these occur
3462 // when the user is scrolling and entering form data, as well as when we're
3463 // leaving a page, in which case our state may have already been moved to
3464 // the next page. The navigation controller will look up the appropriate
3465 // NavigationEntry and update it when it is notified via the delegate.
3466
3467 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583468 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323469 if (entry_index < 0)
3470 return;
[email protected]10f417c52011-12-28 21:04:233471 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323472
[email protected]691aa2f2013-05-28 22:52:043473 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323474 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043475 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323476 controller_.NotifyEntryChanged(entry, entry_index);
3477}
3478
[email protected]b172aee2012-04-10 17:05:263479void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513480 if (delegate_)
3481 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323482}
3483
[email protected]b172aee2012-04-10 17:05:263484void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103485#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293486 // The UI may be in an event-tracking loop, such as between the
3487 // mouse-down and mouse-up in text selection or a button click.
3488 // Defer the close until after tracking is complete, so that we
3489 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293490 // TODO(shess): This could get more fine-grained. For instance,
3491 // closing a tab in another window while selecting text in the
3492 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103493 if (view_->IsEventTracking()) {
3494 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293495 return;
3496 }
[email protected]60780f412013-02-25 16:34:103497#endif
[email protected]07707302009-11-06 00:50:293498
[email protected]420ae012009-04-24 05:16:323499 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523500 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513501 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323502}
3503
[email protected]66bbadaf2014-03-28 16:25:543504void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573505 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3506 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573507}
3508
[email protected]23f41fd2014-06-21 05:29:173509void WebContentsImpl::DidDeferAfterResponseStarted() {
3510#if defined(OS_ANDROID)
3511 ContentViewCoreImpl::FromWebContents(this)->DidDeferAfterResponseStarted();
3512#endif
3513}
3514
3515bool WebContentsImpl::WillHandleDeferAfterResponseStarted() {
3516#if defined(OS_ANDROID)
3517 return ContentViewCoreImpl::FromWebContents(this)->
3518 WillHandleDeferAfterResponseStarted();
3519#else
3520 return false;
3521#endif
3522}
3523
[email protected]b172aee2012-04-10 17:05:263524void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513525 if (delegate_ && delegate_->IsPopupOrPanel(this))
3526 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323527}
3528
[email protected]e3b10d12014-03-28 16:06:093529void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3530 bool to_different_document) {
3531 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3532 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323533}
3534
[email protected]723971b2014-02-12 11:08:253535void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323536 scoped_ptr<LoadNotificationDetails> details;
3537
[email protected]9595fd82013-04-19 21:28:493538 // Use the last committed entry rather than the active one, in case a
3539 // pending entry has been created.
3540 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203541 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493542
[email protected]420ae012009-04-24 05:16:323543 // An entry may not exist for a stop when loading an initial blank page or
3544 // if an iframe injected by script into a blank page finishes loading.
3545 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203546 base::TimeDelta elapsed =
3547 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323548
3549 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513550 entry->GetVirtualURL(),
3551 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323552 elapsed,
3553 &controller_,
3554 controller_.GetCurrentEntryIndex()));
3555 }
3556
[email protected]e3b10d12014-03-28 16:06:093557 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3558 details.get());
[email protected]420ae012009-04-24 05:16:323559}
3560
[email protected]b172aee2012-04-10 17:05:263561void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163562 controller_.DiscardNonCommittedEntries();
3563
3564 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213565 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163566}
3567
[email protected]59167c22013-06-03 18:07:323568void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103569 has_accessed_initial_document_ = true;
3570
[email protected]d1371bf8e2014-04-19 03:26:243571 // We may have left a failed browser-initiated navigation in the address bar
3572 // to let the user edit it and try again. Clear it now that content might
3573 // show up underneath it.
3574 if (!IsLoading() && controller_.GetPendingEntry())
3575 controller_.DiscardPendingEntry();
3576
[email protected]59167c22013-06-03 18:07:323577 // Update the URL display.
3578 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3579}
3580
[email protected]3f19f1a2014-05-02 05:23:273581void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3582 if (opener_) {
3583 // Clear our opener so that future cross-process navigations don't have an
3584 // opener assigned.
3585 RemoveDestructionObserver(opener_);
3586 opener_ = NULL;
3587 }
3588
3589 // Notify all swapped out RenderViewHosts for this tab. This is important
3590 // in case we go back to them, or if another window in those processes tries
3591 // to access window.opener.
3592 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3593}
3594
[email protected]39f2f9252014-05-03 00:54:013595void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293596 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093597 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293598 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093599
3600 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213601 NotificationService::current()->Notify(
3602 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3603 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293604 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083605}
3606
[email protected]ef3adfc2014-05-11 00:04:543607void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3608 int32 page_id,
3609 const base::string16& title,
3610 base::i18n::TextDirection title_direction) {
3611 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3612
3613 // If we have a title, that's a pretty good indication that we've started
3614 // getting useful data.
3615 SetNotWaitingForResponse();
3616
3617 // Try to find the navigation entry, which might not be the current one.
3618 // For example, it might be from a pending RVH for the pending entry.
3619 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3620 rvh->GetSiteInstance(), page_id);
3621
3622 // We can handle title updates when we don't have an entry in
3623 // UpdateTitleForEntry, but only if the update is from the current RVH.
3624 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3625 if (!entry && rvh != GetRenderViewHost())
3626 return;
3627
3628 // TODO(evan): make use of title_direction.
3629 // http://code.google.com/p/chromium/issues/detail?id=27094
3630 if (!UpdateTitleForEntry(entry, title))
3631 return;
3632
3633 // Broadcast notifications when the UI should be updated.
3634 if (entry == controller_.GetEntryAtOffset(0))
3635 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3636}
3637
3638void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3639 const std::string& encoding) {
3640 SetEncoding(encoding);
3641}
3642
[email protected]39f2f9252014-05-03 00:54:013643void WebContentsImpl::DocumentAvailableInMainFrame(
3644 RenderViewHost* render_view_host) {
3645 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3646 DocumentAvailableInMainFrame());
3647}
[email protected]e1c3a552012-05-04 20:51:323648void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3649 // Tell the active RenderViewHost to run unload handlers and close, as long
3650 // as the request came from a RenderViewHost in the same BrowsingInstance.
3651 // In most cases, we receive this from a swapped out RenderViewHost.
3652 // It is possible to receive it from one that has just been swapped in,
3653 // in which case we might as well deliver the message anyway.
3654 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3655 GetRenderViewHost()->ClosePage();
3656}
3657
[email protected]f546640b2012-05-15 00:03:493658void WebContentsImpl::RouteMessageEvent(
3659 RenderViewHost* rvh,
3660 const ViewMsg_PostMessage_Params& params) {
3661 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363662 // came from a RenderViewHost in the same BrowsingInstance or if this
3663 // WebContents is dedicated to a browser plugin guest.
3664 // Note: This check means that an embedder could theoretically receive a
3665 // postMessage from anyone (not just its own guests). However, this is
3666 // probably not a risk for apps since other pages won't have references
3667 // to App windows.
3668 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3669 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493670 return;
3671
3672 ViewMsg_PostMessage_Params new_params(params);
3673
[email protected]0bc7f3542013-10-21 15:05:533674 if (!params.message_port_ids.empty()) {
3675 MessagePortMessageFilter* message_port_message_filter =
3676 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3677 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093678 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3679 params.message_port_ids,
3680 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533681 }
3682
[email protected]f546640b2012-05-15 00:03:493683 // If there is a source_routing_id, translate it to the routing ID for
3684 // the equivalent swapped out RVH in the target process. If we need
3685 // to create a swapped out RVH for the source tab, we create its opener
3686 // chain as well, since those will also be accessible to the target page.
3687 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3688 // Try to look up the WebContents for the source page.
3689 WebContentsImpl* source_contents = NULL;
3690 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3691 rvh->GetProcess()->GetID(), params.source_routing_id);
3692 if (source_rvh) {
3693 source_contents = static_cast<WebContentsImpl*>(
3694 source_rvh->GetDelegate()->GetAsWebContents());
3695 }
3696
3697 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363698 if (GetBrowserPluginGuest()) {
3699 // We create a swapped out RenderView for the embedder in the guest's
3700 // render process but we intentionally do not expose the embedder's
3701 // opener chain to it.
3702 new_params.source_routing_id =
3703 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3704 } else {
3705 new_params.source_routing_id =
3706 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3707 }
[email protected]f546640b2012-05-15 00:03:493708 } else {
3709 // We couldn't find it, so don't pass a source frame.
3710 new_params.source_routing_id = MSG_ROUTING_NONE;
3711 }
3712 }
3713
3714 // In most cases, we receive this from a swapped out RenderViewHost.
3715 // It is possible to receive it from one that has just been swapped in,
3716 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183717 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493718}
3719
[email protected]a796f202012-05-30 14:14:253720bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263721 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253722 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263723 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253724 if (!delegate_)
3725 return false;
3726 return delegate_->AddMessageToConsole(this, level, message, line_no,
3727 source_id);
3728}
3729
[email protected]b172aee2012-04-10 17:05:263730WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273731 // We want to base the page config off of the actual URL, rather than the
3732 // virtual URL.
3733 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3734 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003735 GURL url = controller_.GetActiveEntry()
3736 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153737
[email protected]fa944cb82013-11-15 17:51:213738 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323739}
3740
[email protected]0eba810b2012-10-18 03:19:363741int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213742 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413743 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3744 true, true);
[email protected]0eba810b2012-10-18 03:19:363745}
3746
[email protected]b172aee2012-04-10 17:05:263747void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273748 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253749 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223750
[email protected]ea114722012-03-12 01:11:253751 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173752 if (rdh) // NULL in unittests.
3753 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253754}
3755
[email protected]b172aee2012-04-10 17:05:263756void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443757 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253758 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443759}
3760
[email protected]b172aee2012-04-10 17:05:263761void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563762 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263763 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153764 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523765 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153766 return;
3767
[email protected]9f76c1e2012-03-05 15:15:583768 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3769
[email protected]e5fc1632011-08-08 07:51:533770 // Ignore renderer unresponsive event if debugger is attached to the tab
3771 // since the event may be a result of the renderer sitting on a breakpoint.
3772 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363773 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533774 return;
3775
[email protected]2e9d79f2013-08-16 05:45:563776 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323777 // Hang occurred while firing the beforeunload/unload handler.
3778 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583779 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323780
[email protected]fa944cb82013-11-15 17:51:213781 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323782 return;
3783
3784 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563785 // nothing we can do to recover. If the hang is in the beforeunload handler,
3786 // pretend the beforeunload listeners have all fired and allow the delegate
3787 // to continue closing; the user will not have the option of cancelling the
3788 // close. Otherwise, pretend the unload listeners have all fired and close
3789 // the tab.
3790 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463791 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563792 delegate_->BeforeUnloadFired(this, true, &close);
3793 }
3794 if (close)
3795 Close(rvh);
[email protected]420ae012009-04-24 05:16:323796 return;
3797 }
3798
[email protected]9f76c1e2012-03-05 15:15:583799 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473800 return;
3801
[email protected]6934a702011-12-20 00:04:513802 if (delegate_)
3803 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323804}
3805
[email protected]b172aee2012-04-10 17:05:263806void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513807 if (delegate_)
3808 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323809}
3810
[email protected]b172aee2012-04-10 17:05:263811void WebContentsImpl::LoadStateChanged(
3812 const GURL& url,
3813 const net::LoadStateWithParam& load_state,
3814 uint64 upload_position,
3815 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323816 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563817 upload_position_ = upload_position;
3818 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503819 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213820 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303821 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213822 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323823 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463824 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213825 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463826 }
[email protected]420ae012009-04-24 05:16:323827}
3828
[email protected]b172aee2012-04-10 17:05:263829void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553830 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323831 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123832 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3833 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513834 if (delegate_)
3835 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093836 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323837}
3838
[email protected]58d5cfe2013-07-10 02:40:523839void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543840 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233841 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223842 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543843}
3844
[email protected]b172aee2012-04-10 17:05:263845void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103846 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213847 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263848 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3849 // here during container initialization and normal window size will be set
3850 // later. In case of tab duplication this resizing to 0x0 prevents setting
3851 // normal size later so just ignore it.
3852 if (!size.IsEmpty())
3853 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323854}
3855
[email protected]af905902013-10-01 21:38:513856void WebContentsImpl::CancelModalDialogsForRenderManager() {
3857 // We need to cancel modal dialogs when doing a process swap, since the load
3858 // deferrer would prevent us from swapping out.
3859 if (dialog_manager_)
3860 dialog_manager_->CancelActiveAndPendingDialogs(this);
3861}
3862
[email protected]02d7b6e2014-06-24 21:01:503863void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
3864 RenderFrameHost* new_host,
3865 bool is_main_frame) {
3866 if (is_main_frame) {
3867 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : NULL,
3868 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:083869
[email protected]02d7b6e2014-06-24 21:01:503870 // Make sure the visible RVH reflects the new delegate's preferences.
3871 if (delegate_)
3872 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393873
[email protected]02d7b6e2014-06-24 21:01:503874 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
3875 }
3876
3877 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:543878}
3879
[email protected]14392a52012-05-02 20:28:443880int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3881 SiteInstance* instance) {
3882 if (!opener_)
3883 return MSG_ROUTING_NONE;
3884
3885 // Recursively create RenderViews for anything else in the opener chain.
3886 return opener_->CreateOpenerRenderViews(instance);
3887}
3888
3889int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3890 int opener_route_id = MSG_ROUTING_NONE;
3891
3892 // If this tab has an opener, ensure it has a RenderView in the given
3893 // SiteInstance as well.
3894 if (opener_)
3895 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3896
[email protected]45a22ad2013-02-21 03:25:003897 // If any of the renderers (current, pending, or swapped out) for this
3898 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213899 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3900 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373901
[email protected]fa944cb82013-11-15 17:51:213902 if (GetRenderManager()->pending_render_view_host() &&
3903 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3904 instance)
3905 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003906
[email protected]fa944cb82013-11-15 17:51:213907 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373908 instance);
3909 if (rvh)
3910 return rvh->GetRoutingID();
3911
[email protected]14392a52012-05-02 20:28:443912 // Create a swapped out RenderView in the given SiteInstance if none exists,
3913 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413914 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3915 true, true);
[email protected]14392a52012-05-02 20:28:443916}
3917
[email protected]b172aee2012-04-10 17:05:263918NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193919 return GetController();
[email protected]3a3d47472010-07-15 21:03:543920}
3921
[email protected]b172aee2012-04-10 17:05:263922WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563923 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323924}
3925
[email protected]10f417c52011-12-28 21:04:233926NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263927 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323928 return controller_.GetLastCommittedEntry();
3929}
3930
[email protected]b172aee2012-04-10 17:05:263931bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163932 RenderViewHost* render_view_host,
3933 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043934 int proxy_routing_id,
[email protected]6ab9d682014-05-22 03:48:593935 bool for_main_frame) {
[email protected]e11f0e92013-06-12 15:12:033936 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443937 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483938 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163939 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3940 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3941 // case this because RWH is still a base class of RenderViewHost, and child
3942 // frame RWHVs are unique in that they do not have their own WebContents.
[email protected]6ab9d682014-05-22 03:48:593943 if (!for_main_frame) {
[email protected]bffc8302014-01-23 20:52:163944 RenderWidgetHostViewChildFrame* rwh_view_child =
3945 new RenderWidgetHostViewChildFrame(render_view_host);
[email protected]bffc8302014-01-23 20:52:163946 rwh_view = rwh_view_child;
3947 } else {
3948 rwh_view = view_->CreateViewForWidget(render_view_host);
3949 }
[email protected]1a98a932009-11-17 00:12:523950
[email protected]420ae012009-04-24 05:16:323951 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443952 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213953 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323954
[email protected]74ce1ad2011-12-16 21:51:463955 // Make sure we use the correct starting page_id in the new RenderView.
3956 UpdateMaxPageIDIfNecessary(render_view_host);
3957 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583958 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463959
[email protected]9f76c1e2012-03-05 15:15:583960 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263961 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493962 opener_route_id,
[email protected]5a7100d2014-05-19 01:29:043963 proxy_routing_id,
[email protected]c7c0d822014-04-16 20:19:493964 max_page_id,
3965 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523966 return false;
[email protected]14392a52012-05-02 20:28:443967 }
[email protected]a4127722011-04-27 23:13:523968
[email protected]a220b5932013-09-21 03:47:443969#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503970 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3971 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443972 if (rwh_view) {
3973 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3974 render_widget_host->WasResized();
3975 }
[email protected]f8233cc2011-05-31 20:24:503976#endif
3977
[email protected]420ae012009-04-24 05:16:323978 return true;
3979}
3980
[email protected]7d244f12013-08-22 21:41:513981#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453982
[email protected]155c7f22013-12-09 17:07:183983base::android::ScopedJavaLocalRef<jobject>
3984WebContentsImpl::GetJavaWebContents() {
3985 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3986
3987 WebContentsAndroid* web_contents_android =
3988 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3989 if (!web_contents_android) {
3990 web_contents_android = new WebContentsAndroid(this);
3991 SetUserData(kWebContentsAndroidKey, web_contents_android);
3992 }
3993 return web_contents_android->GetJavaObject();
3994}
3995
[email protected]7d244f12013-08-22 21:41:513996bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3997 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163998 MSG_ROUTING_NONE,
[email protected]5a7100d2014-05-19 01:29:043999 MSG_ROUTING_NONE,
[email protected]6ab9d682014-05-22 03:48:594000 true);
[email protected]7d244f12013-08-22 21:41:514001}
[email protected]fc2b46b2014-05-03 16:33:454002
4003#elif defined(OS_MACOSX)
4004
4005void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
4006 view_->SetAllowOverlappingViews(overlapping);
4007}
4008
4009bool WebContentsImpl::GetAllowOverlappingViews() {
4010 return view_->GetAllowOverlappingViews();
4011}
4012
4013void WebContentsImpl::SetOverlayView(WebContents* overlay,
4014 const gfx::Point& offset) {
4015 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
4016 offset);
4017}
4018
4019void WebContentsImpl::RemoveOverlayView() {
4020 view_->RemoveOverlayView();
4021}
4022
[email protected]7d244f12013-08-22 21:41:514023#endif
4024
[email protected]6fba26d2014-04-29 09:38:284025void WebContentsImpl::OnDialogClosed(int render_process_id,
4026 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264027 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494028 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264029 bool success,
[email protected]fcf75d42013-12-03 20:11:264030 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284031 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4032 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494033 last_dialog_suppressed_ = dialog_was_suppressed;
4034
[email protected]beb440c2009-11-06 04:08:544035 if (is_showing_before_unload_dialog_ && !success) {
4036 // If a beforeunload dialog is canceled, we need to stop the throbber from
4037 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:284038 if (rfh)
4039 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:354040 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:104041
[email protected]6d65a462013-06-21 21:29:124042 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4043 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544044 }
[email protected]87de04b02014-04-08 22:14:494045
[email protected]beb440c2009-11-06 04:08:544046 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284047 if (rfh) {
4048 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4049 dialog_was_suppressed);
4050 } else {
4051 // Don't leak the sync IPC reply if the RFH or process is gone.
4052 delete reply_msg;
4053 }
[email protected]beb440c2009-11-06 04:08:544054}
4055
[email protected]b172aee2012-04-10 17:05:264056void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544057 if (encoding == last_reported_encoding_)
4058 return;
4059 last_reported_encoding_ = encoding;
4060
4061 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124062 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104063}
[email protected]f45d2a72010-03-08 23:28:354064
[email protected]b172aee2012-04-10 17:05:264065void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:484066 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:444067 // Can be NULL during tests.
4068 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:454069 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:364070}
[email protected]9f76c1e2012-03-05 15:15:584071
[email protected]1ac10dca2013-08-20 20:47:044072bool WebContentsImpl::IsHidden() {
4073 return capturer_count_ == 0 && !should_normally_be_visible_;
4074}
4075
[email protected]b0936d22013-11-28 06:47:364076RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214077 return frame_tree_.root()->render_manager();
4078}
4079
[email protected]b172aee2012-04-10 17:05:264080RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:584081 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
4082}
[email protected]7900bfdb2012-05-24 19:31:244083
[email protected]f8497342013-02-05 22:15:024084BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394085 return browser_plugin_guest_.get();
4086}
4087
[email protected]738f57a2013-06-29 21:06:544088void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4089 CHECK(!browser_plugin_guest_);
4090 browser_plugin_guest_.reset(guest);
4091}
4092
[email protected]f8497342013-02-05 22:15:024093BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394094 return browser_plugin_embedder_.get();
4095}
[email protected]8ff00d72012-10-23 19:12:214096
[email protected]d9030b82013-07-19 08:26:064097void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:194098 RenderFrameHost* render_frame_host) {
4099 STLDeleteValues(&power_save_blockers_[render_frame_host]);
4100 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:064101}
4102
4103void WebContentsImpl::ClearAllPowerSaveBlockers() {
4104 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
4105 i != power_save_blockers_.end(); ++i)
4106 STLDeleteValues(&power_save_blockers_[i->first]);
4107 power_save_blockers_.clear();
4108}
4109
[email protected]fc2b46b2014-05-03 16:33:454110gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214111 gfx::Size size;
4112 if (delegate_)
4113 size = delegate_->GetSizeForNewRenderView(this);
4114 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454115 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214116 return size;
4117}
4118
[email protected]9b159a52013-10-03 17:24:554119void WebContentsImpl::OnFrameRemoved(
4120 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:584121 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:554122 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:584123 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:554124}
4125
[email protected]222f5822014-02-05 23:40:494126void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4127 if (!delegate_)
4128 return;
4129 const gfx::Size new_size = GetPreferredSize();
4130 if (new_size != old_size)
4131 delegate_->UpdatePreferredSize(this, new_size);
4132}
4133
[email protected]23f41fd2014-06-21 05:29:174134void WebContentsImpl::ResumeResponseDeferredAtStart() {
4135 FrameTreeNode* node = frame_tree_.root();
4136 node->render_manager()->ResumeResponseDeferredAtStart();
4137}
4138
[email protected]8ff00d72012-10-23 19:12:214139} // namespace content