blob: 7fffb30d214f24dae836c279a33017c05f4b2758 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/browser_plugin/browser_plugin_embedder.h"
22#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]8eb04562013-03-06 03:41:1423#include "content/browser/browser_plugin/browser_plugin_guest_manager.h"
[email protected]b9535422012-02-09 01:47:5924#include "content/browser/child_process_security_policy_impl.h"
[email protected]49413ca52014-03-05 14:13:4325#include "content/browser/devtools/render_view_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4126#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0427#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4628#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1229#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1630#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1631#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4032#include "content/browser/frame_host/interstitial_page_impl.h"
33#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0134#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1835#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1636#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]5c9250872012-01-30 17:24:0537#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4438#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5339#include "content/browser/message_port_message_filter.h"
40#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0641#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3042#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5043#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3244#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5045#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4846#include "content/browser/renderer_host/render_widget_host_view_base.h"
[email protected]b6583592012-01-25 19:52:3347#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1148#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5849#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0350#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5651#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1452#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4253#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4454#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0255#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1756#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5157#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0258#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3659#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1160#include "content/public/browser/browser_context.h"
[email protected]87f3c082011-10-19 18:07:4461#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3662#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1763#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1464#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4665#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1566#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0067#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2768#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0069#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3770#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1471#include "content/public/browser/notification_service.h"
[email protected]55578b0a2012-04-18 14:31:3272#include "content/public/browser/resource_request_details.h"
[email protected]4c3a23582012-08-18 08:54:3473#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:3874#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:4275#include "content/public/browser/web_contents_delegate.h"
[email protected]d8c660432011-12-22 20:51:2576#include "content/public/browser/web_contents_observer.h"
[email protected]e091df82011-10-11 18:13:2177#include "content/public/common/bindings_policy.h"
[email protected]54087fe2011-10-28 22:02:4878#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:5479#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:4980#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:2081#include "content/public/common/result_codes.h"
[email protected]a1d29162011-10-14 17:14:0382#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:5783#include "content/public/common/url_utils.h"
[email protected]a53209b2012-01-20 16:48:1684#include "net/base/mime_util.h"
[email protected]d686e812009-06-03 19:10:2985#include "net/base/net_util.h"
[email protected]8bfc8272013-09-09 20:10:5386#include "net/http/http_cache.h"
87#include "net/http/http_transaction_factory.h"
88#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:3489#include "net/url_request/url_request_context_getter.h"
[email protected]a08412b62012-05-29 21:28:5690#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:0191#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:4192#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:5293#include "ui/gl/gl_switches.h"
[email protected]fab55e72013-05-31 07:06:1894#include "webkit/common/webpreferences.h"
[email protected]3c733bde2010-12-21 19:56:3195
[email protected]583418cc2013-01-17 14:01:1096#if defined(OS_ANDROID)
97#include "content/browser/android/date_time_chooser_android.h"
[email protected]fc2b46b2014-05-03 16:33:4598#include "content/browser/media/android/browser_media_player_manager.h"
[email protected]155c7f22013-12-09 17:07:1899#include "content/browser/web_contents/web_contents_android.h"
[email protected]74ebfb12013-06-07 20:48:00100#include "content/public/browser/android/content_view_core.h"
[email protected]583418cc2013-01-17 14:01:10101#endif
102
[email protected]f66df822012-05-18 16:52:17103#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50104#include "base/mac/foundation_util.h"
[email protected]423e644f2013-06-19 00:48:27105#include "ui/gl/io_surface_support_mac.h"
[email protected]38b098f2012-03-14 21:11:57106#endif
[email protected]3e45ba92009-02-20 21:09:00107
[email protected]420ae012009-04-24 05:16:32108// Cross-Site Navigations
109//
[email protected]b172aee2012-04-10 17:05:26110// If a WebContentsImpl is told to navigate to a different web site (as
111// determined by SiteInstance), it will replace its current RenderViewHost with
112// a new RenderViewHost dedicated to the new SiteInstance. This works as
113// follows:
[email protected]420ae012009-04-24 05:16:32114//
[email protected]fc6c1872013-10-03 01:22:35115// - RVHM::Navigate determines whether the destination is cross-site, and if so,
[email protected]a2750082011-09-01 12:29:46116// it creates a pending_render_view_host_.
[email protected]420ae012009-04-24 05:16:32117// - The pending RVH is "suspended," so that no navigation messages are sent to
[email protected]fc6c1872013-10-03 01:22:35118// its renderer until the beforeunload JavaScript handler has a chance to
[email protected]420ae012009-04-24 05:16:32119// run in the current RVH.
120// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
[email protected]fc6c1872013-10-03 01:22:35121// that it has a pending cross-site request. We will check this on the IO
122// thread when deciding how to handle the response.
123// - The current RVH runs its beforeunload handler. If it returns false, we
[email protected]a2750082011-09-01 12:29:46124// cancel all the pending logic. Otherwise we allow the pending RVH to send
125// the navigation request to its renderer.
126// - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the
[email protected]fc6c1872013-10-03 01:22:35127// main resource load on the pending RVH. It creates a
128// CrossSiteResourceHandler to check whether a process swap is needed when
129// the request is ready to commit.
[email protected]a2750082011-09-01 12:29:46130// - When RDH receives a response, the BufferedResourceHandler determines
131// whether it is a download. If so, it sends a message to the new renderer
132// causing it to cancel the request, and the download proceeds. For now, the
[email protected]b172aee2012-04-10 17:05:26133// pending RVH remains until the next DidNavigate event for this
134// WebContentsImpl. This isn't ideal, but it doesn't affect any functionality.
[email protected]420ae012009-04-24 05:16:32135// - After RDH receives a response and determines that it is safe and not a
[email protected]fc6c1872013-10-03 01:22:35136// download, the CrossSiteResourceHandler checks whether a process swap is
137// needed (either because CrossSiteRequestManager has state for it or because
138// a transfer was needed for a redirect).
139// - If so, CrossSiteResourceHandler pauses the response to first run the old
140// page's unload handler. It does this by asynchronously calling the
[email protected]b0936d22013-11-28 06:47:36141// OnCrossSiteResponse method of RenderFrameHostManager on the UI thread,
142// which sends a SwapOut message to the current RVH.
[email protected]fc6c1872013-10-03 01:22:35143// - Once the unload handler is finished, RVHM::SwappedOut checks if a transfer
144// to a new process is needed, based on the stored pending_nav_params_. (This
145// is independent of whether we started out with a cross-process navigation.)
146// - If not, it just tells the ResourceDispatcherHost to resume the response
147// to its current RenderViewHost.
148// - If so, it cancels the current pending RenderViewHost and sets up a new
149// navigation using RequestTransferURL. When the transferred request
150// arrives in the ResourceDispatcherHost, we transfer the response and
151// resume it.
[email protected]420ae012009-04-24 05:16:32152// - The pending renderer sends a FrameNavigate message that invokes the
153// DidNavigate method. This replaces the current RVH with the
[email protected]a2750082011-09-01 12:29:46154// pending RVH.
[email protected]b0936d22013-11-28 06:47:36155// - The previous renderer is kept swapped out in RenderFrameHostManager in case
[email protected]992db4c2011-05-12 15:37:15156// the user goes back. The process only stays live if another tab is using
157// it, but if so, the existing frame relationships will be maintained.
[email protected]420ae012009-04-24 05:16:32158
[email protected]8ff00d72012-10-23 19:12:21159namespace content {
[email protected]420ae012009-04-24 05:16:32160namespace {
161
[email protected]82114f52012-03-20 22:53:41162const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05163
[email protected]155c7f22013-12-09 17:07:18164#if defined(OS_ANDROID)
165const char kWebContentsAndroidKey[] = "web_contents_android";
166#endif // OS_ANDROID
167
[email protected]e4abd3b42013-11-12 18:28:47168base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46169g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
170
[email protected]988ed7132014-03-31 16:25:58171static int StartDownload(content::RenderFrameHost* rfh,
[email protected]795c28972012-12-06 06:13:39172 const GURL& url,
[email protected]433bd24b2013-03-20 18:27:29173 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:30174 uint32_t max_bitmap_size) {
[email protected]41225fe2013-03-29 05:32:02175 static int g_next_image_download_id = 0;
[email protected]988ed7132014-03-31 16:25:58176 rfh->Send(new ImageMsg_DownloadImage(rfh->GetRoutingID(),
[email protected]41225fe2013-03-29 05:32:02177 ++g_next_image_download_id,
178 url,
179 is_favicon,
[email protected]263cb08f2013-09-18 00:26:30180 max_bitmap_size));
[email protected]41225fe2013-03-29 05:32:02181 return g_next_image_download_id;
[email protected]795c28972012-12-06 06:13:39182}
183
[email protected]8bfc8272013-09-09 20:10:53184void NotifyCacheOnIO(
185 scoped_refptr<net::URLRequestContextGetter> request_context,
186 const GURL& url,
187 const std::string& http_method) {
188 request_context->GetURLRequestContext()->http_transaction_factory()->
189 GetCache()->OnExternalCacheHit(url, http_method);
190}
191
[email protected]9b159a52013-10-03 17:24:55192// Helper function for retrieving all the sites in a frame tree.
193bool CollectSites(BrowserContext* context,
194 std::set<GURL>* sites,
195 FrameTreeNode* node) {
196 sites->insert(SiteInstance::GetSiteForURL(context, node->current_url()));
197 return true;
198}
199
[email protected]a86c0e962013-12-17 17:10:39200bool ForEachFrameInternal(
201 const base::Callback<void(RenderFrameHost*)>& on_frame,
202 FrameTreeNode* node) {
[email protected]94d0cc12013-12-18 00:07:41203 on_frame.Run(node->current_frame_host());
[email protected]a86c0e962013-12-17 17:10:39204 return true;
205}
206
[email protected]c06c58c2014-03-12 20:31:59207bool ForEachPendingFrameInternal(
208 const base::Callback<void(RenderFrameHost*)>& on_frame,
209 FrameTreeNode* node) {
210 RenderFrameHost* pending_frame_host =
211 node->render_manager()->pending_frame_host();
212 if (pending_frame_host)
213 on_frame.Run(pending_frame_host);
214 return true;
215}
216
[email protected]a86c0e962013-12-17 17:10:39217void SendToAllFramesInternal(IPC::Message* message, RenderFrameHost* rfh) {
218 IPC::Message* message_copy = new IPC::Message(*message);
219 message_copy->set_routing_id(rfh->GetRoutingID());
220 rfh->Send(message_copy);
221}
222
[email protected]c06c58c2014-03-12 20:31:59223void RunRenderFrameDeleted(
224 ObserverList<WebContentsObserver>* observer_list,
225 RenderFrameHost* render_frame_host) {
226 FOR_EACH_OBSERVER(WebContentsObserver,
227 *observer_list,
228 RenderFrameDeleted(render_frame_host));
229}
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]443b80e2010-12-14 00:42:23330 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
331 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34332 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26333 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56334 upload_size_(0),
335 upload_position_(0),
[email protected]f17a0ee2010-05-17 17:38:47336 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10337 has_accessed_initial_document_(false),
[email protected]54597982013-02-06 01:59:55338 capturer_count_(0),
339 should_normally_be_visible_(true),
[email protected]fdd61c62009-04-22 19:22:57340 is_being_destroyed_(false),
341 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15342 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01343 is_showing_before_unload_dialog_(false),
[email protected]9a890452014-02-13 22:21:02344 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38345 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21346 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
347 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
[email protected]9e823662010-10-13 23:36:00348 temporary_zoom_settings_(false),
[email protected]bab38af2014-03-30 17:37:29349 totalPinchGestureAmount_(0),
350 currentPinchZoomStepDelta_(0),
[email protected]f114fa42013-12-06 17:06:44351 render_view_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42352 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]87de04b02014-04-08 22:14:49353 is_subframe_(false),
354 last_dialog_suppressed_(false) {
[email protected]cbb1ef592013-06-05 19:49:46355 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
356 g_created_callbacks.Get().at(i).Run(this);
[email protected]9b159a52013-10-03 17:24:55357 frame_tree_.SetFrameRemoveListener(
358 base::Bind(&WebContentsImpl::OnFrameRemoved,
359 base::Unretained(this)));
[email protected]332af7732009-03-11 13:21:35360}
initial.commit09911bf2008-07-26 23:55:29361
[email protected]b172aee2012-04-10 17:05:26362WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32363 is_being_destroyed_ = true;
364
[email protected]21b41c7e892014-02-28 01:52:24365 // Delete all RFH pending shutdown, which will lead the corresponding RVH to
366 // shutdown and be deleted as well.
367 frame_tree_.ForEach(
368 base::Bind(&RenderFrameHostManager::ClearRFHsPendingShutdown));
369
[email protected]d9030b82013-07-19 08:26:06370 ClearAllPowerSaveBlockers();
371
[email protected]b24b68a2012-09-24 21:57:26372 for (std::set<RenderWidgetHostImpl*>::iterator iter =
373 created_widgets_.begin(); iter != created_widgets_.end(); ++iter) {
374 (*iter)->DetachDelegate();
375 }
376 created_widgets_.clear();
377
[email protected]3ab9cb82011-06-03 18:02:07378 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15379 if (dialog_manager_)
[email protected]4567f152013-07-31 13:20:11380 dialog_manager_->WebContentsDestroyed(this);
[email protected]3ab9cb82011-06-03 18:02:07381
[email protected]8ed16472014-04-11 19:02:48382 if (color_chooser_info_.get())
383 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20384
[email protected]420ae012009-04-24 05:16:32385 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32386
[email protected]ca13a442012-04-17 14:00:12387 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21388 NotificationService::current()->Notify(
389 NOTIFICATION_WEB_CONTENTS_DESTROYED,
390 Source<WebContents>(this),
391 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32392
[email protected]c06c58c2014-03-12 20:31:59393 base::Callback<void(RenderFrameHost*)> run_render_frame_deleted_callback =
394 base::Bind(&RunRenderFrameDeleted, base::Unretained(&observers_));
395 frame_tree_.ForEach(base::Bind(&ForEachPendingFrameInternal,
396 run_render_frame_deleted_callback));
397
[email protected]fa944cb82013-11-15 17:51:21398 RenderViewHost* pending_rvh = GetRenderManager()->pending_render_view_host();
[email protected]f273ee52013-10-18 16:05:27399 if (pending_rvh) {
400 FOR_EACH_OBSERVER(WebContentsObserver,
401 observers_,
402 RenderViewDeleted(pending_rvh));
403 }
404
[email protected]c06c58c2014-03-12 20:31:59405 ForEachFrame(run_render_frame_deleted_callback);
406
[email protected]f273ee52013-10-18 16:05:27407 FOR_EACH_OBSERVER(WebContentsObserver,
408 observers_,
[email protected]fa944cb82013-11-15 17:51:21409 RenderViewDeleted(GetRenderManager()->current_host()));
[email protected]f273ee52013-10-18 16:05:27410
[email protected]2db9bd72012-04-13 20:20:56411 FOR_EACH_OBSERVER(WebContentsObserver,
412 observers_,
[email protected]12a46832014-05-09 13:35:58413 WebContentsDestroyed());
414
415 FOR_EACH_OBSERVER(WebContentsObserver,
416 observers_,
417 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08418
[email protected]6934a702011-12-20 00:04:51419 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10420
421 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
422 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42423}
424
[email protected]d1198fd2012-08-13 22:50:19425WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59426 const WebContents::CreateParams& params,
[email protected]d1198fd2012-08-13 22:50:19427 WebContentsImpl* opener) {
[email protected]e11f0e92013-06-12 15:12:03428 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
[email protected]54944cde2012-12-09 09:24:59429 WebContentsImpl* new_contents = new WebContentsImpl(
430 params.browser_context, opener);
[email protected]d1198fd2012-08-13 22:50:19431
[email protected]83100cd2014-05-10 11:50:06432 if (params.guest_instance_id) {
433 scoped_ptr<base::DictionaryValue> extra_params(
434 params.guest_extra_params->DeepCopy());
435 // This makes |new_contents| act as a guest.
436 // For more info, see comment above class BrowserPluginGuest.
437 BrowserPluginGuest::Create(params.guest_instance_id,
438 params.site_instance,
439 new_contents,
440 extra_params.Pass());
441 // We are instantiating a WebContents for browser plugin. Set its subframe
442 // bit to true.
443 new_contents->is_subframe_ = true;
444 }
[email protected]54944cde2012-12-09 09:24:59445 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19446 return new_contents;
447}
448
[email protected]b0936d22013-11-28 06:47:36449RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21450 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28451}
452
[email protected]7bb761892012-07-20 09:32:47453bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
454 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44455 return OnMessageReceived(render_view_host, NULL, message);
456}
457
458bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
459 RenderFrameHost* render_frame_host,
460 const IPC::Message& message) {
461 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56462 if (GetWebUI() &&
463 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17464 return true;
[email protected]d2353452012-01-19 19:53:56465 }
[email protected]f82d57b52011-04-27 19:13:17466
[email protected]d8c660432011-12-22 20:51:25467 ObserverListBase<WebContentsObserver>::Iterator it(observers_);
468 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33469 if (render_frame_host) {
470 while ((observer = it.GetNext()) != NULL)
471 if (observer->OnMessageReceived(message, render_frame_host))
472 return true;
473 } else {
474 while ((observer = it.GetNext()) != NULL)
475 if (observer->OnMessageReceived(message))
476 return true;
477 }
[email protected]403415a2011-01-10 18:57:53478
[email protected]1d62cf72014-02-07 21:31:57479 // Message handlers should be aware of which
480 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
481 // stored in render_(view|frame)_message_source_.
[email protected]49413ca52014-03-05 14:13:43482 if (render_frame_host) {
483 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
484 render_frame_host->GetRenderViewHost(), message))
485 return true;
[email protected]1d62cf72014-02-07 21:31:57486 render_frame_message_source_ = render_frame_host;
[email protected]49413ca52014-03-05 14:13:43487 } else {
488 if (RenderViewDevToolsAgentHost::DispatchIPCMessage(
489 render_view_host, message))
490 return true;
[email protected]1d62cf72014-02-07 21:31:57491 render_view_message_source_ = render_view_host;
[email protected]49413ca52014-03-05 14:13:43492 }
[email protected]1d62cf72014-02-07 21:31:57493
[email protected]724159a2010-12-30 01:11:18494 bool handled = true;
495 bool message_is_ok = true;
[email protected]b172aee2012-04-10 17:05:26496 IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok)
[email protected]f114fa42013-12-06 17:06:44497 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
498 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]cfa856d62014-02-22 07:58:40499 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
500 OnDomOperationResponse)
[email protected]8ed16472014-04-11 19:02:48501 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
502 OnDocumentLoadedInFrame)
503 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
504 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
505 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
506 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
507 OnSetSelectedColorInColorChooser)
[email protected]96307312014-05-04 01:00:19508 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPlayingNotification,
509 OnMediaPlayingNotification)
510 IPC_MESSAGE_HANDLER(FrameHostMsg_MediaPausedNotification,
511 OnMediaPausedNotification)
[email protected]724159a2010-12-30 01:11:18512 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
513 OnDidLoadResourceFromMemoryCache)
514 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
515 OnDidDisplayInsecureContent)
516 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
517 OnDidRunInsecureContent)
[email protected]7d472472011-01-22 01:30:25518 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26519 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
[email protected]3a29a6e2011-08-24 18:26:21520 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
[email protected]7d189022011-08-25 22:54:20521 IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler,
522 OnRegisterProtocolHandler)
[email protected]b888919c2011-09-02 00:32:16523 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10524 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50525 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
[email protected]d8415ad92012-08-23 14:40:50526 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
527 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55528 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_AllocateInstanceID,
529 OnBrowserPluginMessage(message))
530 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
531 OnBrowserPluginMessage(message))
[email protected]41225fe2013-03-29 05:32:02532 IPC_MESSAGE_HANDLER(ImageHostMsg_DidDownloadImage, OnDidDownloadImage)
533 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]9f268072013-11-07 00:02:15534 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
535 OnFirstVisuallyNonEmptyPaint)
[email protected]edc3af82013-12-12 21:24:07536 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
537 OnShowValidationMessage)
538 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
539 OnHideValidationMessage)
540 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
541 OnMoveValidationMessage)
[email protected]8ed16472014-04-11 19:02:48542#if defined(OS_ANDROID)
543 IPC_MESSAGE_HANDLER(ViewHostMsg_FindMatchRects_Reply,
544 OnFindMatchRectsReply)
545 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
546 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48547#endif
[email protected]724159a2010-12-30 01:11:18548 IPC_MESSAGE_UNHANDLED(handled = false)
549 IPC_END_MESSAGE_MAP_EX()
[email protected]f114fa42013-12-06 17:06:44550 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57551 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18552
553 if (!message_is_ok) {
[email protected]e6e30ac2014-01-13 21:24:39554 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD"));
[email protected]724159a2010-12-30 01:11:18555 GetRenderProcessHost()->ReceivedBadMessage();
556 }
557
558 return handled;
559}
560
[email protected]b172aee2012-04-10 17:05:26561void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18562 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21563 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43564 if (delegate_)
565 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18566}
567
[email protected]d1198fd2012-08-13 22:50:19568NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56569 return controller_;
570}
571
[email protected]d1198fd2012-08-13 22:50:19572const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56573 return controller_;
574}
575
[email protected]8ff00d72012-10-23 19:12:21576BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55577 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30578}
579
[email protected]b172aee2012-04-10 17:05:26580const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24581 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32582 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51583 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31584}
585
[email protected]a093ce02013-07-22 20:53:14586const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24587 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32588 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24589 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
590}
591
592const GURL& WebContentsImpl::GetLastCommittedURL() const {
593 // We may not have a navigation entry yet.
594 NavigationEntry* entry = controller_.GetLastCommittedEntry();
595 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
596}
597
[email protected]8ff00d72012-10-23 19:12:21598WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31599 return delegate_;
600}
601
[email protected]8ff00d72012-10-23 19:12:21602void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31603 // TODO(cbentzel): remove this debugging code?
604 if (delegate == delegate_)
605 return;
606 if (delegate_)
607 delegate_->Detach(this);
608 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08609 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31610 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08611 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00612 if (view_)
613 view_->SetOverscrollControllerEnabled(delegate->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08614 }
[email protected]be1f56ab2011-12-22 06:55:31615}
616
[email protected]8ff00d72012-10-23 19:12:21617RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21618 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41619 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16620}
621
[email protected]60eca4eb2013-12-06 00:02:16622RenderFrameHost* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41623 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16624}
625
[email protected]9c9343b2014-03-08 02:56:07626RenderFrameHost* WebContentsImpl::GetFocusedFrame() {
627 if (!frame_tree_.GetFocusedFrame())
628 return NULL;
629 return frame_tree_.GetFocusedFrame()->current_frame_host();
630}
631
[email protected]a86c0e962013-12-17 17:10:39632void WebContentsImpl::ForEachFrame(
633 const base::Callback<void(RenderFrameHost*)>& on_frame) {
634 frame_tree_.ForEach(base::Bind(&ForEachFrameInternal, on_frame));
635}
636
637void WebContentsImpl::SendToAllFrames(IPC::Message* message) {
638 ForEachFrame(base::Bind(&SendToAllFramesInternal, message));
639 delete message;
640}
641
[email protected]b172aee2012-04-10 17:05:26642RenderViewHost* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21643 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31644}
645
[email protected]bfcfa692013-02-07 06:17:02646WebContents* WebContentsImpl::GetEmbedderWebContents() const {
647 BrowserPluginGuest* guest = GetBrowserPluginGuest();
648 if (guest)
649 return guest->embedder_web_contents();
650 return NULL;
651}
652
653int WebContentsImpl::GetEmbeddedInstanceID() const {
654 BrowserPluginGuest* guest = GetBrowserPluginGuest();
655 if (guest)
656 return guest->instance_id();
657 return 0;
658}
659
[email protected]6b618e62012-08-16 12:59:18660int WebContentsImpl::GetRoutingID() const {
661 if (!GetRenderViewHost())
662 return MSG_ROUTING_NONE;
663
664 return GetRenderViewHost()->GetRoutingID();
665}
666
[email protected]44470a22013-01-24 01:21:54667int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
668 return fullscreen_widget_routing_id_;
669}
670
[email protected]b172aee2012-04-10 17:05:26671RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21672 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31673}
674
[email protected]4aebbca2013-09-17 22:26:49675RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
676 const {
677 RenderWidgetHost* const widget_host =
678 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
679 GetFullscreenWidgetRoutingID());
680 return widget_host ? widget_host->GetView() : NULL;
681}
682
[email protected]8ff00d72012-10-23 19:12:21683WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31684 return view_.get();
685}
686
[email protected]8ff00d72012-10-23 19:12:21687WebUI* WebContentsImpl::CreateWebUI(const GURL& url) {
[email protected]d2353452012-01-19 19:53:56688 WebUIImpl* web_ui = new WebUIImpl(this);
[email protected]86a0a6e2013-01-28 06:33:03689 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
690 CreateWebUIControllerForURL(web_ui, url);
[email protected]c63cedf22012-01-17 18:42:22691 if (controller) {
[email protected]eb2ef212013-01-29 04:27:58692 web_ui->AddMessageHandler(new GenericHandler());
[email protected]c63cedf22012-01-17 18:42:22693 web_ui->SetController(controller);
694 return web_ui;
695 }
696
697 delete web_ui;
698 return NULL;
699}
700
[email protected]8ff00d72012-10-23 19:12:21701WebUI* WebContentsImpl::GetWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21702 return GetRenderManager()->web_ui() ? GetRenderManager()->web_ui()
703 : GetRenderManager()->pending_web_ui();
[email protected]be1f56ab2011-12-22 06:55:31704}
705
[email protected]8ff00d72012-10-23 19:12:21706WebUI* WebContentsImpl::GetCommittedWebUI() const {
[email protected]fa944cb82013-11-15 17:51:21707 return GetRenderManager()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34708}
709
[email protected]86ef6a392012-05-11 22:03:11710void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22711 if (GetUserAgentOverride() == override)
712 return;
713
714 renderer_preferences_.user_agent_override = override;
715
716 // Send the new override string to the renderer.
717 RenderViewHost* host = GetRenderViewHost();
718 if (host)
719 host->SyncRendererPrefs();
720
721 // Reload the page if a load is currently in progress to avoid having
722 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27723 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]bf70edce2012-06-20 22:32:22724 if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent())
725 controller_.ReloadIgnoringCache(true);
[email protected]8d0f3312012-08-18 01:47:53726
727 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
728 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11729}
730
731const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22732 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11733}
734
[email protected]2ceee8f2014-01-14 18:02:08735#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:41736void WebContentsImpl::SetParentNativeViewAccessible(
737gfx::NativeViewAccessible accessible_parent) {
738 accessible_parent_ = accessible_parent;
[email protected]3144b892013-05-25 01:14:45739 if (GetRenderViewHost())
740 GetRenderViewHostImpl()->SetParentNativeViewAccessible(accessible_parent);
[email protected]c73a2282013-04-29 21:10:41741}
742#endif
743
[email protected]fcf75d42013-12-03 20:11:26744const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55745 // Transient entries take precedence. They are used for interstitial pages
746 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23747 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]b5cca982011-05-26 04:42:08748 std::string accept_languages =
[email protected]8ff00d72012-10-23 19:12:21749 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:30750 GetBrowserContext());
[email protected]45d0ef7f2011-01-05 13:46:23751 if (entry) {
[email protected]b5cca982011-05-26 04:42:08752 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23753 }
[email protected]fa944cb82013-11-15 17:51:21754 WebUI* our_web_ui = GetRenderManager()->pending_web_ui() ?
755 GetRenderManager()->pending_web_ui() : GetRenderManager()->web_ui();
[email protected]7ade2732011-02-10 00:13:58756 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54757 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32758 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54759 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35760 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26761 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54762 if (!title.empty())
763 return title;
764 }
765 }
766
767 // We use the title for the last committed entry rather than a pending
768 // navigation entry. For example, when the user types in a URL, we want to
769 // keep the old page's title until the new load has committed and we get a new
770 // title.
[email protected]96d185d2009-04-24 03:28:54771 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:32772
[email protected]9eeafc012013-11-25 23:49:47773 // We make an exception for initial navigations.
774 if (controller_.IsInitialNavigation()) {
775 // We only want to use the title from the visible entry in one of two cases:
776 // 1. There's already a committed entry for an initial navigation, in which
777 // case we are doing a history navigation in a new tab (e.g., Ctrl+Back).
778 // 2. The pending entry has been explicitly assigned a title to display.
779 //
780 // If there's no last committed entry and no assigned title, we should fall
781 // back to |page_title_when_no_navigation_entry_| rather than showing the
782 // URL.
783 if (entry ||
784 (controller_.GetVisibleEntry() &&
785 !controller_.GetVisibleEntry()->GetTitle().empty())) {
786 entry = controller_.GetVisibleEntry();
787 }
788 }
[email protected]59167c22013-06-03 18:07:32789
[email protected]45d0ef7f2011-01-05 13:46:23790 if (entry) {
[email protected]b5cca982011-05-26 04:42:08791 return entry->GetTitleForDisplay(accept_languages);
[email protected]45d0ef7f2011-01-05 13:46:23792 }
[email protected]987fc3a2011-05-26 14:18:09793
794 // |page_title_when_no_navigation_entry_| is finally used
795 // if no title cannot be retrieved.
796 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:54797}
798
[email protected]b172aee2012-04-10 17:05:26799int32 WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:46800 return GetMaxPageIDForSiteInstance(GetSiteInstance());
801}
802
[email protected]b172aee2012-04-10 17:05:26803int32 WebContentsImpl::GetMaxPageIDForSiteInstance(
804 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:33805 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
806 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:46807
[email protected]b6583592012-01-25 19:52:33808 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:34809}
810
[email protected]b172aee2012-04-10 17:05:26811void WebContentsImpl::UpdateMaxPageID(int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46812 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
813}
814
[email protected]b172aee2012-04-10 17:05:26815void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
[email protected]b6583592012-01-25 19:52:33816 SiteInstance* site_instance, int32 page_id) {
[email protected]74ce1ad2011-12-16 21:51:46817 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:33818 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:34819}
820
[email protected]ec6c05f2013-10-23 18:41:57821void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
822 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
823 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:57824}
825
[email protected]b172aee2012-04-10 17:05:26826SiteInstance* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21827 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:54828}
829
[email protected]b172aee2012-04-10 17:05:26830SiteInstance* WebContentsImpl::GetPendingSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:21831 RenderViewHost* dest_rvh = GetRenderManager()->pending_render_view_host() ?
832 GetRenderManager()->pending_render_view_host() :
833 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:58834 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:38835}
836
[email protected]b172aee2012-04-10 17:05:26837bool WebContentsImpl::IsLoading() const {
[email protected]be1f56ab2011-12-22 06:55:31838 return is_loading_;
[email protected]3c9e1872010-11-18 16:17:49839}
840
[email protected]b172aee2012-04-10 17:05:26841bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]be1f56ab2011-12-22 06:55:31842 return waiting_for_response_;
843}
844
[email protected]b172aee2012-04-10 17:05:26845const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:31846 return load_state_;
847}
848
[email protected]fcf75d42013-12-03 20:11:26849const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:31850 return load_state_host_;
851}
852
[email protected]b172aee2012-04-10 17:05:26853uint64 WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:31854 return upload_size_;
855}
856
[email protected]b172aee2012-04-10 17:05:26857uint64 WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:31858 return upload_position_;
859}
860
[email protected]1ae93fb2013-06-14 03:38:56861std::set<GURL> WebContentsImpl::GetSitesInTab() const {
[email protected]1ae93fb2013-06-14 03:38:56862 std::set<GURL> sites;
[email protected]a86c0e962013-12-17 17:10:39863 frame_tree_.ForEach(base::Bind(&CollectSites,
864 base::Unretained(GetBrowserContext()),
865 base::Unretained(&sites)));
[email protected]1ae93fb2013-06-14 03:38:56866 return sites;
867}
868
[email protected]b172aee2012-04-10 17:05:26869const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:54870 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:31871}
872
[email protected]b172aee2012-04-10 17:05:26873bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:31874 return displayed_insecure_content_;
875}
876
[email protected]222f5822014-02-05 23:40:49877void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:25878 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:55879 ++capturer_count_;
880 DVLOG(1) << "There are now " << capturer_count_
881 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:49882
883 // Note: This provides a hint to upstream code to size the views optimally
884 // for quality (e.g., to avoid scaling).
885 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
886 preferred_size_for_capture_ = capture_size;
887 OnPreferredSizeChanged(preferred_size_);
888 }
[email protected]54597982013-02-06 01:59:55889}
890
891void WebContentsImpl::DecrementCapturerCount() {
892 --capturer_count_;
893 DVLOG(1) << "There are now " << capturer_count_
894 << " capturing(s) of WebContentsImpl@" << this;
895 DCHECK_LE(0, capturer_count_);
896
[email protected]5a652232013-02-12 06:15:25897 if (is_being_destroyed_)
898 return;
899
[email protected]222f5822014-02-05 23:40:49900 if (capturer_count_ == 0) {
901 const gfx::Size old_size = preferred_size_for_capture_;
902 preferred_size_for_capture_ = gfx::Size();
903 OnPreferredSizeChanged(old_size);
904 }
905
[email protected]1ac10dca2013-08-20 20:47:04906 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:55907 DVLOG(1) << "Executing delayed WasHidden().";
908 WasHidden();
909 }
[email protected]be1f56ab2011-12-22 06:55:31910}
911
[email protected]f2bd40812013-07-20 04:30:44912int WebContentsImpl::GetCapturerCount() const {
913 return capturer_count_;
914}
915
[email protected]b172aee2012-04-10 17:05:26916bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:31917 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
918 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
919 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
[email protected]3c9e1872010-11-18 16:17:49920}
921
[email protected]b172aee2012-04-10 17:05:26922void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
923 int error_code) {
[email protected]443b80e2010-12-14 00:42:23924 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34925 return;
926
[email protected]443b80e2010-12-14 00:42:23927 crashed_status_ = status;
928 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:21929 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34930}
931
[email protected]b172aee2012-04-10 17:05:26932base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:31933 return crashed_status_;
934}
935
[email protected]b172aee2012-04-10 17:05:26936bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:31937 return is_being_destroyed_;
938}
939
[email protected]b172aee2012-04-10 17:05:26940void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) {
[email protected]d5f942ba2008-09-26 19:30:34941 if (delegate_)
942 delegate_->NavigationStateChanged(this, changed_flags);
943}
944
[email protected]9a890452014-02-13 22:21:02945base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
946 return last_active_time_;
[email protected]3e324142012-06-25 18:26:33947}
948
[email protected]9e2e4632012-07-27 16:38:41949void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:54950 controller_.SetActive(true);
[email protected]cfd80b02014-05-01 17:46:48951 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]8cb5d5b2010-02-09 11:36:16952 if (rwhv) {
[email protected]68ef3962013-09-26 06:45:29953 rwhv->Show();
[email protected]789e9152009-08-04 21:59:43954#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16955 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43956#endif
957 }
[email protected]96d185d2009-04-24 03:28:54958
[email protected]9a890452014-02-13 22:21:02959 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:38960
[email protected]b9769d82012-02-10 00:23:59961 // The resize rect might have changed while this was inactive -- send the new
962 // one to make sure it's up to date.
[email protected]9f76c1e2012-03-05 15:15:58963 RenderViewHostImpl* rvh =
964 static_cast<RenderViewHostImpl*>(GetRenderViewHost());
[email protected]b9769d82012-02-10 00:23:59965 if (rvh) {
966 rvh->ResizeRectChanged(GetRootWindowResizerRect());
967 }
[email protected]96d185d2009-04-24 03:28:54968
[email protected]c0d9d5672013-10-09 07:38:03969 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
970
[email protected]54597982013-02-06 01:59:55971 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:31972}
973
[email protected]b172aee2012-04-10 17:05:26974void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:55975 // If there are entities capturing screenshots or video (e.g., mirroring),
976 // don't activate the "disable rendering" optimization.
977 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:52978 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:55979 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:26980 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:52981 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:33982 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:52983 // calls us).
[email protected]cfd80b02014-05-01 17:46:48984 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]8cb5d5b2010-02-09 11:36:16985 if (rwhv)
[email protected]68ef3962013-09-26 06:45:29986 rwhv->Hide();
[email protected]96d185d2009-04-24 03:28:54987 }
988
[email protected]c0d9d5672013-10-09 07:38:03989 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
990
[email protected]54597982013-02-06 01:59:55991 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:37992}
993
[email protected]b172aee2012-04-10 17:05:26994bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:31995 // TODO(creis): Should we fire even for interstitial pages?
[email protected]0bfbf882011-12-22 18:19:27996 return WillNotifyDisconnection() &&
997 !ShowingInterstitialPage() &&
[email protected]9f76c1e2012-03-05 15:15:58998 !static_cast<RenderViewHostImpl*>(
999 GetRenderViewHost())->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311000}
1001
[email protected]1c3f80bd2014-04-08 23:02:061002void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
1003 static_cast<RenderFrameHostImpl*>(GetMainFrame())->DispatchBeforeUnload(
1004 for_cross_site_transition);
1005}
1006
[email protected]b172aee2012-04-10 17:05:261007void WebContentsImpl::Stop() {
[email protected]fa944cb82013-11-15 17:51:211008 GetRenderManager()->Stop();
[email protected]d16609c2013-08-23 06:01:401009 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271010}
1011
[email protected]b172aee2012-04-10 17:05:261012WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441013 // We use our current SiteInstance since the cloned entry will use it anyway.
[email protected]ed245db2012-12-18 08:00:451014 // We pass our own opener so that the cloned page can access it if it was
1015 // before.
[email protected]54944cde2012-12-09 09:24:591016 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451017 create_params.initial_size = GetContainerBounds().size();
[email protected]54944cde2012-12-09 09:24:591018 WebContentsImpl* tc = CreateWithOpener(create_params, opener_);
[email protected]d1198fd2012-08-13 22:50:191019 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221020 FOR_EACH_OBSERVER(WebContentsObserver,
1021 observers_,
1022 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271023 return tc;
1024}
1025
[email protected]14392a52012-05-02 20:28:441026void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211027 const NotificationSource& source,
1028 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441029 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211030 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1031 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]bafe6cd2012-05-23 23:09:501032 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1033 i != pending_widget_views_.end(); ++i) {
1034 if (host->GetView() == i->second) {
1035 pending_widget_views_.erase(i);
1036 break;
1037 }
1038 }
1039 break;
1040 }
[email protected]14392a52012-05-02 20:28:441041 default:
1042 NOTREACHED();
1043 }
1044}
1045
[email protected]ec6c05f2013-10-23 18:41:571046WebContents* WebContentsImpl::GetWebContents() {
1047 return this;
1048}
1049
[email protected]54944cde2012-12-09 09:24:591050void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211051 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361052 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211053 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431054 should_normally_be_visible_ = !params.initially_hidden;
1055
[email protected]fa944cb82013-11-15 17:51:211056 GetRenderManager()->Init(
[email protected]227692c52013-05-31 22:43:041057 params.browser_context, params.site_instance, params.routing_id,
1058 params.main_frame_routing_id);
[email protected]d1198fd2012-08-13 22:50:191059
[email protected]fc2b46b2014-05-03 16:33:451060 WebContentsViewDelegate* delegate =
1061 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1062
1063 if (browser_plugin_guest_) {
1064 scoped_ptr<WebContentsView> platform_view(CreateWebContentsView(
1065 this, delegate, &render_view_host_delegate_view_));
1066
1067 WebContentsViewGuest* rv = new WebContentsViewGuest(
1068 this, browser_plugin_guest_.get(), platform_view.Pass(),
1069 render_view_host_delegate_view_);
1070 render_view_host_delegate_view_ = rv;
1071 view_.reset(rv);
[email protected]d1198fd2012-08-13 22:50:191072 } else {
[email protected]fc2b46b2014-05-03 16:33:451073 // Regular WebContentsView.
1074 view_.reset(CreateWebContentsView(
1075 this, delegate, &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191076 }
[email protected]fc2b46b2014-05-03 16:33:451077 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191078 CHECK(view_.get());
1079
[email protected]ed245db2012-12-18 08:00:451080 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591081 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191082
1083 // Listen for whether our opener gets destroyed.
[email protected]7fff43e2013-05-21 20:21:101084 if (opener_)
1085 AddDestructionObserver(opener_);
[email protected]d1198fd2012-08-13 22:50:191086
1087 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211088 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1089 NotificationService::AllBrowserContextsAndSources());
[email protected]c7654a232013-06-12 21:04:441090#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101091 date_time_chooser_.reset(new DateTimeChooserAndroid());
1092#endif
[email protected]d1198fd2012-08-13 22:50:191093}
1094
[email protected]7fff43e2013-05-21 20:21:101095void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1096 RemoveDestructionObserver(web_contents);
1097
[email protected]14392a52012-05-02 20:28:441098 // Clear the opener if it has been closed.
1099 if (web_contents == opener_) {
[email protected]14392a52012-05-02 20:28:441100 opener_ = NULL;
[email protected]ceee8cd2013-03-08 04:59:511101 return;
[email protected]14392a52012-05-02 20:28:441102 }
[email protected]ceee8cd2013-03-08 04:59:511103 // Clear a pending contents that has been closed before being shown.
1104 for (PendingContents::iterator iter = pending_contents_.begin();
1105 iter != pending_contents_.end();
1106 ++iter) {
1107 if (iter->second != web_contents)
1108 continue;
1109 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511110 return;
1111 }
1112 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441113}
1114
[email protected]7fff43e2013-05-21 20:21:101115void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1116 if (!ContainsKey(destruction_observers_, web_contents)) {
1117 destruction_observers_[web_contents] =
1118 new DestructionObserver(this, web_contents);
1119 }
1120}
1121
1122void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1123 DestructionObservers::iterator iter =
1124 destruction_observers_.find(web_contents);
1125 if (iter != destruction_observers_.end()) {
1126 delete destruction_observers_[web_contents];
1127 destruction_observers_.erase(iter);
1128 }
1129}
1130
[email protected]b172aee2012-04-10 17:05:261131void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311132 observers_.AddObserver(observer);
1133}
1134
[email protected]b172aee2012-04-10 17:05:261135void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311136 observers_.RemoveObserver(observer);
1137}
1138
[email protected]b172aee2012-04-10 17:05:261139void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341140 if (delegate_)
1141 delegate_->ActivateContents(this);
1142}
1143
[email protected]b172aee2012-04-10 17:05:261144void WebContentsImpl::Deactivate() {
[email protected]ea42e7782010-08-23 23:58:121145 if (delegate_)
1146 delegate_->DeactivateContents(this);
1147}
1148
[email protected]b172aee2012-04-10 17:05:261149void WebContentsImpl::LostCapture() {
[email protected]63954792011-07-11 04:17:481150 if (delegate_)
1151 delegate_->LostCapture();
1152}
1153
[email protected]b24b68a2012-09-24 21:57:261154void WebContentsImpl::RenderWidgetDeleted(
1155 RenderWidgetHostImpl* render_widget_host) {
1156 if (is_being_destroyed_) {
1157 // |created_widgets_| might have been destroyed.
1158 return;
1159 }
1160
1161 std::set<RenderWidgetHostImpl*>::iterator iter =
1162 created_widgets_.find(render_widget_host);
1163 if (iter != created_widgets_.end())
1164 created_widgets_.erase(iter);
[email protected]44470a22013-01-24 01:21:541165
1166 if (render_widget_host &&
1167 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491168 if (delegate_ && delegate_->EmbedsFullscreenWidget())
1169 delegate_->ToggleFullscreenModeForTab(this, false);
[email protected]44470a22013-01-24 01:21:541170 FOR_EACH_OBSERVER(WebContentsObserver,
1171 observers_,
1172 DidDestroyFullscreenWidget(
1173 fullscreen_widget_routing_id_));
1174 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
1175 }
[email protected]b24b68a2012-09-24 21:57:261176}
1177
[email protected]b172aee2012-04-10 17:05:261178bool WebContentsImpl::PreHandleKeyboardEvent(
1179 const NativeWebKeyboardEvent& event,
1180 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481181 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131182 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481183}
1184
[email protected]b172aee2012-04-10 17:05:261185void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]6d5c060a2013-06-18 11:27:061186 if (browser_plugin_embedder_ &&
1187 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1188 return;
1189 }
1190
[email protected]63954792011-07-11 04:17:481191 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131192 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481193}
1194
[email protected]d92026ef2014-03-03 21:04:131195bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461196 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191197#if !defined(OS_MACOSX)
1198 // On platforms other than Mac, control+mousewheel changes zoom. On Mac, this
1199 // isn't done for two reasons:
1200 // -the OS already has a gesture to do this through pinch-zoom
1201 // -if a user starts an inertial scroll, let's go, and presses control
1202 // (i.e. control+tab) then the OS's buffered scroll events will come in
1203 // with control key set which isn't what the user wants
[email protected]fb3f066e2013-02-12 19:12:521204 if (delegate_ &&
1205 event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551206 (event.modifiers & blink::WebInputEvent::ControlKey) &&
1207 // Avoid adjusting the zoom in response to two-finger-scrolling touchpad
1208 // gestures, which are regrettably easy to trigger accidentally.
1209 !event.hasPreciseScrollingDeltas) {
[email protected]fb3f066e2013-02-12 19:12:521210 delegate_->ContentsZoomChange(event.wheelTicksY > 0);
1211 return true;
1212 }
[email protected]bccc4472013-04-18 16:37:191213#endif
[email protected]fb3f066e2013-02-12 19:12:521214 return false;
1215}
1216
[email protected]04bce562014-01-30 05:34:541217bool WebContentsImpl::PreHandleGestureEvent(
1218 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031219 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541220}
1221
[email protected]bab38af2014-03-30 17:37:291222bool WebContentsImpl::HandleGestureEvent(
1223 const blink::WebGestureEvent& event) {
1224 // Some platforms (eg. Mac) send GesturePinch events for trackpad pinch-zoom.
1225 // Use them to implement browser zoom, as for HandleWheelEvent above.
1226 if (event.type == blink::WebInputEvent::GesturePinchUpdate &&
1227 event.sourceDevice == blink::WebGestureEvent::Touchpad) {
1228 // The scale difference necessary to trigger a zoom action. Derived from
1229 // experimentation to find a value that feels reasonable.
1230 const float kZoomStepValue = 0.6f;
1231
1232 // Find the (absolute) thresholds on either side of the current zoom factor,
1233 // then convert those to actual numbers to trigger a zoom in or out.
1234 // This logic deliberately makes the range around the starting zoom value
1235 // for the gesture twice as large as the other ranges (i.e., the notches are
1236 // at ..., -3*step, -2*step, -step, step, 2*step, 3*step, ... but not at 0)
1237 // so that it's easier to get back to your starting point than it is to
1238 // overshoot.
1239 float nextStep = (abs(currentPinchZoomStepDelta_) + 1) * kZoomStepValue;
1240 float backStep = abs(currentPinchZoomStepDelta_) * kZoomStepValue;
1241 float zoomInThreshold = (currentPinchZoomStepDelta_ >= 0) ? nextStep
1242 : -backStep;
1243 float zoomOutThreshold = (currentPinchZoomStepDelta_ <= 0) ? -nextStep
1244 : backStep;
1245
[email protected]fb546cb2014-04-28 14:09:371246 totalPinchGestureAmount_ += (event.data.pinchUpdate.scale - 1.0);
[email protected]bab38af2014-03-30 17:37:291247 if (totalPinchGestureAmount_ > zoomInThreshold) {
1248 currentPinchZoomStepDelta_++;
[email protected]aa62afd2014-04-22 19:22:461249 if (delegate_)
1250 delegate_->ContentsZoomChange(true);
[email protected]bab38af2014-03-30 17:37:291251 } else if (totalPinchGestureAmount_ < zoomOutThreshold) {
1252 currentPinchZoomStepDelta_--;
[email protected]aa62afd2014-04-22 19:22:461253 if (delegate_)
1254 delegate_->ContentsZoomChange(false);
[email protected]bab38af2014-03-30 17:37:291255 }
1256 return true;
1257 }
1258
1259 return false;
1260}
1261
[email protected]2ceee8f2014-01-14 18:02:081262#if defined(OS_WIN)
[email protected]c73a2282013-04-29 21:10:411263gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() {
1264 return accessible_parent_;
1265}
1266#endif
1267
[email protected]b172aee2012-04-10 17:05:261268void WebContentsImpl::HandleMouseDown() {
[email protected]32ded2212011-11-10 18:51:431269 if (delegate_)
1270 delegate_->HandleMouseDown();
1271}
1272
[email protected]b172aee2012-04-10 17:05:261273void WebContentsImpl::HandleMouseUp() {
[email protected]63954792011-07-11 04:17:481274 if (delegate_)
1275 delegate_->HandleMouseUp();
1276}
1277
[email protected]590a634e2012-07-19 16:38:231278void WebContentsImpl::HandlePointerActivate() {
[email protected]63954792011-07-11 04:17:481279 if (delegate_)
[email protected]590a634e2012-07-19 16:38:231280 delegate_->HandlePointerActivate();
1281}
1282
1283void WebContentsImpl::HandleGestureBegin() {
1284 if (delegate_)
1285 delegate_->HandleGestureBegin();
1286}
1287
1288void WebContentsImpl::HandleGestureEnd() {
1289 if (delegate_)
1290 delegate_->HandleGestureEnd();
[email protected]63954792011-07-11 04:17:481291}
1292
[email protected]b172aee2012-04-10 17:05:261293void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) {
[email protected]4aebbca2013-09-17 22:26:491294 // This method is being called to enter or leave renderer-initiated fullscreen
1295 // mode. Either way, make sure any existing fullscreen widget is shut down
1296 // first.
1297 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
1298 if (widget_view)
1299 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())->Shutdown();
1300
[email protected]8a5e0ca2011-08-25 06:30:471301 if (delegate_)
1302 delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen);
[email protected]657c8e02014-03-19 19:18:371303
1304 FOR_EACH_OBSERVER(WebContentsObserver,
1305 observers_,
1306 DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab()));
[email protected]8a5e0ca2011-08-25 06:30:471307}
1308
[email protected]b172aee2012-04-10 17:05:261309bool WebContentsImpl::IsFullscreenForCurrentTab() const {
[email protected]199bba6e2012-04-04 16:19:381310 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121311}
1312
[email protected]a9c81f02012-06-01 00:15:441313void WebContentsImpl::RequestToLockMouse(bool user_gesture,
1314 bool last_unlocked_by_target) {
[email protected]e9621112011-10-17 05:38:371315 if (delegate_) {
[email protected]a9c81f02012-06-01 00:15:441316 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
[email protected]e9621112011-10-17 05:38:371317 } else {
1318 GotResponseToLockMouseRequest(false);
1319 }
1320}
1321
[email protected]b172aee2012-04-10 17:05:261322void WebContentsImpl::LostMouseLock() {
[email protected]e9621112011-10-17 05:38:371323 if (delegate_)
1324 delegate_->LostMouseLock();
1325}
1326
[email protected]bafe6cd2012-05-23 23:09:501327void WebContentsImpl::CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:201328 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:501329 int route_id,
[email protected]227692c52013-05-31 22:43:041330 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:131331 const ViewHostMsg_CreateWindow_Params& params,
1332 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501333 // We usually create the new window in the same BrowsingInstance (group of
1334 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551335 // if the opener is being suppressed (in a non-guest), we create a new
1336 // SiteInstance in its own BrowsingInstance.
1337 bool is_guest = GetRenderProcessHost()->IsGuest();
1338
[email protected]04cbd3d2013-12-04 04:58:201339 // If the opener is to be suppressed, the new window can be in any process.
1340 // Since routing ids are process specific, we must not have one passed in
1341 // as argument here.
1342 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1343
[email protected]bafe6cd2012-05-23 23:09:501344 scoped_refptr<SiteInstance> site_instance =
[email protected]c4538072013-03-18 02:17:551345 params.opener_suppressed && !is_guest ?
[email protected]e94bbcb2012-09-07 05:33:571346 SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) :
[email protected]bafe6cd2012-05-23 23:09:501347 GetSiteInstance();
1348
[email protected]04cbd3d2013-12-04 04:58:201349 // A message to create a new window can only come from the active process for
1350 // this WebContentsImpl instance. If any other process sends the request,
1351 // it is invalid and the process must be terminated.
1352 if (GetRenderProcessHost()->GetID() != render_process_id) {
1353 base::ProcessHandle process_handle =
1354 RenderProcessHost::FromID(render_process_id)->GetHandle();
1355 if (process_handle != base::kNullProcessHandle) {
1356 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391357 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
[email protected]04cbd3d2013-12-04 04:58:201358 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1359 }
1360 return;
1361 }
1362
[email protected]d1198fd2012-08-13 22:50:191363 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341364 //
1365 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301366 const std::string& partition_id =
1367 GetContentClient()->browser()->
1368 GetStoragePartitionIdForSite(GetBrowserContext(),
1369 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461370 StoragePartition* partition = BrowserContext::GetStoragePartition(
1371 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411372 DOMStorageContextWrapper* dom_storage_context =
1373 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191374 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1375 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1376 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371377
1378 if (delegate_ &&
1379 !delegate_->ShouldCreateWebContents(this,
1380 route_id,
1381 params.window_container_type,
1382 params.frame_name,
1383 params.target_url,
1384 partition_id,
1385 session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011386 if (route_id != MSG_ROUTING_NONE &&
1387 !RenderViewHost::FromID(render_process_id, route_id)) {
1388 // If the embedder didn't create a WebContents for this route, we need to
1389 // delete the RenderView that had already been created.
1390 Send(new ViewMsg_Close(route_id));
1391 }
[email protected]dd6730412013-08-14 15:03:371392 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(route_id);
1393 GetRenderViewHost()->GetProcess()->ResumeRequestsForView(
1394 main_frame_route_id);
1395 return;
1396 }
1397
1398 // Create the new web contents. This will automatically create the new
1399 // WebContentsView. In the future, we may want to create the view separately.
1400 WebContentsImpl* new_contents =
1401 new WebContentsImpl(GetBrowserContext(),
1402 params.opener_suppressed ? NULL : this);
1403
[email protected]d1198fd2012-08-13 22:50:191404 new_contents->GetController().SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:301405 partition_id,
[email protected]d1198fd2012-08-13 22:50:191406 session_storage_namespace);
[email protected]fc72bb12013-06-02 21:13:461407 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591408 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041409 create_params.main_frame_routing_id = main_frame_route_id;
[email protected]c4538072013-03-18 02:17:551410 if (!is_guest) {
1411 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451412 create_params.initial_size = GetContainerBounds().size();
[email protected]c4538072013-03-18 02:17:551413 } else {
1414 // This makes |new_contents| act as a guest.
1415 // For more info, see comment above class BrowserPluginGuest.
[email protected]24569262014-05-06 03:31:301416 int instance_id =
1417 BrowserPluginGuestManager::FromBrowserContext(GetBrowserContext())->
1418 GetNextInstanceID();
[email protected]c4538072013-03-18 02:17:551419 WebContentsImpl* new_contents_impl =
1420 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461421 BrowserPluginGuest::CreateWithOpener(instance_id,
1422 new_contents_impl->opener() != NULL,
1423 new_contents_impl,
1424 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551425 }
[email protected]1ac10dca2013-08-20 20:47:041426 if (params.disposition == NEW_BACKGROUND_TAB)
1427 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591428 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191429
[email protected]c4538072013-03-18 02:17:551430 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341431 // will be shown immediately).
1432 if (!params.opener_suppressed) {
1433 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451434 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501435
[email protected]d70bea92013-04-05 04:23:341436 // TODO(brettw): It seems bogus that we have to call this function on the
1437 // newly created object and give it one of its own member variables.
1438 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1439 }
[email protected]bafe6cd2012-05-23 23:09:501440 // Save the created window associated with the route so we can show it
1441 // later.
1442 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1443 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101444 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501445 }
1446
1447 if (delegate_) {
1448 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071449 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131450 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501451 }
1452
1453 if (params.opener_suppressed) {
1454 // When the opener is suppressed, the original renderer cannot access the
1455 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001456 bool was_blocked = false;
1457 if (delegate_) {
1458 gfx::Rect initial_pos;
1459 delegate_->AddNewContents(
1460 this, new_contents, params.disposition, initial_pos,
1461 params.user_gesture, &was_blocked);
1462 }
1463 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211464 OpenURLParams open_params(params.target_url,
1465 Referrer(),
1466 CURRENT_TAB,
1467 PAGE_TRANSITION_LINK,
1468 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301469 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001470 new_contents->OpenURL(open_params);
1471 }
[email protected]bafe6cd2012-05-23 23:09:501472 }
1473}
1474
[email protected]a8504022013-12-04 20:23:511475void WebContentsImpl::CreateNewWidget(int render_process_id,
1476 int route_id,
[email protected]180ef242013-11-07 06:50:461477 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511478 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501479}
1480
[email protected]a8504022013-12-04 20:23:511481void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1482 int route_id) {
1483 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501484}
1485
[email protected]a8504022013-12-04 20:23:511486void WebContentsImpl::CreateNewWidget(int render_process_id,
1487 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501488 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461489 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211490 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511491 // A message to create a new widget can only come from the active process for
1492 // this WebContentsImpl instance. If any other process sends the request,
1493 // it is invalid and the process must be terminated.
1494 if (process->GetID() != render_process_id) {
1495 base::ProcessHandle process_handle =
1496 RenderProcessHost::FromID(render_process_id)->GetHandle();
1497 if (process_handle != base::kNullProcessHandle) {
1498 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391499 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511500 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1501 }
1502 return;
1503 }
1504
[email protected]bafe6cd2012-05-23 23:09:501505 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041506 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261507 created_widgets_.insert(widget_host);
1508
[email protected]cfd80b02014-05-01 17:46:481509 RenderWidgetHostViewBase* widget_view =
1510 static_cast<RenderWidgetHostViewBase*>(
1511 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191512 if (!widget_view)
1513 return;
[email protected]bafe6cd2012-05-23 23:09:501514 if (!is_fullscreen) {
1515 // Popups should not get activated.
1516 widget_view->SetPopupType(popup_type);
1517 }
1518 // Save the created widget associated with the route so we can show it later.
1519 pending_widget_views_[route_id] = widget_view;
1520
1521#if defined(OS_MACOSX)
1522 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1523 // to allow it to survive the trip without being hosted.
1524 base::mac::NSObjectRetain(widget_view->GetNativeView());
1525#endif
1526}
1527
1528void WebContentsImpl::ShowCreatedWindow(int route_id,
1529 WindowOpenDisposition disposition,
1530 const gfx::Rect& initial_pos,
1531 bool user_gesture) {
1532 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001533 if (contents) {
1534 WebContentsDelegate* delegate = GetDelegate();
1535 if (delegate) {
1536 delegate->AddNewContents(
1537 this, contents, disposition, initial_pos, user_gesture, NULL);
1538 }
1539 }
[email protected]bafe6cd2012-05-23 23:09:501540}
1541
1542void WebContentsImpl::ShowCreatedWidget(int route_id,
1543 const gfx::Rect& initial_pos) {
1544 ShowCreatedWidget(route_id, false, initial_pos);
1545}
1546
1547void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1548 ShowCreatedWidget(route_id, true, gfx::Rect());
1549}
1550
1551void WebContentsImpl::ShowCreatedWidget(int route_id,
1552 bool is_fullscreen,
1553 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481554 RenderWidgetHostViewBase* widget_host_view =
1555 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501556 if (!widget_host_view)
1557 return;
[email protected]cfd80b02014-05-01 17:46:481558
1559 RenderWidgetHostView* view = NULL;
1560 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1561 if (guest && guest->embedder_web_contents()) {
1562 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1563 } else {
1564 view = GetRenderWidgetHostView();
1565 }
1566
[email protected]4aebbca2013-09-17 22:26:491567 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311568 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1569 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491570 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1571 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1572 delegate_->ToggleFullscreenModeForTab(this, true);
1573 } else {
[email protected]cfd80b02014-05-01 17:46:481574 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491575 }
[email protected]4aebbca2013-09-17 22:26:491576 FOR_EACH_OBSERVER(WebContentsObserver,
1577 observers_,
1578 DidShowFullscreenWidget(route_id));
1579 if (!widget_host_view->HasFocus())
1580 widget_host_view->Focus();
1581 } else {
[email protected]cfd80b02014-05-01 17:46:481582 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491583 }
[email protected]89054502012-06-03 10:29:241584
1585 RenderWidgetHostImpl* render_widget_host_impl =
1586 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1587 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311588 // Only allow privileged mouse lock for fullscreen render widget, which is
1589 // used to implement Pepper Flash fullscreen.
1590 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501591
1592#if defined(OS_MACOSX)
1593 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1594 // properly embedded (or purposefully ignored) we can release the retain we
1595 // took in CreateNewWidget().
1596 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1597#endif
1598}
1599
1600WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1601 PendingContents::iterator iter = pending_contents_.find(route_id);
1602
1603 // Certain systems can block the creation of new windows. If we didn't succeed
1604 // in creating one, just return NULL.
1605 if (iter == pending_contents_.end()) {
1606 return NULL;
1607 }
1608
1609 WebContentsImpl* new_contents = iter->second;
1610 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101611 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501612
[email protected]d70bea92013-04-05 04:23:341613 // Don't initialize the guest WebContents immediately.
1614 if (new_contents->GetRenderProcessHost()->IsGuest())
1615 return new_contents;
1616
[email protected]bafe6cd2012-05-23 23:09:501617 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1618 !new_contents->GetRenderViewHost()->GetView())
1619 return NULL;
1620
1621 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1622 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1623 return new_contents;
1624}
1625
1626RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1627 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1628 if (iter == pending_widget_views_.end()) {
1629 DCHECK(false);
1630 return NULL;
1631 }
1632
1633 RenderWidgetHostView* widget_host_view = iter->second;
1634 pending_widget_views_.erase(route_id);
1635
1636 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1637 if (!widget_host->GetProcess()->HasConnection()) {
1638 // The view has gone away or the renderer crashed. Nothing to do.
1639 return NULL;
1640 }
1641
1642 return widget_host_view;
1643}
1644
[email protected]f13b4202012-06-12 23:53:231645void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091646 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211647 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371648 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231649 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371650 } else {
1651 callback.Run(MediaStreamDevices(),
1652 MEDIA_DEVICE_INVALID_STATE,
1653 scoped_ptr<MediaStreamUI>());
1654 }
[email protected]f13b4202012-06-12 23:53:231655}
1656
[email protected]cc9200432013-07-23 23:02:401657SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1658 SiteInstance* instance) {
1659 return controller_.GetSessionStorageNamespace(instance);
1660}
1661
[email protected]9b159a52013-10-03 17:24:551662FrameTree* WebContentsImpl::GetFrameTree() {
1663 return &frame_tree_;
1664}
1665
[email protected]31a71eaf2014-03-13 01:47:361666void WebContentsImpl::AccessibilityEventReceived(
1667 const std::vector<AXEventNotificationDetails>& details) {
1668 FOR_EACH_OBSERVER(
1669 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1670}
1671
[email protected]edc3af82013-12-12 21:24:071672void WebContentsImpl::OnShowValidationMessage(
1673 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291674 const base::string16& main_text,
1675 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071676 if (delegate_)
1677 delegate_->ShowValidationMessage(
1678 this, anchor_in_root_view, main_text, sub_text);
1679}
1680
1681void WebContentsImpl::OnHideValidationMessage() {
1682 if (delegate_)
1683 delegate_->HideValidationMessage(this);
1684}
1685
1686void WebContentsImpl::OnMoveValidationMessage(
1687 const gfx::Rect& anchor_in_root_view) {
1688 if (delegate_)
1689 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1690}
1691
[email protected]32deec62013-05-15 23:55:041692void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1693 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441694 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041695}
1696
[email protected]b172aee2012-04-10 17:05:261697void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491698 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231699 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491700 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331701}
1702
[email protected]b172aee2012-04-10 17:05:261703void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341704 if (delegate_)
1705 delegate_->ResizeDueToAutoResize(this, new_size);
1706}
1707
[email protected]b172aee2012-04-10 17:05:261708WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201709 if (!delegate_)
1710 return NULL;
[email protected]00c37fc2011-08-02 00:22:501711
[email protected]e5d549d2011-12-28 01:29:201712 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201713 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341714}
1715
[email protected]6b618e62012-08-16 12:59:181716bool WebContentsImpl::Send(IPC::Message* message) {
1717 if (!GetRenderViewHost()) {
1718 delete message;
1719 return false;
1720 }
1721
1722 return GetRenderViewHost()->Send(message);
1723}
1724
[email protected]b172aee2012-04-10 17:05:261725bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501726 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261727 FrameTreeNode* node = frame_tree_.root();
1728
1729 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1730 // specified in the pending entry.
1731 NavigationEntryImpl* pending_entry =
1732 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1733 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1734 pending_entry->frame_tree_node_id() != -1) {
1735 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1736 }
1737
1738 return node->navigator()->NavigateToPendingEntry(
1739 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541740}
[email protected]96d185d2009-04-24 03:28:541741
[email protected]a86c0e962013-12-17 17:10:391742void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1743 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441744 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391745 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441746}
1747
[email protected]20ca0382013-02-28 19:50:071748void WebContentsImpl::AttachInterstitialPage(
1749 InterstitialPageImpl* interstitial_page) {
1750 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211751 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291752
1753 // Cancel any visible dialogs so that they don't interfere with the
1754 // interstitial.
1755 if (dialog_manager_)
1756 dialog_manager_->CancelActiveAndPendingDialogs(this);
1757
[email protected]20ca0382013-02-28 19:50:071758 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1759 DidAttachInterstitialPage());
1760}
1761
1762void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571763 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211764 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071765 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1766 DidDetachInterstitialPage());
1767}
1768
[email protected]b172aee2012-04-10 17:05:261769void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331770 const SiteInstance* site_instance,
1771 int history_length,
1772 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411773 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1774 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211775 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191776 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141777 return;
[email protected]9e1ad4b2011-08-14 16:49:191778 }
[email protected]9f76c1e2012-03-05 15:15:581779 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191780 if (!rvh) {
1781 NOTREACHED();
1782 return;
1783 }
[email protected]9f76c1e2012-03-05 15:15:581784 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191785 NOTREACHED();
1786 return;
1787 }
[email protected]6b618e62012-08-16 12:59:181788 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1789 history_length,
1790 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141791}
1792
[email protected]4fed3702014-04-01 09:08:001793void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171794 RenderFrameHost* focused_frame = GetFocusedFrame();
1795 if (!focused_frame)
1796 return;
1797
[email protected]959be4c2014-04-08 15:01:331798 focused_frame->Send(new FrameMsg_Reload(
1799 focused_frame->GetRoutingID(), ignore_cache));
1800}
1801
1802void WebContentsImpl::Undo() {
1803 RenderFrameHost* focused_frame = GetFocusedFrame();
1804 if (!focused_frame)
1805 return;
1806
1807 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1808 RecordAction(base::UserMetricsAction("Undo"));
1809}
1810
1811void WebContentsImpl::Redo() {
1812 RenderFrameHost* focused_frame = GetFocusedFrame();
1813 if (!focused_frame)
1814 return;
1815 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1816 RecordAction(base::UserMetricsAction("Redo"));
1817}
1818
1819void WebContentsImpl::Cut() {
1820 RenderFrameHost* focused_frame = GetFocusedFrame();
1821 if (!focused_frame)
1822 return;
1823
1824 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1825 RecordAction(base::UserMetricsAction("Cut"));
1826}
1827
1828void WebContentsImpl::Copy() {
1829 RenderFrameHost* focused_frame = GetFocusedFrame();
1830 if (!focused_frame)
1831 return;
1832
1833 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1834 RecordAction(base::UserMetricsAction("Copy"));
1835}
1836
1837void WebContentsImpl::CopyToFindPboard() {
1838#if defined(OS_MACOSX)
1839 RenderFrameHost* focused_frame = GetFocusedFrame();
1840 if (!focused_frame)
1841 return;
1842
1843 // Windows/Linux don't have the concept of a find pasteboard.
1844 focused_frame->Send(
1845 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1846 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1847#endif
1848}
1849
1850void WebContentsImpl::Paste() {
1851 RenderFrameHost* focused_frame = GetFocusedFrame();
1852 if (!focused_frame)
1853 return;
1854
1855 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1856 RecordAction(base::UserMetricsAction("Paste"));
1857}
1858
1859void WebContentsImpl::PasteAndMatchStyle() {
1860 RenderFrameHost* focused_frame = GetFocusedFrame();
1861 if (!focused_frame)
1862 return;
1863
1864 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1865 focused_frame->GetRoutingID()));
1866 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1867}
1868
1869void WebContentsImpl::Delete() {
1870 RenderFrameHost* focused_frame = GetFocusedFrame();
1871 if (!focused_frame)
1872 return;
1873
1874 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1875 RecordAction(base::UserMetricsAction("DeleteSelection"));
1876}
1877
1878void WebContentsImpl::SelectAll() {
1879 RenderFrameHost* focused_frame = GetFocusedFrame();
1880 if (!focused_frame)
1881 return;
1882
1883 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1884 RecordAction(base::UserMetricsAction("SelectAll"));
1885}
1886
1887void WebContentsImpl::Unselect() {
1888 RenderFrameHost* focused_frame = GetFocusedFrame();
1889 if (!focused_frame)
1890 return;
1891
1892 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1893 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171894}
1895
1896void WebContentsImpl::Replace(const base::string16& word) {
1897 RenderFrameHost* focused_frame = GetFocusedFrame();
1898 if (!focused_frame)
1899 return;
1900
[email protected]959be4c2014-04-08 15:01:331901 focused_frame->Send(new InputMsg_Replace(
1902 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171903}
1904
1905void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1906 RenderFrameHost* focused_frame = GetFocusedFrame();
1907 if (!focused_frame)
1908 return;
1909
[email protected]959be4c2014-04-08 15:01:331910 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1911 focused_frame->GetRoutingID(), word));
1912}
1913
1914void WebContentsImpl::NotifyContextMenuClosed(
1915 const CustomContextMenuContext& context) {
1916 RenderFrameHost* focused_frame = GetFocusedFrame();
1917 if (!focused_frame)
1918 return;
1919
1920 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1921 focused_frame->GetRoutingID(), context));
1922}
1923
1924void WebContentsImpl::ExecuteCustomContextMenuCommand(
1925 int action, const CustomContextMenuContext& context) {
1926 RenderFrameHost* focused_frame = GetFocusedFrame();
1927 if (!focused_frame)
1928 return;
1929
1930 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1931 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001932}
1933
[email protected]fc2b46b2014-05-03 16:33:451934gfx::NativeView WebContentsImpl::GetNativeView() {
1935 return view_->GetNativeView();
1936}
1937
1938gfx::NativeView WebContentsImpl::GetContentNativeView() {
1939 return view_->GetContentNativeView();
1940}
1941
1942gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1943 return view_->GetTopLevelNativeWindow();
1944}
1945
1946gfx::Rect WebContentsImpl::GetViewBounds() {
1947 return view_->GetViewBounds();
1948}
1949
1950gfx::Rect WebContentsImpl::GetContainerBounds() {
1951 gfx::Rect rv;
1952 view_->GetContainerBounds(&rv);
1953 return rv;
1954}
1955
1956DropData* WebContentsImpl::GetDropData() {
1957 return view_->GetDropData();
1958}
1959
1960void WebContentsImpl::Focus() {
1961 view_->Focus();
1962}
1963
1964void WebContentsImpl::SetInitialFocus() {
1965 view_->SetInitialFocus();
1966}
1967
1968void WebContentsImpl::StoreFocus() {
1969 view_->StoreFocus();
1970}
1971
1972void WebContentsImpl::RestoreFocus() {
1973 view_->RestoreFocus();
1974}
1975
[email protected]b172aee2012-04-10 17:05:261976void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271977 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211978 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541979 return;
1980 }
[email protected]9f76c1e2012-03-05 15:15:581981 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541982}
1983
[email protected]b172aee2012-04-10 17:05:261984bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211985 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541986}
1987
[email protected]b172aee2012-04-10 17:05:261988InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211989 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221990}
1991
[email protected]b172aee2012-04-10 17:05:261992bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161993 // WebKit creates Document object when MIME type is application/xhtml+xml,
1994 // so we also support this MIME type.
1995 return contents_mime_type_ == "text/html" ||
1996 contents_mime_type_ == "text/xml" ||
1997 contents_mime_type_ == "application/xhtml+xml" ||
1998 contents_mime_type_ == "text/plain" ||
1999 contents_mime_type_ == "text/css" ||
2000 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2001}
2002
[email protected]b172aee2012-04-10 17:05:262003void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592004 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162005 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552006 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012007 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142008 return;
[email protected]c7dd2f62011-07-18 15:57:592009 }
2010
2011 Stop();
2012
2013 // Create the save package and possibly prompt the user for the name to save
2014 // the page as. The user prompt is an asynchronous operation that runs on
2015 // another thread.
2016 save_package_ = new SavePackage(this);
2017 save_package_->GetSaveInfo();
2018}
2019
2020// Used in automated testing to bypass prompting the user for file names.
2021// Instead, the names and paths are hard coded rather than running them through
2022// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342023bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2024 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212025 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592026 // Stop the page from navigating.
2027 Stop();
2028
2029 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212030 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592031}
2032
[email protected]3c71576ce2013-07-23 02:00:012033void WebContentsImpl::SaveFrame(const GURL& url,
2034 const Referrer& referrer) {
2035 if (!GetURL().is_valid())
2036 return;
2037 bool is_main_frame = (url == GetURL());
2038
2039 DownloadManager* dlm =
2040 BrowserContext::GetDownloadManager(GetBrowserContext());
2041 if (!dlm)
2042 return;
2043 int64 post_id = -1;
2044 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272045 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012046 if (entry)
2047 post_id = entry->GetPostID();
2048 }
2049 scoped_ptr<DownloadUrlParameters> params(
2050 DownloadUrlParameters::FromWebContents(this, url));
2051 params->set_referrer(referrer);
2052 params->set_post_id(post_id);
2053 params->set_prefer_cache(true);
2054 if (post_id >= 0)
2055 params->set_method("POST");
2056 params->set_prompt(true);
2057 dlm->DownloadUrl(params.Pass());
2058}
2059
[email protected]b172aee2012-04-10 17:05:262060void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342061 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482062 const base::Callback<void(int64)>& callback) {
2063 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122064}
2065
[email protected]6286a372013-10-09 04:03:272066// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262067bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272068 NavigationEntryImpl* visible_entry =
2069 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2070 return (visible_entry != NULL &&
2071 visible_entry->site_instance() == GetSiteInstance() &&
2072 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322073}
2074
[email protected]b172aee2012-04-10 17:05:262075const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272076 return contents_mime_type_;
2077}
2078
[email protected]b172aee2012-04-10 17:05:262079bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272080 return notify_disconnection_;
2081}
2082
[email protected]b172aee2012-04-10 17:05:262083void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312084 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182085 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162086}
2087
[email protected]b172aee2012-04-10 17:05:262088void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542089 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182090 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162091}
2092
[email protected]8ff00d72012-10-23 19:12:212093RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272094 return &renderer_preferences_;
2095}
2096
[email protected]e35ccd52012-05-23 16:22:472097void WebContentsImpl::Close() {
2098 Close(GetRenderViewHost());
2099}
2100
[email protected]cf200a562013-05-03 16:24:292101void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462102 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292103 if (browser_plugin_embedder_.get())
2104 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2105 screen_x, screen_y, operation);
2106 if (GetRenderViewHost())
2107 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2108 screen_x, screen_y, operation);
2109}
2110
[email protected]d60f3702013-12-26 16:30:242111void WebContentsImpl::DidGetResourceResponseStart(
2112 const ResourceRequestDetails& details) {
2113 controller_.ssl_manager()->DidStartResourceResponse(details);
2114
2115 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2116 DidGetResourceResponseStart(details));
2117
2118 // TODO(avi): Remove. http://crbug.com/170921
2119 NotificationService::current()->Notify(
2120 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2121 Source<WebContents>(this),
2122 Details<const ResourceRequestDetails>(&details));
2123}
2124
2125void WebContentsImpl::DidGetRedirectForResourceRequest(
2126 RenderViewHost* render_view_host,
2127 const ResourceRedirectDetails& details) {
2128 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2129
2130 FOR_EACH_OBSERVER(
2131 WebContentsObserver,
2132 observers_,
2133 DidGetRedirectForResourceRequest(render_view_host, details));
2134
2135 // TODO(avi): Remove. http://crbug.com/170921
2136 NotificationService::current()->Notify(
2137 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2138 Source<WebContents>(this),
2139 Details<const ResourceRedirectDetails>(&details));
2140}
2141
[email protected]b172aee2012-04-10 17:05:262142void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522143 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582144 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512145 if (delegate_)
2146 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292147 if (browser_plugin_embedder_.get())
2148 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342149}
2150
[email protected]e35ccd52012-05-23 16:22:472151void WebContentsImpl::UserGestureDone() {
2152 OnUserGesture();
2153}
2154
[email protected]b172aee2012-04-10 17:05:262155void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272156 closed_by_user_gesture_ = value;
2157}
2158
[email protected]b172aee2012-04-10 17:05:262159bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272160 return closed_by_user_gesture_;
2161}
2162
[email protected]b172aee2012-04-10 17:05:262163double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052164 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562165 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252166 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172167 return 0;
[email protected]b75b8292010-10-01 07:28:252168
2169 double zoom_level;
2170 if (temporary_zoom_settings_) {
2171 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582172 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252173 } else {
[email protected]2ae88d12011-10-14 09:11:192174 GURL url;
[email protected]6286a372013-10-09 04:03:272175 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192176 // Since zoom map is updated using rewritten URL, use rewritten URL
2177 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272178 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022179 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2180 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252181 }
[email protected]d0b8d092010-10-25 04:05:172182 return zoom_level;
2183}
[email protected]b75b8292010-10-01 07:28:252184
[email protected]b172aee2012-04-10 17:05:262185int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592186 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172187 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012188 // Calculate the zoom percent from the factor. Round up to the nearest whole
2189 // number.
[email protected]b75b8292010-10-01 07:28:252190 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492191 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252192 *enable_decrement = percent > minimum_zoom_percent_;
2193 *enable_increment = percent < maximum_zoom_percent_;
2194 return percent;
2195}
2196
[email protected]b172aee2012-04-10 17:05:262197void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502198 if (!delegate_)
2199 return;
2200
[email protected]6286a372013-10-09 04:03:272201 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2202 if (!entry)
[email protected]1788e772010-12-15 16:40:502203 return;
2204
[email protected]6286a372013-10-09 04:03:272205 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122206}
2207
[email protected]b172aee2012-04-10 17:05:262208void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042209 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272210 if (!delegate_)
2211 return;
2212
[email protected]691aa2f2013-05-28 22:52:042213 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272214}
2215
[email protected]b172aee2012-04-10 17:05:262216int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272217 return minimum_zoom_percent_;
2218}
2219
[email protected]b172aee2012-04-10 17:05:262220int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272221 return maximum_zoom_percent_;
2222}
2223
[email protected]b172aee2012-04-10 17:05:262224gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492225 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232226}
2227
[email protected]b172aee2012-04-10 17:05:262228bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272229 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582230 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272231}
2232
[email protected]b172aee2012-04-10 17:05:262233bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442234 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502235}
2236
[email protected]cb805452013-05-22 15:16:212237void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482238 if (!color_chooser_info_.get())
2239 return;
2240 RenderFrameHost* rfh = RenderFrameHost::FromID(
2241 color_chooser_info_->render_process_id,
2242 color_chooser_info_->render_frame_id);
2243 if (!rfh)
2244 return;
2245
2246 rfh->Send(new FrameMsg_DidChooseColorResponse(
2247 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202248}
2249
[email protected]cb805452013-05-22 15:16:212250void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482251 if (!color_chooser_info_.get())
2252 return;
2253 RenderFrameHost* rfh = RenderFrameHost::FromID(
2254 color_chooser_info_->render_process_id,
2255 color_chooser_info_->render_frame_id);
2256 if (!rfh)
2257 return;
2258
2259 rfh->Send(new FrameMsg_DidEndColorChooser(
2260 rfh->GetRoutingID(), color_chooser_info_->identifier));
2261 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202262}
2263
[email protected]41225fe2013-03-29 05:32:022264int WebContentsImpl::DownloadImage(const GURL& url,
2265 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302266 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022267 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582268 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022269 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392270 return id;
2271}
2272
[email protected]5dcaf8e2013-12-28 01:31:422273bool WebContentsImpl::IsSubframe() const {
2274 return is_subframe_;
2275}
2276
[email protected]9649d492014-01-10 07:15:522277void WebContentsImpl::SetZoomLevel(double level) {
2278 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2279 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2280 if (embedder)
2281 embedder->SetZoomLevel(level);
2282}
2283
[email protected]36ec24f2014-01-09 00:32:082284void WebContentsImpl::Find(int request_id,
2285 const base::string16& search_text,
2286 const blink::WebFindOptions& options) {
2287 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2288}
2289
2290void WebContentsImpl::StopFinding(StopFindAction action) {
2291 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2292}
2293
[email protected]4fe53add2014-04-08 19:53:362294void WebContentsImpl::InsertCSS(const std::string& css) {
2295 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2296 GetMainFrame()->GetRoutingID(), css));
2297}
2298
[email protected]b172aee2012-04-10 17:05:262299bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272300 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202301 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332302 return true;
2303 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272304}
2305
[email protected]b172aee2012-04-10 17:05:262306void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272307 if (delegate_)
2308 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212309}
2310
[email protected]52913802013-12-10 05:52:182311void WebContentsImpl::DidStartProvisionalLoad(
2312 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072313 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182314 const GURL& validated_url,
2315 bool is_error_page,
2316 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262317 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182318 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572319 DidChangeLoadProgress(0);
2320
[email protected]0d60f0192011-04-14 12:40:102321 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272322 int render_frame_id = render_frame_host->GetRoutingID();
2323 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252324 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072325 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272326 render_frame_id, parent_routing_id, is_main_frame,
2327 validated_url, is_error_page, is_iframe_srcdoc,
2328 render_view_host));
[email protected]400992b2012-06-14 00:03:542329
2330 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182331 FOR_EACH_OBSERVER(
2332 WebContentsObserver,
2333 observers_,
2334 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582335 render_frame_host));
[email protected]400992b2012-06-14 00:03:542336 }
2337}
2338
[email protected]3109fbb72014-01-06 23:57:152339void WebContentsImpl::DidFailProvisionalLoadWithError(
2340 RenderFrameHostImpl* render_frame_host,
2341 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2342 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272343 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262344 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272345 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152346 FOR_EACH_OBSERVER(
2347 WebContentsObserver,
2348 observers_,
[email protected]161eabd2014-03-19 19:47:272349 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152350 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262351 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152352 validated_url,
2353 params.error_code,
2354 params.error_description,
[email protected]161eabd2014-03-19 19:47:272355 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152356}
2357
[email protected]b80624c2014-02-09 02:46:552358void WebContentsImpl::DidFailLoadWithError(
2359 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552360 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552361 int error_code,
2362 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272363 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262364 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272365 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552366 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272367 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262368 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552369}
2370
[email protected]52913802013-12-10 05:52:182371void WebContentsImpl::NotifyChangedNavigationState(
2372 InvalidateTypes changed_flags) {
2373 NotifyNavigationStateChanged(changed_flags);
2374}
2375
[email protected]3691e5cf2014-01-22 10:16:202376void WebContentsImpl::AboutToNavigateRenderFrame(
2377 RenderFrameHostImpl* render_frame_host) {
2378 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272379 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202380 FOR_EACH_OBSERVER(
2381 WebContentsObserver,
2382 observers_,
[email protected]161eabd2014-03-19 19:47:272383 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202384}
2385
2386void WebContentsImpl::DidStartNavigationToPendingEntry(
2387 RenderFrameHostImpl* render_frame_host,
2388 const GURL& url,
2389 NavigationController::ReloadType reload_type) {
2390 // Notify observers about navigation.
2391 FOR_EACH_OBSERVER(
2392 WebContentsObserver,
2393 observers_,
2394 DidStartNavigationToPendingEntry(url, reload_type));
2395}
2396
[email protected]8cb834e2014-03-06 14:23:232397void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2398 const OpenURLParams& params) {
2399 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182400 WebContents* new_contents = OpenURL(params);
2401
2402 if (new_contents) {
2403 // Notify observers.
2404 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2405 DidOpenRequestedURL(new_contents,
2406 params.url,
2407 params.referrer,
2408 params.disposition,
2409 params.transition,
[email protected]8cb834e2014-03-06 14:23:232410 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182411 }
2412}
2413
[email protected]aa62afd2014-04-22 19:22:462414bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2415 if (!delegate_)
2416 return false;
2417 return delegate_->ShouldPreserveAbortedURLs(this);
2418}
2419
[email protected]400992b2012-06-14 00:03:542420void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582421 RenderFrameHostImpl* render_frame_host,
2422 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542423 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582424 FOR_EACH_OBSERVER(
2425 WebContentsObserver,
2426 observers_,
2427 ProvisionalChangeToMainFrameUrl(validated_target_url,
2428 render_frame_host));
[email protected]724159a2010-12-30 01:11:182429}
2430
[email protected]37567b432014-02-12 01:12:222431void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432432 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222433 const base::string16& frame_unique_name,
2434 bool is_main_frame,
2435 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432436 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432437 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272438 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222439 // Notify observers about the commit of the provisional load.
2440 FOR_EACH_OBSERVER(
2441 WebContentsObserver,
2442 observers_,
[email protected]27dd82fd2014-03-03 22:11:432443 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222444 frame_unique_name,
2445 is_main_frame,
2446 url,
2447 transition_type,
2448 render_view_host));
2449}
2450
[email protected]0d0f4c492014-04-02 06:42:572451void WebContentsImpl::DidNavigateMainFramePreCommit(
2452 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2453 // Ensure fullscreen mode is exited before committing the navigation to a
2454 // different page. The next page will not start out assuming it is in
2455 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192456 if (controller_.IsURLInPageNavigation(params.url,
2457 params.was_within_same_page,
2458 NAVIGATION_TYPE_UNKNOWN)) {
2459 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572460 return;
2461 }
2462 if (IsFullscreenForCurrentTab())
2463 GetRenderViewHost()->ExitFullscreen();
2464 DCHECK(!IsFullscreenForCurrentTab());
2465}
2466
[email protected]37567b432014-02-12 01:12:222467void WebContentsImpl::DidNavigateMainFramePostCommit(
2468 const LoadCommittedDetails& details,
2469 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2470 if (details.is_navigation_to_different_page()) {
2471 // Clear the status bubble. This is a workaround for a bug where WebKit
2472 // doesn't let us know that the cursor left an element during a
2473 // transition (this is also why the mouse cursor remains as a hand after
2474 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2475 // clear the bubble when a user navigates to a named anchor in the same
2476 // page.
2477 UpdateTargetURL(details.entry->GetPageID(), GURL());
2478 }
2479
2480 if (!details.is_in_page) {
2481 // Once the main frame is navigated, we're no longer considered to have
2482 // displayed insecure content.
2483 displayed_insecure_content_ = false;
2484 SSLManager::NotifySSLInternalStateChanged(
2485 GetController().GetBrowserContext());
2486 }
2487
2488 // Notify observers about navigation.
2489 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2490 DidNavigateMainFrame(details, params));
2491
2492 if (delegate_) {
2493 delegate_->DidNavigateMainFramePostCommit(this);
2494 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2495 }
2496}
2497
2498void WebContentsImpl::DidNavigateAnyFramePostCommit(
2499 RenderFrameHostImpl* render_frame_host,
2500 const LoadCommittedDetails& details,
2501 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102502 // Now that something has committed, we don't need to track whether the
2503 // initial page has been accessed.
2504 has_accessed_initial_document_ = false;
2505
[email protected]37567b432014-02-12 01:12:222506 // If we navigate off the page, close all JavaScript dialogs.
2507 if (dialog_manager_ && !details.is_in_page)
2508 dialog_manager_->CancelActiveAndPendingDialogs(this);
2509
2510 // Notify observers about navigation.
2511 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2512 DidNavigateAnyFrame(details, params));
2513}
2514
2515void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2516 contents_mime_type_ = mime_type;
2517}
2518
2519bool WebContentsImpl::CanOverscrollContent() {
2520 if (delegate_)
2521 return delegate_->CanOverscrollContent();
2522
2523 return false;
2524}
2525
[email protected]b172aee2012-04-10 17:05:262526void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182527 const GURL& url,
[email protected]70435962011-08-02 20:13:282528 const std::string& security_info,
2529 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182530 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282531 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192532 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182533 cache.Increment();
2534
2535 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082536 int cert_id = 0;
2537 net::CertStatus cert_status = 0;
2538 int security_bits = -1;
2539 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122540 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212541 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122542 &security_bits, &connection_status,
2543 &signed_certificate_timestamp_ids);
2544 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212545 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002546 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2547 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182548
[email protected]b0f724c2013-09-05 04:21:132549 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2550
2551 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2552 DidLoadResourceFromMemoryCache(details));
2553
[email protected]8bfc8272013-09-09 20:10:532554 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2555 scoped_refptr<net::URLRequestContextGetter> request_context(
2556 resource_type == ResourceType::MEDIA ?
2557 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2558 GetRenderProcessHost()->GetID()) :
2559 GetBrowserContext()->GetRequestContextForRenderProcess(
2560 GetRenderProcessHost()->GetID()));
2561 BrowserThread::PostTask(
2562 BrowserThread::IO,
2563 FROM_HERE,
2564 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2565 }
[email protected]724159a2010-12-30 01:11:182566}
2567
[email protected]b172aee2012-04-10 17:05:262568void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392569 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182570 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192571 SSLManager::NotifySSLInternalStateChanged(
2572 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182573}
2574
[email protected]b172aee2012-04-10 17:05:262575void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022576 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582577 LOG(WARNING) << security_origin << " ran insecure content from "
2578 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392579 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412580 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392581 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182582 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412583 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192584 SSLManager::NotifySSLInternalStateChanged(
2585 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182586}
2587
[email protected]501052ff2014-02-21 22:19:072588void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572589 CHECK(render_frame_message_source_);
2590 CHECK(!render_view_message_source_);
2591 RenderFrameHostImpl* rfh =
2592 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2593
[email protected]161eabd2014-03-19 19:47:272594 int render_frame_id = rfh->GetRoutingID();
2595 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572596 FOR_EACH_OBSERVER(WebContentsObserver,
2597 observers_,
[email protected]161eabd2014-03-19 19:47:272598 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182599}
2600
[email protected]b172aee2012-04-10 17:05:262601void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262602 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372603 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122604 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2605 GetRenderProcessHost()->ReceivedBadMessage();
2606 return;
2607 }
[email protected]a1b99262013-12-27 21:56:222608
[email protected]8b3af1e2014-01-24 13:29:122609 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442610 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372611 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422612 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372613
[email protected]61ac9e242014-03-21 20:55:262614 RenderFrameHostImpl* rfh =
2615 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272616 int render_frame_id = rfh->GetRoutingID();
2617 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262618 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252619 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272620 DidFinishLoad(render_frame_id, validated_url,
2621 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312622}
2623
[email protected]b172aee2012-04-10 17:05:262624void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222625 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2626 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262627}
2628
[email protected]b172aee2012-04-10 17:05:262629void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2630 int maximum_percent,
2631 bool remember) {
[email protected]216813952011-05-19 22:21:262632 minimum_zoom_percent_ = minimum_percent;
2633 maximum_zoom_percent_ = maximum_percent;
2634 temporary_zoom_settings_ = !remember;
2635}
2636
[email protected]b172aee2012-04-10 17:05:262637void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342638 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432639 if (!delegate_)
2640 return;
2641
[email protected]b9535422012-02-09 01:47:592642 ChildProcessSecurityPolicyImpl* policy =
2643 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222644 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592645 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212646}
2647
[email protected]b172aee2012-04-10 17:05:262648void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2649 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262650 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362651 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432652 if (!delegate_)
2653 return;
2654
[email protected]b9535422012-02-09 01:47:592655 ChildProcessSecurityPolicyImpl* policy =
2656 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322657 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592658 return;
[email protected]8f810632013-06-06 22:33:322659
[email protected]c125e532014-05-10 20:39:062660 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202661}
2662
[email protected]b172aee2012-04-10 17:05:262663void WebContentsImpl::OnFindReply(int request_id,
2664 int number_of_matches,
2665 const gfx::Rect& selection_rect,
2666 int active_match_ordinal,
2667 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432668 if (delegate_) {
2669 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2670 active_match_ordinal, final_update);
2671 }
[email protected]b888919c2011-09-02 00:32:162672}
2673
[email protected]59363fc92012-09-05 03:46:312674#if defined(OS_ANDROID)
2675void WebContentsImpl::OnFindMatchRectsReply(
2676 int version,
2677 const std::vector<gfx::RectF>& rects,
2678 const gfx::RectF& active_rect) {
2679 if (delegate_)
2680 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2681}
[email protected]583418cc2013-01-17 14:01:102682
[email protected]1ff427972013-02-07 21:14:072683void WebContentsImpl::OnOpenDateTimeDialog(
2684 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092685 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2686 GetRenderViewHost(),
2687 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132688 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092689 value.minimum,
2690 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172691 value.step,
2692 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102693}
2694
[email protected]59363fc92012-09-05 03:46:312695#endif
2696
[email protected]f114fa42013-12-06 17:06:442697void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2698 const base::FilePath& path,
2699 bool is_hung) {
2700 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2701
2702 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2703 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2704}
2705
2706void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422707 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442708 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422709 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452710}
2711
[email protected]cfa856d62014-02-22 07:58:402712void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2713 int automation_id) {
2714 DomOperationNotificationDetails details(json_string, automation_id);
2715 NotificationService::current()->Notify(
2716 NOTIFICATION_DOM_OPERATION_RESPONSE,
2717 Source<WebContents>(this),
2718 Details<DomOperationNotificationDetails>(&details));
2719}
2720
[email protected]b172aee2012-04-10 17:05:262721void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2722 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102723 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252724 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102725 AppCacheAccessed(manifest_url, blocked_by_policy));
2726}
2727
[email protected]8bc5ff02013-11-29 06:34:032728void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482729 int color_chooser_id,
2730 SkColor color,
2731 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462732 ColorChooser* new_color_chooser = delegate_ ?
2733 delegate_->OpenColorChooser(this, color, suggestions) :
2734 NULL;
[email protected]820957a2014-01-14 14:56:302735 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212736 return;
[email protected]8ed16472014-04-11 19:02:482737 if (color_chooser_info_.get())
2738 color_chooser_info_->chooser->End();
2739
2740 color_chooser_info_.reset(new ColorChooserInfo(
2741 render_frame_message_source_->GetProcess()->GetID(),
2742 render_frame_message_source_->GetRoutingID(),
2743 new_color_chooser,
2744 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202745}
2746
[email protected]b172aee2012-04-10 17:05:262747void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482748 if (color_chooser_info_ &&
2749 color_chooser_id == color_chooser_info_->identifier)
2750 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202751}
2752
[email protected]b172aee2012-04-10 17:05:262753void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322754 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482755 if (color_chooser_info_ &&
2756 color_chooser_id == color_chooser_info_->identifier)
2757 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202758}
2759
[email protected]d0759f492012-04-19 22:50:502760// This exists for render views that don't have a WebUI, but do have WebUI
2761// bindings enabled.
2762void WebContentsImpl::OnWebUISend(const GURL& source_url,
2763 const std::string& name,
2764 const base::ListValue& args) {
2765 if (delegate_)
2766 delegate_->WebUISend(this, source_url, name, args);
2767}
2768
[email protected]d8415ad92012-08-23 14:40:502769void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442770 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502771 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342772 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162773 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442774 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162775 return;
[email protected]d8415ad92012-08-23 14:40:502776 }
2777
[email protected]8c8fc292012-11-23 18:57:162778 if (!delegate_->RequestPpapiBrokerPermission(
2779 this, url, plugin_path,
2780 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442781 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162782 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442783 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162784 }
[email protected]d8415ad92012-08-23 14:40:502785}
2786
[email protected]ea0309c2013-08-06 19:35:442787void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502788 bool result) {
[email protected]ea0309c2013-08-06 19:35:442789 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502790}
2791
[email protected]c4538072013-03-18 02:17:552792void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372793 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082794 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552795 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392796 // For more info, see comment above classes BrowserPluginEmbedder and
2797 // BrowserPluginGuest.
2798 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142799 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082800 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372801}
2802
[email protected]41225fe2013-03-29 05:32:022803void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392804 int id,
[email protected]749fadd2013-05-15 08:37:482805 int http_status_code,
[email protected]795c28972012-12-06 06:13:392806 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302807 const std::vector<SkBitmap>& bitmaps,
2808 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132809 if (bitmaps.size() != original_bitmap_sizes.size())
2810 return;
2811
[email protected]41225fe2013-03-29 05:32:022812 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2813 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392814 // Currently WebContents notifies us of ANY downloads so that it is
2815 // possible to get here.
2816 return;
2817 }
2818 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302819 iter->second.Run(
2820 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392821 }
[email protected]41225fe2013-03-29 05:32:022822 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392823}
2824
2825void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392826 const std::vector<FaviconURL>& candidates) {
2827 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292828 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392829}
2830
[email protected]1dd0bb752014-02-01 01:16:262831void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2832 bool has_video,
2833 bool has_audio) {
2834// Chrome OS does its own detection of audio and video.
2835#if !defined(OS_CHROMEOS)
2836 scoped_ptr<PowerSaveBlocker> blocker;
2837 if (has_video) {
2838 blocker = PowerSaveBlocker::Create(
2839 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2840#if defined(OS_ANDROID)
2841 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2842 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2843#endif
2844 } else if (has_audio) {
2845 blocker = PowerSaveBlocker::Create(
2846 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2847 }
2848
2849 if (blocker) {
[email protected]96307312014-05-04 01:00:192850 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262851 blocker.release();
2852 }
2853#endif // !defined(OS_CHROMEOS)
2854}
2855
2856void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062857 // Chrome OS does its own detection of audio and video.
2858#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192859 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2860 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062861#endif // !defined(OS_CHROMEOS)
2862}
2863
[email protected]50279492014-05-05 23:24:292864void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152865 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292866 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152867}
[email protected]d9030b82013-07-19 08:26:062868
[email protected]e67ebf32013-02-13 11:07:192869void WebContentsImpl::DidChangeVisibleSSLState() {
2870 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2871 DidChangeVisibleSSLState());
2872}
2873
[email protected]17e286e2013-03-01 23:29:392874void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2875 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2876 BeforeFormRepostWarningShow());
2877}
2878
[email protected]ec6c05f2013-10-23 18:41:572879
2880void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2881 Activate();
2882 if (delegate_)
2883 delegate_->ShowRepostFormWarningDialog(this);
2884}
2885
[email protected]b4c84012014-04-28 19:51:102886bool WebContentsImpl::HasAccessedInitialDocument() {
2887 return has_accessed_initial_document_;
2888}
2889
[email protected]96d185d2009-04-24 03:28:542890// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592891// loading, or done loading.
2892void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2893 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092894 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262895 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542896 if (is_loading == is_loading_)
2897 return;
2898
2899 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262900 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2901 base::string16());
[email protected]96d185d2009-04-24 03:28:542902 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562903 upload_size_ = 0;
2904 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542905 }
2906
[email protected]fa944cb82013-11-15 17:51:212907 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542908
2909 is_loading_ = is_loading;
2910 waiting_for_response_ = is_loading;
2911
[email protected]6ebdc9b2010-09-27 16:55:572912 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092913 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212914 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542915
[email protected]eab61442013-11-14 18:35:482916 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592917 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482918 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2919 "URL", url);
[email protected]91621872013-10-08 04:04:592920 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2921 DidStartLoading(render_view_host));
2922 } else {
[email protected]eab61442013-11-14 18:35:482923 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2924 "URL", url);
[email protected]91621872013-10-08 04:04:592925 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2926 DidStopLoading(render_view_host));
2927 }
[email protected]66798902013-10-01 18:40:162928
2929 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212930 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2931 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542932 if (details)
[email protected]8ff00d72012-10-23 19:12:212933 det = Details<LoadNotificationDetails>(details);
2934 NotificationService::current()->Notify(
2935 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542936}
2937
[email protected]959be4c2014-04-08 15:01:332938void WebContentsImpl::SelectRange(const gfx::Point& start,
2939 const gfx::Point& end) {
2940 RenderFrameHost* focused_frame = GetFocusedFrame();
2941 if (!focused_frame)
2942 return;
2943
2944 focused_frame->Send(
2945 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
2946}
2947
[email protected]b172aee2012-04-10 17:05:262948void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462949 // If we are creating a RVH for a restored controller, then we need to make
2950 // sure the RenderView starts with a next_page_id_ larger than the number
2951 // of restored entries. This must be called before the RenderView starts
2952 // navigating (to avoid a race between the browser updating max_page_id and
2953 // the renderer updating next_page_id_). Because of this, we only call this
2954 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562955 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582956 if (max_restored_page_id >
2957 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2958 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2959 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322960}
2961
[email protected]b172aee2012-04-10 17:05:262962bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262963 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322964 // For file URLs without a title, use the pathname instead. In the case of a
2965 // synthesized title, we don't want the update to count toward the "one set
2966 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262967 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322968 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512969 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242970 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322971 explicit_set = false; // Don't count synthetic titles toward the set limit.
2972 } else {
[email protected]8af69c6c2014-03-03 19:05:312973 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322974 explicit_set = true;
2975 }
2976
[email protected]987fc3a2011-05-26 14:18:092977 // If a page is created via window.open and never navigated,
2978 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552979 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092980 if (entry) {
[email protected]36fc0392011-12-25 03:59:512981 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092982 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322983
[email protected]36fc0392011-12-25 03:59:512984 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092985 } else {
2986 if (page_title_when_no_navigation_entry_ == final_title)
2987 return false; // Nothing changed, don't bother.
2988
2989 page_title_when_no_navigation_entry_ = final_title;
2990 }
[email protected]420ae012009-04-24 05:16:322991
[email protected]420ae012009-04-24 05:16:322992 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232993 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322994
[email protected]66798902013-10-01 18:40:162995 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532996 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162997
2998 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212999 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:463000 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213001 NotificationService::current()->Notify(
3002 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3003 Source<WebContents>(this),
3004 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043005
[email protected]420ae012009-04-24 05:16:323006 return true;
3007}
3008
[email protected]7b712ee22013-10-03 00:57:283009void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
3010 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323011 // After sending out a swap notification, we need to send a disconnect
3012 // notification so that clients that pick up a pointer to |this| can NULL the
3013 // pointer. See Bug 1230284.
3014 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113015 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283016 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113017
3018 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283019 std::pair<RenderViewHost*, RenderViewHost*> details =
3020 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213021 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283022 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213023 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283024 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393025
3026 // Ensure that the associated embedder gets cleared after a RenderViewHost
3027 // gets swapped, so we don't reuse the same embedder next time a
3028 // RenderViewHost is attached to this WebContents.
3029 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323030}
3031
[email protected]da7a7182013-09-06 08:11:113032// TODO(avi): Remove this entire function because this notification is already
3033// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263034void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323035 if (!notify_disconnection_)
3036 return;
3037
3038 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213039 NotificationService::current()->Notify(
3040 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3041 Source<WebContents>(this),
3042 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323043}
3044
[email protected]cbb1ef592013-06-05 19:49:463045void WebContentsImpl::NotifyNavigationEntryCommitted(
3046 const LoadCommittedDetails& load_details) {
3047 FOR_EACH_OBSERVER(
3048 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3049}
3050
[email protected]f114fa42013-12-06 17:06:443051bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3052 const IPC::Message& message) {
3053 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313054}
3055
[email protected]c31a84802014-04-03 15:55:493056const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3057 return GetLastCommittedURL();
3058}
3059
[email protected]b849847b2013-12-10 21:57:583060void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3061 // Note this is only for subframes, the notification for the main frame
3062 // happens in RenderViewCreated.
3063 FOR_EACH_OBSERVER(WebContentsObserver,
3064 observers_,
3065 RenderFrameCreated(render_frame_host));
3066}
3067
3068void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193069 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583070 FOR_EACH_OBSERVER(WebContentsObserver,
3071 observers_,
3072 RenderFrameDeleted(render_frame_host));
3073}
3074
[email protected]a09d53ce2014-01-31 00:46:423075void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303076 if (delegate_)
3077 delegate_->WorkerCrashed(this);
3078}
3079
[email protected]a09d53ce2014-01-31 00:46:423080void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3081 const ContextMenuParams& params) {
3082 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:403083 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:423084 return;
3085
3086 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
3087}
3088
[email protected]87de04b02014-04-08 22:14:493089void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013090 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493091 const base::string16& message,
3092 const base::string16& default_prompt,
3093 const GURL& frame_url,
3094 JavaScriptMessageType javascript_message_type,
3095 IPC::Message* reply_msg) {
3096 // Suppress JavaScript dialogs when requested. Also suppress messages when
3097 // showing an interstitial as it's shown over the previous page and we don't
3098 // want the hidden page's dialogs to interfere with the interstitial.
3099 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013100 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493101 IsSwappedOut() ||
3102 ShowingInterstitialPage() ||
3103 !delegate_ ||
3104 delegate_->ShouldSuppressDialogs() ||
3105 !delegate_->GetJavaScriptDialogManager();
3106
3107 if (!suppress_this_message) {
3108 std::string accept_lang = GetContentClient()->browser()->
3109 GetAcceptLangs(GetBrowserContext());
3110 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3111 dialog_manager_->RunJavaScriptDialog(
3112 this,
3113 frame_url.GetOrigin(),
3114 accept_lang,
3115 javascript_message_type,
3116 message,
3117 default_prompt,
3118 base::Bind(&WebContentsImpl::OnDialogClosed,
3119 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013120 render_frame_host->GetProcess()->GetID(),
3121 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493122 reply_msg,
3123 false),
3124 &suppress_this_message);
3125 }
3126
3127 if (suppress_this_message) {
3128 // If we are suppressing messages, just reply as if the user immediately
3129 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013130 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3131 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283132 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493133 }
3134
3135 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3136 // http://crbug.com/288961 ). The only safe thing to do here is return.
3137}
3138
3139void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013140 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493141 const base::string16& message,
3142 bool is_reload,
3143 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013144 RenderFrameHostImpl* rfhi =
3145 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493146 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013147 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493148 if (delegate_)
3149 delegate_->WillRunBeforeUnloadConfirm();
3150
3151 bool suppress_this_message =
3152 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3153 !delegate_ ||
3154 delegate_->ShouldSuppressDialogs() ||
3155 !delegate_->GetJavaScriptDialogManager();
3156 if (suppress_this_message) {
3157 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3158 return;
3159 }
3160
3161 is_showing_before_unload_dialog_ = true;
3162 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3163 dialog_manager_->RunBeforeUnloadDialog(
3164 this, message, is_reload,
3165 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013166 render_frame_host->GetProcess()->GetID(),
3167 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283168 false));
[email protected]87de04b02014-04-08 22:14:493169}
3170
[email protected]a86c0e962013-12-17 17:10:393171WebContents* WebContentsImpl::GetAsWebContents() {
3172 return this;
3173}
3174
[email protected]7912e822014-04-16 02:37:033175bool WebContentsImpl::IsNeverVisible() {
3176 if (!delegate_)
3177 return false;
3178 return delegate_->IsNeverVisible(this);
3179}
3180
[email protected]5a3bdf52012-05-24 15:12:573181RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3182 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323183}
3184
[email protected]8ff00d72012-10-23 19:12:213185RendererPreferences WebContentsImpl::GetRendererPrefs(
3186 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463187 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513188}
3189
[email protected]b172aee2012-04-10 17:05:263190gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173191 if (delegate_)
3192 return delegate_->GetRootWindowResizerRect();
3193 return gfx::Rect();
3194}
3195
[email protected]7a846df2012-09-20 19:17:393196void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273197 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393198 browser_plugin_embedder_.reset();
3199}
3200
[email protected]b172aee2012-04-10 17:05:263201void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443202 // Don't send notifications if we are just creating a swapped-out RVH for
3203 // the opener chain. These won't be used for view-source or WebUI, so it's
3204 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243205 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443206 return;
3207
[email protected]86f98a22013-03-20 14:35:003208 if (delegate_)
3209 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083210
[email protected]8ff00d72012-10-23 19:12:213211 NotificationService::current()->Notify(
3212 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3213 Source<WebContents>(this),
3214 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323215
3216 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353217 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213218 if (GetRenderManager()->pending_web_ui())
3219 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323220
[email protected]6286a372013-10-09 04:03:273221 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333222 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323223 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183224 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583225 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323226 }
[email protected]0666aef2009-05-13 19:48:083227
[email protected]60780f412013-02-25 16:34:103228 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263229
3230 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253231 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583232
3233 // We tell the observers now instead of when the main RenderFrameHostImpl is
3234 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3235 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363236 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583237 FOR_EACH_OBSERVER(
3238 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323239}
3240
[email protected]b172aee2012-04-10 17:05:263241void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523242 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323243 // Don't notify the world, since this came from a renderer in the
3244 // background.
3245 return;
3246 }
3247
[email protected]da7a7182013-09-06 08:11:113248 notify_disconnection_ = true;
3249 // TODO(avi): Remove. http://crbug.com/170921
3250 NotificationService::current()->Notify(
3251 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3252 Source<WebContents>(this),
3253 NotificationService::NoDetails());
3254
[email protected]be1f56ab2011-12-22 06:55:313255 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233256 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303257
3258 // Restore the focus to the tab (otherwise the focus will be on the top
3259 // window).
[email protected]484ae5912010-09-29 19:16:143260 if (was_crashed && !FocusLocationBarByDefault() &&
3261 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063262 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143263 }
[email protected]32ded2212011-11-10 18:51:433264
[email protected]d8c660432011-12-22 20:51:253265 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323266}
3267
[email protected]ec6a7eb2013-04-22 17:34:223268void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3269 base::TerminationStatus status,
3270 int error_code) {
[email protected]151a63d2011-12-20 22:32:523271 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323272 // The pending page's RenderViewHost is gone.
3273 return;
3274 }
3275
[email protected]2fcdcc32014-03-05 02:14:073276 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3277 // renderer may not have made a clean exit.
3278 if (IsFullscreenForCurrentTab())
3279 ToggleFullscreenMode(false);
3280
[email protected]698191dc2014-02-25 01:06:133281 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3282 if (dialog_manager_)
3283 dialog_manager_->CancelActiveAndPendingDialogs(this);
3284
[email protected]e3b10d12014-03-28 16:06:093285 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323286 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233287 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453288
3289#if defined(OS_ANDROID)
3290 if (GetRenderViewHostImpl()->media_player_manager())
3291 GetRenderViewHostImpl()->media_player_manager()->DestroyAllMediaPlayers();
3292#endif
[email protected]420ae012009-04-24 05:16:323293
[email protected]d8c660432011-12-22 20:51:253294 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273295 observers_,
[email protected]58d5cfe2013-07-10 02:40:523296 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323297}
3298
[email protected]b172aee2012-04-10 17:05:263299void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253300 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063301}
3302
[email protected]b172aee2012-04-10 17:05:263303void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3304 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043305 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153306 // Ensure that this state update comes from either the active RVH or one of
3307 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413308 // TODO(nasko): This should go through RenderFrameHost.
3309 // TODO(creis): We can't update state for cross-process subframes until we
3310 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3311 if (rvh != GetRenderViewHost() &&
3312 !GetRenderManager()->IsRVHOnSwappedOutList(
3313 static_cast<RenderViewHostImpl*>(rvh)))
3314 return;
[email protected]420ae012009-04-24 05:16:323315
3316 // We must be prepared to handle state updates for any page, these occur
3317 // when the user is scrolling and entering form data, as well as when we're
3318 // leaving a page, in which case our state may have already been moved to
3319 // the next page. The navigation controller will look up the appropriate
3320 // NavigationEntry and update it when it is notified via the delegate.
3321
3322 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583323 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323324 if (entry_index < 0)
3325 return;
[email protected]10f417c52011-12-28 21:04:233326 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323327
[email protected]691aa2f2013-05-28 22:52:043328 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323329 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043330 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323331 controller_.NotifyEntryChanged(entry, entry_index);
3332}
3333
[email protected]b172aee2012-04-10 17:05:263334void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513335 if (delegate_)
3336 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323337}
3338
[email protected]b172aee2012-04-10 17:05:263339void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103340#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293341 // The UI may be in an event-tracking loop, such as between the
3342 // mouse-down and mouse-up in text selection or a button click.
3343 // Defer the close until after tracking is complete, so that we
3344 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293345 // TODO(shess): This could get more fine-grained. For instance,
3346 // closing a tab in another window while selecting text in the
3347 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103348 if (view_->IsEventTracking()) {
3349 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293350 return;
3351 }
[email protected]60780f412013-02-25 16:34:103352#endif
[email protected]07707302009-11-06 00:50:293353
[email protected]420ae012009-04-24 05:16:323354 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523355 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513356 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323357}
3358
[email protected]66bbadaf2014-03-28 16:25:543359void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573360 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3361 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573362}
3363
[email protected]b172aee2012-04-10 17:05:263364void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513365 if (delegate_ && delegate_->IsPopupOrPanel(this))
3366 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323367}
3368
[email protected]e3b10d12014-03-28 16:06:093369void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3370 bool to_different_document) {
3371 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3372 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323373}
3374
[email protected]723971b2014-02-12 11:08:253375void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323376 scoped_ptr<LoadNotificationDetails> details;
3377
[email protected]9595fd82013-04-19 21:28:493378 // Use the last committed entry rather than the active one, in case a
3379 // pending entry has been created.
3380 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203381 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493382
[email protected]420ae012009-04-24 05:16:323383 // An entry may not exist for a stop when loading an initial blank page or
3384 // if an iframe injected by script into a blank page finishes loading.
3385 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203386 base::TimeDelta elapsed =
3387 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323388
3389 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513390 entry->GetVirtualURL(),
3391 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323392 elapsed,
3393 &controller_,
3394 controller_.GetCurrentEntryIndex()));
3395 }
3396
[email protected]e3b10d12014-03-28 16:06:093397 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3398 details.get());
[email protected]420ae012009-04-24 05:16:323399}
3400
[email protected]b172aee2012-04-10 17:05:263401void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163402 controller_.DiscardNonCommittedEntries();
3403
3404 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213405 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163406}
3407
[email protected]b172aee2012-04-10 17:05:263408void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513409 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133410 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403411}
3412
[email protected]59167c22013-06-03 18:07:323413void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103414 has_accessed_initial_document_ = true;
3415
[email protected]d1371bf8e2014-04-19 03:26:243416 // We may have left a failed browser-initiated navigation in the address bar
3417 // to let the user edit it and try again. Clear it now that content might
3418 // show up underneath it.
3419 if (!IsLoading() && controller_.GetPendingEntry())
3420 controller_.DiscardPendingEntry();
3421
[email protected]59167c22013-06-03 18:07:323422 // Update the URL display.
3423 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3424}
3425
[email protected]3f19f1a2014-05-02 05:23:273426void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3427 if (opener_) {
3428 // Clear our opener so that future cross-process navigations don't have an
3429 // opener assigned.
3430 RemoveDestructionObserver(opener_);
3431 opener_ = NULL;
3432 }
3433
3434 // Notify all swapped out RenderViewHosts for this tab. This is important
3435 // in case we go back to them, or if another window in those processes tries
3436 // to access window.opener.
3437 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3438}
3439
[email protected]39f2f9252014-05-03 00:54:013440void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293441 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093442 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293443 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093444
3445 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213446 NotificationService::current()->Notify(
3447 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3448 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293449 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083450}
3451
[email protected]ef3adfc2014-05-11 00:04:543452void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3453 int32 page_id,
3454 const base::string16& title,
3455 base::i18n::TextDirection title_direction) {
3456 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3457
3458 // If we have a title, that's a pretty good indication that we've started
3459 // getting useful data.
3460 SetNotWaitingForResponse();
3461
3462 // Try to find the navigation entry, which might not be the current one.
3463 // For example, it might be from a pending RVH for the pending entry.
3464 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3465 rvh->GetSiteInstance(), page_id);
3466
3467 // We can handle title updates when we don't have an entry in
3468 // UpdateTitleForEntry, but only if the update is from the current RVH.
3469 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3470 if (!entry && rvh != GetRenderViewHost())
3471 return;
3472
3473 // TODO(evan): make use of title_direction.
3474 // http://code.google.com/p/chromium/issues/detail?id=27094
3475 if (!UpdateTitleForEntry(entry, title))
3476 return;
3477
3478 // Broadcast notifications when the UI should be updated.
3479 if (entry == controller_.GetEntryAtOffset(0))
3480 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3481}
3482
3483void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3484 const std::string& encoding) {
3485 SetEncoding(encoding);
3486}
3487
[email protected]39f2f9252014-05-03 00:54:013488void WebContentsImpl::DocumentAvailableInMainFrame(
3489 RenderViewHost* render_view_host) {
3490 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3491 DocumentAvailableInMainFrame());
3492}
[email protected]e1c3a552012-05-04 20:51:323493void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3494 // Tell the active RenderViewHost to run unload handlers and close, as long
3495 // as the request came from a RenderViewHost in the same BrowsingInstance.
3496 // In most cases, we receive this from a swapped out RenderViewHost.
3497 // It is possible to receive it from one that has just been swapped in,
3498 // in which case we might as well deliver the message anyway.
3499 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3500 GetRenderViewHost()->ClosePage();
3501}
3502
[email protected]f546640b2012-05-15 00:03:493503void WebContentsImpl::RouteMessageEvent(
3504 RenderViewHost* rvh,
3505 const ViewMsg_PostMessage_Params& params) {
3506 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363507 // came from a RenderViewHost in the same BrowsingInstance or if this
3508 // WebContents is dedicated to a browser plugin guest.
3509 // Note: This check means that an embedder could theoretically receive a
3510 // postMessage from anyone (not just its own guests). However, this is
3511 // probably not a risk for apps since other pages won't have references
3512 // to App windows.
3513 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3514 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493515 return;
3516
3517 ViewMsg_PostMessage_Params new_params(params);
3518
[email protected]0bc7f3542013-10-21 15:05:533519 if (!params.message_port_ids.empty()) {
3520 MessagePortMessageFilter* message_port_message_filter =
3521 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3522 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093523 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3524 params.message_port_ids,
3525 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533526 }
3527
[email protected]f546640b2012-05-15 00:03:493528 // If there is a source_routing_id, translate it to the routing ID for
3529 // the equivalent swapped out RVH in the target process. If we need
3530 // to create a swapped out RVH for the source tab, we create its opener
3531 // chain as well, since those will also be accessible to the target page.
3532 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3533 // Try to look up the WebContents for the source page.
3534 WebContentsImpl* source_contents = NULL;
3535 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3536 rvh->GetProcess()->GetID(), params.source_routing_id);
3537 if (source_rvh) {
3538 source_contents = static_cast<WebContentsImpl*>(
3539 source_rvh->GetDelegate()->GetAsWebContents());
3540 }
3541
3542 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363543 if (GetBrowserPluginGuest()) {
3544 // We create a swapped out RenderView for the embedder in the guest's
3545 // render process but we intentionally do not expose the embedder's
3546 // opener chain to it.
3547 new_params.source_routing_id =
3548 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3549 } else {
3550 new_params.source_routing_id =
3551 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3552 }
[email protected]f546640b2012-05-15 00:03:493553 } else {
3554 // We couldn't find it, so don't pass a source frame.
3555 new_params.source_routing_id = MSG_ROUTING_NONE;
3556 }
3557 }
3558
3559 // In most cases, we receive this from a swapped out RenderViewHost.
3560 // It is possible to receive it from one that has just been swapped in,
3561 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183562 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493563}
3564
[email protected]a796f202012-05-30 14:14:253565bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263566 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253567 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263568 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253569 if (!delegate_)
3570 return false;
3571 return delegate_->AddMessageToConsole(this, level, message, line_no,
3572 source_id);
3573}
3574
[email protected]b172aee2012-04-10 17:05:263575WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273576 // We want to base the page config off of the actual URL, rather than the
3577 // virtual URL.
3578 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3579 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003580 GURL url = controller_.GetActiveEntry()
3581 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153582
[email protected]fa944cb82013-11-15 17:51:213583 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323584}
3585
[email protected]0eba810b2012-10-18 03:19:363586int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213587 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413588 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3589 true, true);
[email protected]0eba810b2012-10-18 03:19:363590}
3591
[email protected]b172aee2012-04-10 17:05:263592void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273593 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253594 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223595
[email protected]ea114722012-03-12 01:11:253596 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173597 if (rdh) // NULL in unittests.
3598 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253599}
3600
[email protected]b172aee2012-04-10 17:05:263601void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443602 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253603 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443604}
3605
[email protected]b172aee2012-04-10 17:05:263606void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563607 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263608 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153609 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523610 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153611 return;
3612
[email protected]9f76c1e2012-03-05 15:15:583613 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3614
[email protected]e5fc1632011-08-08 07:51:533615 // Ignore renderer unresponsive event if debugger is attached to the tab
3616 // since the event may be a result of the renderer sitting on a breakpoint.
3617 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363618 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533619 return;
3620
[email protected]2e9d79f2013-08-16 05:45:563621 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323622 // Hang occurred while firing the beforeunload/unload handler.
3623 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583624 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323625
[email protected]fa944cb82013-11-15 17:51:213626 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323627 return;
3628
3629 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563630 // nothing we can do to recover. If the hang is in the beforeunload handler,
3631 // pretend the beforeunload listeners have all fired and allow the delegate
3632 // to continue closing; the user will not have the option of cancelling the
3633 // close. Otherwise, pretend the unload listeners have all fired and close
3634 // the tab.
3635 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463636 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563637 delegate_->BeforeUnloadFired(this, true, &close);
3638 }
3639 if (close)
3640 Close(rvh);
[email protected]420ae012009-04-24 05:16:323641 return;
3642 }
3643
[email protected]9f76c1e2012-03-05 15:15:583644 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473645 return;
3646
[email protected]6934a702011-12-20 00:04:513647 if (delegate_)
3648 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323649}
3650
[email protected]b172aee2012-04-10 17:05:263651void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513652 if (delegate_)
3653 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323654}
3655
[email protected]b172aee2012-04-10 17:05:263656void WebContentsImpl::LoadStateChanged(
3657 const GURL& url,
3658 const net::LoadStateWithParam& load_state,
3659 uint64 upload_position,
3660 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323661 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563662 upload_position_ = upload_position;
3663 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503664 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213665 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303666 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213667 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323668 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463669 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213670 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463671 }
[email protected]420ae012009-04-24 05:16:323672}
3673
[email protected]b172aee2012-04-10 17:05:263674void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553675 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323676 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123677 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3678 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513679 if (delegate_)
3680 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093681 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323682}
3683
[email protected]58d5cfe2013-07-10 02:40:523684void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543685 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233686 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223687 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543688}
3689
[email protected]b172aee2012-04-10 17:05:263690void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103691 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213692 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263693 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3694 // here during container initialization and normal window size will be set
3695 // later. In case of tab duplication this resizing to 0x0 prevents setting
3696 // normal size later so just ignore it.
3697 if (!size.IsEmpty())
3698 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323699}
3700
[email protected]af905902013-10-01 21:38:513701void WebContentsImpl::CancelModalDialogsForRenderManager() {
3702 // We need to cancel modal dialogs when doing a process swap, since the load
3703 // deferrer would prevent us from swapping out.
3704 if (dialog_manager_)
3705 dialog_manager_->CancelActiveAndPendingDialogs(this);
3706}
3707
[email protected]7b712ee22013-10-03 00:57:283708void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3709 RenderViewHost* new_host) {
3710 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083711
3712 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003713 if (delegate_)
3714 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393715
[email protected]7b712ee22013-10-03 00:57:283716 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543717}
3718
[email protected]14392a52012-05-02 20:28:443719int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3720 SiteInstance* instance) {
3721 if (!opener_)
3722 return MSG_ROUTING_NONE;
3723
3724 // Recursively create RenderViews for anything else in the opener chain.
3725 return opener_->CreateOpenerRenderViews(instance);
3726}
3727
3728int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3729 int opener_route_id = MSG_ROUTING_NONE;
3730
3731 // If this tab has an opener, ensure it has a RenderView in the given
3732 // SiteInstance as well.
3733 if (opener_)
3734 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3735
[email protected]45a22ad2013-02-21 03:25:003736 // If any of the renderers (current, pending, or swapped out) for this
3737 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213738 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3739 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373740
[email protected]fa944cb82013-11-15 17:51:213741 if (GetRenderManager()->pending_render_view_host() &&
3742 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3743 instance)
3744 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003745
[email protected]fa944cb82013-11-15 17:51:213746 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373747 instance);
3748 if (rvh)
3749 return rvh->GetRoutingID();
3750
[email protected]14392a52012-05-02 20:28:443751 // Create a swapped out RenderView in the given SiteInstance if none exists,
3752 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413753 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3754 true, true);
[email protected]14392a52012-05-02 20:28:443755}
3756
[email protected]b172aee2012-04-10 17:05:263757NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193758 return GetController();
[email protected]3a3d47472010-07-15 21:03:543759}
3760
[email protected]b172aee2012-04-10 17:05:263761WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563762 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323763}
3764
[email protected]10f417c52011-12-28 21:04:233765NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263766 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323767 return controller_.GetLastCommittedEntry();
3768}
3769
[email protected]b172aee2012-04-10 17:05:263770bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163771 RenderViewHost* render_view_host,
3772 int opener_route_id,
3773 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033774 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443775 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483776 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163777 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3778 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3779 // case this because RWH is still a base class of RenderViewHost, and child
3780 // frame RWHVs are unique in that they do not have their own WebContents.
3781 if (frame_connector) {
3782 RenderWidgetHostViewChildFrame* rwh_view_child =
3783 new RenderWidgetHostViewChildFrame(render_view_host);
3784 frame_connector->set_view(rwh_view_child);
3785 rwh_view = rwh_view_child;
3786 } else {
3787 rwh_view = view_->CreateViewForWidget(render_view_host);
3788 }
[email protected]1a98a932009-11-17 00:12:523789
[email protected]420ae012009-04-24 05:16:323790 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443791 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213792 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323793
[email protected]74ce1ad2011-12-16 21:51:463794 // Make sure we use the correct starting page_id in the new RenderView.
3795 UpdateMaxPageIDIfNecessary(render_view_host);
3796 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583797 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463798
[email protected]9f76c1e2012-03-05 15:15:583799 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263800 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493801 opener_route_id,
[email protected]c7c0d822014-04-16 20:19:493802 max_page_id,
3803 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523804 return false;
[email protected]14392a52012-05-02 20:28:443805 }
[email protected]a4127722011-04-27 23:13:523806
[email protected]a220b5932013-09-21 03:47:443807#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503808 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3809 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443810 if (rwh_view) {
3811 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3812 render_widget_host->WasResized();
3813 }
[email protected]f8233cc2011-05-31 20:24:503814#endif
3815
[email protected]420ae012009-04-24 05:16:323816 return true;
3817}
3818
[email protected]7d244f12013-08-22 21:41:513819#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453820
[email protected]155c7f22013-12-09 17:07:183821base::android::ScopedJavaLocalRef<jobject>
3822WebContentsImpl::GetJavaWebContents() {
3823 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3824
3825 WebContentsAndroid* web_contents_android =
3826 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3827 if (!web_contents_android) {
3828 web_contents_android = new WebContentsAndroid(this);
3829 SetUserData(kWebContentsAndroidKey, web_contents_android);
3830 }
3831 return web_contents_android->GetJavaObject();
3832}
3833
[email protected]7d244f12013-08-22 21:41:513834bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3835 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163836 MSG_ROUTING_NONE,
3837 NULL);
[email protected]7d244f12013-08-22 21:41:513838}
[email protected]fc2b46b2014-05-03 16:33:453839
3840#elif defined(OS_MACOSX)
3841
3842void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
3843 view_->SetAllowOverlappingViews(overlapping);
3844}
3845
3846bool WebContentsImpl::GetAllowOverlappingViews() {
3847 return view_->GetAllowOverlappingViews();
3848}
3849
3850void WebContentsImpl::SetOverlayView(WebContents* overlay,
3851 const gfx::Point& offset) {
3852 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
3853 offset);
3854}
3855
3856void WebContentsImpl::RemoveOverlayView() {
3857 view_->RemoveOverlayView();
3858}
3859
[email protected]7d244f12013-08-22 21:41:513860#endif
3861
[email protected]6fba26d2014-04-29 09:38:283862void WebContentsImpl::OnDialogClosed(int render_process_id,
3863 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:263864 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493865 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263866 bool success,
[email protected]fcf75d42013-12-03 20:11:263867 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:283868 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3869 render_frame_id);
[email protected]87de04b02014-04-08 22:14:493870 last_dialog_suppressed_ = dialog_was_suppressed;
3871
[email protected]beb440c2009-11-06 04:08:543872 if (is_showing_before_unload_dialog_ && !success) {
3873 // If a beforeunload dialog is canceled, we need to stop the throbber from
3874 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:283875 if (rfh)
3876 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353877 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103878
[email protected]6d65a462013-06-21 21:29:123879 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3880 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543881 }
[email protected]87de04b02014-04-08 22:14:493882
[email protected]beb440c2009-11-06 04:08:543883 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:283884 if (rfh) {
3885 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3886 dialog_was_suppressed);
3887 } else {
3888 // Don't leak the sync IPC reply if the RFH or process is gone.
3889 delete reply_msg;
3890 }
[email protected]beb440c2009-11-06 04:08:543891}
3892
[email protected]b172aee2012-04-10 17:05:263893void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:543894 if (encoding == last_reported_encoding_)
3895 return;
3896 last_reported_encoding_ = encoding;
3897
3898 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123899 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103900}
[email protected]f45d2a72010-03-08 23:28:353901
[email protected]b172aee2012-04-10 17:05:263902void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:483903 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443904 // Can be NULL during tests.
3905 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:453906 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:363907}
[email protected]9f76c1e2012-03-05 15:15:583908
[email protected]1ac10dca2013-08-20 20:47:043909bool WebContentsImpl::IsHidden() {
3910 return capturer_count_ == 0 && !should_normally_be_visible_;
3911}
3912
[email protected]b0936d22013-11-28 06:47:363913RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213914 return frame_tree_.root()->render_manager();
3915}
3916
[email protected]b172aee2012-04-10 17:05:263917RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583918 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3919}
[email protected]7900bfdb2012-05-24 19:31:243920
[email protected]f8497342013-02-05 22:15:023921BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393922 return browser_plugin_guest_.get();
3923}
3924
[email protected]738f57a2013-06-29 21:06:543925void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3926 CHECK(!browser_plugin_guest_);
3927 browser_plugin_guest_.reset(guest);
3928}
3929
[email protected]f8497342013-02-05 22:15:023930BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393931 return browser_plugin_embedder_.get();
3932}
[email protected]8ff00d72012-10-23 19:12:213933
[email protected]d9030b82013-07-19 08:26:063934void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:193935 RenderFrameHost* render_frame_host) {
3936 STLDeleteValues(&power_save_blockers_[render_frame_host]);
3937 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:063938}
3939
3940void WebContentsImpl::ClearAllPowerSaveBlockers() {
3941 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3942 i != power_save_blockers_.end(); ++i)
3943 STLDeleteValues(&power_save_blockers_[i->first]);
3944 power_save_blockers_.clear();
3945}
3946
[email protected]fc2b46b2014-05-03 16:33:453947gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:213948 gfx::Size size;
3949 if (delegate_)
3950 size = delegate_->GetSizeForNewRenderView(this);
3951 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:453952 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:213953 return size;
3954}
3955
[email protected]9b159a52013-10-03 17:24:553956void WebContentsImpl::OnFrameRemoved(
3957 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583958 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553959 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583960 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553961}
3962
[email protected]222f5822014-02-05 23:40:493963void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3964 if (!delegate_)
3965 return;
3966 const gfx::Size new_size = GetPreferredSize();
3967 if (new_size != old_size)
3968 delegate_->UpdatePreferredSize(this, new_size);
3969}
3970
[email protected]8ff00d72012-10-23 19:12:213971} // namespace content