blob: 45f6468b7f9afcc91069818cf5fe57be01c978d3 [file] [log] [blame]
[email protected]91854cd2012-01-10 19:43:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]93ddb3c2012-04-11 21:44:295#include "content/browser/web_contents/web_contents_impl.h"
[email protected]39526562011-02-05 03:41:516
[email protected]2bb171882012-03-07 02:09:467#include <utility>
[email protected]b75b8292010-10-01 07:28:258
[email protected]36fb2c7c2011-04-04 15:49:089#include "base/command_line.h"
[email protected]e11f0e92013-06-12 15:12:0310#include "base/debug/trace_event.h"
[email protected]cbb1ef592013-06-05 19:49:4611#include "base/lazy_instance.h"
[email protected]6d636e62013-07-31 03:15:5612#include "base/logging.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1814#include "base/metrics/stats_counters.h"
[email protected]04cbd3d2013-12-04 04:58:2015#include "base/process/process.h"
[email protected]348fbaac2013-06-11 06:31:5116#include "base/strings/string16.h"
17#include "base/strings/string_number_conversions.h"
18#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3720#include "base/time/time.h"
[email protected]7a846df2012-09-20 19:17:3921#include "content/browser/browser_plugin/browser_plugin_embedder.h"
22#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5923#include "content/browser/child_process_security_policy_impl.h"
[email protected]49413ca52014-03-05 14:13:4324#include "content/browser/devtools/render_view_devtools_agent_host.h"
[email protected]5f2aa722013-08-07 16:59:4125#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0426#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4627#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1228#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1629#include "content/browser/download/save_package.h"
[email protected]bffc8302014-01-23 20:52:1630#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4031#include "content/browser/frame_host/interstitial_page_impl.h"
32#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0133#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1834#include "content/browser/frame_host/render_frame_host_impl.h"
[email protected]bffc8302014-01-23 20:52:1635#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
[email protected]5c9250872012-01-30 17:24:0536#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4437#include "content/browser/loader/resource_dispatcher_host_impl.h"
[email protected]0bc7f3542013-10-21 15:05:5338#include "content/browser/message_port_message_filter.h"
39#include "content/browser/message_port_service.h"
[email protected]d9030b82013-07-19 08:26:0640#include "content/browser/power_save_blocker_impl.h"
[email protected]f3b1a082011-11-18 00:34:3041#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5042#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3243#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5044#include "content/browser/renderer_host/render_widget_host_impl.h"
[email protected]cfd80b02014-05-01 17:46:4845#include "content/browser/renderer_host/render_widget_host_view_base.h"
[email protected]b6583592012-01-25 19:52:3346#include "content/browser/site_instance_impl.h"
[email protected]b5a40842012-11-28 15:26:1147#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5848#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0349#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5650#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1451#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4252#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4453#include "content/common/frame_messages.h"
[email protected]41225fe2013-03-29 05:32:0254#include "content/common/image_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1755#include "content/common/input_messages.h"
[email protected]35be7ec2012-02-12 20:42:5156#include "content/common/ssl_status_serialization.h"
[email protected]2c5569662011-03-22 20:45:0257#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3658#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1159#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2860#include "content/public/browser/browser_plugin_guest_manager.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 =
[email protected]139355f2014-05-11 14:21:281417 GetBrowserContext()->GetGuestManager()->GetNextInstanceID();
[email protected]c4538072013-03-18 02:17:551418 WebContentsImpl* new_contents_impl =
1419 static_cast<WebContentsImpl*>(new_contents);
[email protected]c61b317c72013-11-14 06:40:461420 BrowserPluginGuest::CreateWithOpener(instance_id,
1421 new_contents_impl->opener() != NULL,
1422 new_contents_impl,
1423 GetBrowserPluginGuest());
[email protected]c4538072013-03-18 02:17:551424 }
[email protected]1ac10dca2013-08-20 20:47:041425 if (params.disposition == NEW_BACKGROUND_TAB)
1426 create_params.initially_hidden = true;
[email protected]54944cde2012-12-09 09:24:591427 new_contents->Init(create_params);
[email protected]d1198fd2012-08-13 22:50:191428
[email protected]c4538072013-03-18 02:17:551429 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341430 // will be shown immediately).
1431 if (!params.opener_suppressed) {
1432 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451433 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501434
[email protected]d70bea92013-04-05 04:23:341435 // TODO(brettw): It seems bogus that we have to call this function on the
1436 // newly created object and give it one of its own member variables.
1437 new_view->CreateViewForWidget(new_contents->GetRenderViewHost());
1438 }
[email protected]bafe6cd2012-05-23 23:09:501439 // Save the created window associated with the route so we can show it
1440 // later.
1441 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1442 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101443 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501444 }
1445
1446 if (delegate_) {
1447 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071448 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131449 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501450 }
1451
1452 if (params.opener_suppressed) {
1453 // When the opener is suppressed, the original renderer cannot access the
1454 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:001455 bool was_blocked = false;
1456 if (delegate_) {
1457 gfx::Rect initial_pos;
1458 delegate_->AddNewContents(
1459 this, new_contents, params.disposition, initial_pos,
1460 params.user_gesture, &was_blocked);
1461 }
1462 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:211463 OpenURLParams open_params(params.target_url,
1464 Referrer(),
1465 CURRENT_TAB,
1466 PAGE_TRANSITION_LINK,
1467 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:301468 open_params.user_gesture = params.user_gesture;
[email protected]eda238a12012-09-07 23:44:001469 new_contents->OpenURL(open_params);
1470 }
[email protected]bafe6cd2012-05-23 23:09:501471 }
1472}
1473
[email protected]a8504022013-12-04 20:23:511474void WebContentsImpl::CreateNewWidget(int render_process_id,
1475 int route_id,
[email protected]180ef242013-11-07 06:50:461476 blink::WebPopupType popup_type) {
[email protected]a8504022013-12-04 20:23:511477 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:501478}
1479
[email protected]a8504022013-12-04 20:23:511480void WebContentsImpl::CreateNewFullscreenWidget(int render_process_id,
1481 int route_id) {
1482 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:501483}
1484
[email protected]a8504022013-12-04 20:23:511485void WebContentsImpl::CreateNewWidget(int render_process_id,
1486 int route_id,
[email protected]bafe6cd2012-05-23 23:09:501487 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:461488 blink::WebPopupType popup_type) {
[email protected]8ff00d72012-10-23 19:12:211489 RenderProcessHost* process = GetRenderProcessHost();
[email protected]a8504022013-12-04 20:23:511490 // A message to create a new widget can only come from the active process for
1491 // this WebContentsImpl instance. If any other process sends the request,
1492 // it is invalid and the process must be terminated.
1493 if (process->GetID() != render_process_id) {
1494 base::ProcessHandle process_handle =
1495 RenderProcessHost::FromID(render_process_id)->GetHandle();
1496 if (process_handle != base::kNullProcessHandle) {
1497 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391498 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
[email protected]a8504022013-12-04 20:23:511499 base::KillProcess(process_handle, content::RESULT_CODE_KILLED, false);
1500 }
1501 return;
1502 }
1503
[email protected]bafe6cd2012-05-23 23:09:501504 RenderWidgetHostImpl* widget_host =
[email protected]1ac10dca2013-08-20 20:47:041505 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:261506 created_widgets_.insert(widget_host);
1507
[email protected]cfd80b02014-05-01 17:46:481508 RenderWidgetHostViewBase* widget_view =
1509 static_cast<RenderWidgetHostViewBase*>(
1510 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:191511 if (!widget_view)
1512 return;
[email protected]bafe6cd2012-05-23 23:09:501513 if (!is_fullscreen) {
1514 // Popups should not get activated.
1515 widget_view->SetPopupType(popup_type);
1516 }
1517 // Save the created widget associated with the route so we can show it later.
1518 pending_widget_views_[route_id] = widget_view;
1519
1520#if defined(OS_MACOSX)
1521 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
1522 // to allow it to survive the trip without being hosted.
1523 base::mac::NSObjectRetain(widget_view->GetNativeView());
1524#endif
1525}
1526
1527void WebContentsImpl::ShowCreatedWindow(int route_id,
1528 WindowOpenDisposition disposition,
1529 const gfx::Rect& initial_pos,
1530 bool user_gesture) {
1531 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:001532 if (contents) {
1533 WebContentsDelegate* delegate = GetDelegate();
1534 if (delegate) {
1535 delegate->AddNewContents(
1536 this, contents, disposition, initial_pos, user_gesture, NULL);
1537 }
1538 }
[email protected]bafe6cd2012-05-23 23:09:501539}
1540
1541void WebContentsImpl::ShowCreatedWidget(int route_id,
1542 const gfx::Rect& initial_pos) {
1543 ShowCreatedWidget(route_id, false, initial_pos);
1544}
1545
1546void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
1547 ShowCreatedWidget(route_id, true, gfx::Rect());
1548}
1549
1550void WebContentsImpl::ShowCreatedWidget(int route_id,
1551 bool is_fullscreen,
1552 const gfx::Rect& initial_pos) {
[email protected]cfd80b02014-05-01 17:46:481553 RenderWidgetHostViewBase* widget_host_view =
1554 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:501555 if (!widget_host_view)
1556 return;
[email protected]cfd80b02014-05-01 17:46:481557
1558 RenderWidgetHostView* view = NULL;
1559 BrowserPluginGuest* guest = GetBrowserPluginGuest();
1560 if (guest && guest->embedder_web_contents()) {
1561 view = guest->embedder_web_contents()->GetRenderWidgetHostView();
1562 } else {
1563 view = GetRenderWidgetHostView();
1564 }
1565
[email protected]4aebbca2013-09-17 22:26:491566 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:311567 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
1568 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:491569 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
1570 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
1571 delegate_->ToggleFullscreenModeForTab(this, true);
1572 } else {
[email protected]cfd80b02014-05-01 17:46:481573 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:491574 }
[email protected]4aebbca2013-09-17 22:26:491575 FOR_EACH_OBSERVER(WebContentsObserver,
1576 observers_,
1577 DidShowFullscreenWidget(route_id));
1578 if (!widget_host_view->HasFocus())
1579 widget_host_view->Focus();
1580 } else {
[email protected]cfd80b02014-05-01 17:46:481581 widget_host_view->InitAsPopup(view, initial_pos);
[email protected]4aebbca2013-09-17 22:26:491582 }
[email protected]89054502012-06-03 10:29:241583
1584 RenderWidgetHostImpl* render_widget_host_impl =
1585 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
1586 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:311587 // Only allow privileged mouse lock for fullscreen render widget, which is
1588 // used to implement Pepper Flash fullscreen.
1589 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:501590
1591#if defined(OS_MACOSX)
1592 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
1593 // properly embedded (or purposefully ignored) we can release the retain we
1594 // took in CreateNewWidget().
1595 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
1596#endif
1597}
1598
1599WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
1600 PendingContents::iterator iter = pending_contents_.find(route_id);
1601
1602 // Certain systems can block the creation of new windows. If we didn't succeed
1603 // in creating one, just return NULL.
1604 if (iter == pending_contents_.end()) {
1605 return NULL;
1606 }
1607
1608 WebContentsImpl* new_contents = iter->second;
1609 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:101610 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501611
[email protected]d70bea92013-04-05 04:23:341612 // Don't initialize the guest WebContents immediately.
1613 if (new_contents->GetRenderProcessHost()->IsGuest())
1614 return new_contents;
1615
[email protected]bafe6cd2012-05-23 23:09:501616 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
1617 !new_contents->GetRenderViewHost()->GetView())
1618 return NULL;
1619
1620 // TODO(brettw): It seems bogus to reach into here and initialize the host.
1621 static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init();
1622 return new_contents;
1623}
1624
1625RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
1626 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
1627 if (iter == pending_widget_views_.end()) {
1628 DCHECK(false);
1629 return NULL;
1630 }
1631
1632 RenderWidgetHostView* widget_host_view = iter->second;
1633 pending_widget_views_.erase(route_id);
1634
1635 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
1636 if (!widget_host->GetProcess()->HasConnection()) {
1637 // The view has gone away or the renderer crashed. Nothing to do.
1638 return NULL;
1639 }
1640
1641 return widget_host_view;
1642}
1643
[email protected]f13b4202012-06-12 23:53:231644void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:091645 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:211646 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:371647 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:231648 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:371649 } else {
1650 callback.Run(MediaStreamDevices(),
1651 MEDIA_DEVICE_INVALID_STATE,
1652 scoped_ptr<MediaStreamUI>());
1653 }
[email protected]f13b4202012-06-12 23:53:231654}
1655
[email protected]cc9200432013-07-23 23:02:401656SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
1657 SiteInstance* instance) {
1658 return controller_.GetSessionStorageNamespace(instance);
1659}
1660
[email protected]9b159a52013-10-03 17:24:551661FrameTree* WebContentsImpl::GetFrameTree() {
1662 return &frame_tree_;
1663}
1664
[email protected]31a71eaf2014-03-13 01:47:361665void WebContentsImpl::AccessibilityEventReceived(
1666 const std::vector<AXEventNotificationDetails>& details) {
1667 FOR_EACH_OBSERVER(
1668 WebContentsObserver, observers_, AccessibilityEventReceived(details));
1669}
1670
[email protected]edc3af82013-12-12 21:24:071671void WebContentsImpl::OnShowValidationMessage(
1672 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:291673 const base::string16& main_text,
1674 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:071675 if (delegate_)
1676 delegate_->ShowValidationMessage(
1677 this, anchor_in_root_view, main_text, sub_text);
1678}
1679
1680void WebContentsImpl::OnHideValidationMessage() {
1681 if (delegate_)
1682 delegate_->HideValidationMessage(this);
1683}
1684
1685void WebContentsImpl::OnMoveValidationMessage(
1686 const gfx::Rect& anchor_in_root_view) {
1687 if (delegate_)
1688 delegate_->MoveValidationMessage(this, anchor_in_root_view);
1689}
1690
[email protected]32deec62013-05-15 23:55:041691void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) {
1692 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:441693 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:041694}
1695
[email protected]b172aee2012-04-10 17:05:261696void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:491697 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:231698 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:491699 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:331700}
1701
[email protected]b172aee2012-04-10 17:05:261702void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) {
[email protected]61e2b3cc2012-03-02 16:13:341703 if (delegate_)
1704 delegate_->ResizeDueToAutoResize(this, new_size);
1705}
1706
[email protected]b172aee2012-04-10 17:05:261707WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:201708 if (!delegate_)
1709 return NULL;
[email protected]00c37fc2011-08-02 00:22:501710
[email protected]e5d549d2011-12-28 01:29:201711 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:201712 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:341713}
1714
[email protected]6b618e62012-08-16 12:59:181715bool WebContentsImpl::Send(IPC::Message* message) {
1716 if (!GetRenderViewHost()) {
1717 delete message;
1718 return false;
1719 }
1720
1721 return GetRenderViewHost()->Send(message);
1722}
1723
[email protected]b172aee2012-04-10 17:05:261724bool WebContentsImpl::NavigateToPendingEntry(
[email protected]c5eed492012-01-04 17:07:501725 NavigationController::ReloadType reload_type) {
[email protected]61ac9e242014-03-21 20:55:261726 FrameTreeNode* node = frame_tree_.root();
1727
1728 // If we are using --site-per-process, we should navigate in the FrameTreeNode
1729 // specified in the pending entry.
1730 NavigationEntryImpl* pending_entry =
1731 NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry());
1732 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSitePerProcess) &&
1733 pending_entry->frame_tree_node_id() != -1) {
1734 node = frame_tree_.FindByID(pending_entry->frame_tree_node_id());
1735 }
1736
1737 return node->navigator()->NavigateToPendingEntry(
1738 node->current_frame_host(), reload_type);
[email protected]876bc832010-09-07 16:29:541739}
[email protected]96d185d2009-04-24 03:28:541740
[email protected]a86c0e962013-12-17 17:10:391741void WebContentsImpl::RenderFrameForInterstitialPageCreated(
1742 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:441743 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:391744 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:441745}
1746
[email protected]20ca0382013-02-28 19:50:071747void WebContentsImpl::AttachInterstitialPage(
1748 InterstitialPageImpl* interstitial_page) {
1749 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:211750 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:291751
1752 // Cancel any visible dialogs so that they don't interfere with the
1753 // interstitial.
1754 if (dialog_manager_)
1755 dialog_manager_->CancelActiveAndPendingDialogs(this);
1756
[email protected]20ca0382013-02-28 19:50:071757 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1758 DidAttachInterstitialPage());
1759}
1760
1761void WebContentsImpl::DetachInterstitialPage() {
[email protected]6832c8bc2014-04-29 07:20:571762 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:211763 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:071764 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1765 DidDetachInterstitialPage());
1766}
1767
[email protected]b172aee2012-04-10 17:05:261768void WebContentsImpl::SetHistoryLengthAndPrune(
[email protected]b6583592012-01-25 19:52:331769 const SiteInstance* site_instance,
1770 int history_length,
1771 int32 minimum_page_id) {
[email protected]5229253b2011-08-16 14:36:411772 // SetHistoryLengthAndPrune doesn't work when there are pending cross-site
1773 // navigations. Callers should ensure that this is the case.
[email protected]fa944cb82013-11-15 17:51:211774 if (GetRenderManager()->pending_render_view_host()) {
[email protected]9e1ad4b2011-08-14 16:49:191775 NOTREACHED();
[email protected]796931a92011-08-10 01:32:141776 return;
[email protected]9e1ad4b2011-08-14 16:49:191777 }
[email protected]9f76c1e2012-03-05 15:15:581778 RenderViewHostImpl* rvh = GetRenderViewHostImpl();
[email protected]9e1ad4b2011-08-14 16:49:191779 if (!rvh) {
1780 NOTREACHED();
1781 return;
1782 }
[email protected]9f76c1e2012-03-05 15:15:581783 if (site_instance && rvh->GetSiteInstance() != site_instance) {
[email protected]9e1ad4b2011-08-14 16:49:191784 NOTREACHED();
1785 return;
1786 }
[email protected]6b618e62012-08-16 12:59:181787 Send(new ViewMsg_SetHistoryLengthAndPrune(GetRoutingID(),
1788 history_length,
1789 minimum_page_id));
[email protected]796931a92011-08-10 01:32:141790}
1791
[email protected]4fed3702014-04-01 09:08:001792void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) {
[email protected]1f3fc1d2014-04-03 14:50:171793 RenderFrameHost* focused_frame = GetFocusedFrame();
1794 if (!focused_frame)
1795 return;
1796
[email protected]959be4c2014-04-08 15:01:331797 focused_frame->Send(new FrameMsg_Reload(
1798 focused_frame->GetRoutingID(), ignore_cache));
1799}
1800
1801void WebContentsImpl::Undo() {
1802 RenderFrameHost* focused_frame = GetFocusedFrame();
1803 if (!focused_frame)
1804 return;
1805
1806 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
1807 RecordAction(base::UserMetricsAction("Undo"));
1808}
1809
1810void WebContentsImpl::Redo() {
1811 RenderFrameHost* focused_frame = GetFocusedFrame();
1812 if (!focused_frame)
1813 return;
1814 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
1815 RecordAction(base::UserMetricsAction("Redo"));
1816}
1817
1818void WebContentsImpl::Cut() {
1819 RenderFrameHost* focused_frame = GetFocusedFrame();
1820 if (!focused_frame)
1821 return;
1822
1823 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
1824 RecordAction(base::UserMetricsAction("Cut"));
1825}
1826
1827void WebContentsImpl::Copy() {
1828 RenderFrameHost* focused_frame = GetFocusedFrame();
1829 if (!focused_frame)
1830 return;
1831
1832 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
1833 RecordAction(base::UserMetricsAction("Copy"));
1834}
1835
1836void WebContentsImpl::CopyToFindPboard() {
1837#if defined(OS_MACOSX)
1838 RenderFrameHost* focused_frame = GetFocusedFrame();
1839 if (!focused_frame)
1840 return;
1841
1842 // Windows/Linux don't have the concept of a find pasteboard.
1843 focused_frame->Send(
1844 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
1845 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
1846#endif
1847}
1848
1849void WebContentsImpl::Paste() {
1850 RenderFrameHost* focused_frame = GetFocusedFrame();
1851 if (!focused_frame)
1852 return;
1853
1854 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
1855 RecordAction(base::UserMetricsAction("Paste"));
1856}
1857
1858void WebContentsImpl::PasteAndMatchStyle() {
1859 RenderFrameHost* focused_frame = GetFocusedFrame();
1860 if (!focused_frame)
1861 return;
1862
1863 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
1864 focused_frame->GetRoutingID()));
1865 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
1866}
1867
1868void WebContentsImpl::Delete() {
1869 RenderFrameHost* focused_frame = GetFocusedFrame();
1870 if (!focused_frame)
1871 return;
1872
1873 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
1874 RecordAction(base::UserMetricsAction("DeleteSelection"));
1875}
1876
1877void WebContentsImpl::SelectAll() {
1878 RenderFrameHost* focused_frame = GetFocusedFrame();
1879 if (!focused_frame)
1880 return;
1881
1882 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
1883 RecordAction(base::UserMetricsAction("SelectAll"));
1884}
1885
1886void WebContentsImpl::Unselect() {
1887 RenderFrameHost* focused_frame = GetFocusedFrame();
1888 if (!focused_frame)
1889 return;
1890
1891 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
1892 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:171893}
1894
1895void WebContentsImpl::Replace(const base::string16& word) {
1896 RenderFrameHost* focused_frame = GetFocusedFrame();
1897 if (!focused_frame)
1898 return;
1899
[email protected]959be4c2014-04-08 15:01:331900 focused_frame->Send(new InputMsg_Replace(
1901 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:171902}
1903
1904void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
1905 RenderFrameHost* focused_frame = GetFocusedFrame();
1906 if (!focused_frame)
1907 return;
1908
[email protected]959be4c2014-04-08 15:01:331909 focused_frame->Send(new InputMsg_ReplaceMisspelling(
1910 focused_frame->GetRoutingID(), word));
1911}
1912
1913void WebContentsImpl::NotifyContextMenuClosed(
1914 const CustomContextMenuContext& context) {
1915 RenderFrameHost* focused_frame = GetFocusedFrame();
1916 if (!focused_frame)
1917 return;
1918
1919 focused_frame->Send(new FrameMsg_ContextMenuClosed(
1920 focused_frame->GetRoutingID(), context));
1921}
1922
1923void WebContentsImpl::ExecuteCustomContextMenuCommand(
1924 int action, const CustomContextMenuContext& context) {
1925 RenderFrameHost* focused_frame = GetFocusedFrame();
1926 if (!focused_frame)
1927 return;
1928
1929 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
1930 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:001931}
1932
[email protected]fc2b46b2014-05-03 16:33:451933gfx::NativeView WebContentsImpl::GetNativeView() {
1934 return view_->GetNativeView();
1935}
1936
1937gfx::NativeView WebContentsImpl::GetContentNativeView() {
1938 return view_->GetContentNativeView();
1939}
1940
1941gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
1942 return view_->GetTopLevelNativeWindow();
1943}
1944
1945gfx::Rect WebContentsImpl::GetViewBounds() {
1946 return view_->GetViewBounds();
1947}
1948
1949gfx::Rect WebContentsImpl::GetContainerBounds() {
1950 gfx::Rect rv;
1951 view_->GetContainerBounds(&rv);
1952 return rv;
1953}
1954
1955DropData* WebContentsImpl::GetDropData() {
1956 return view_->GetDropData();
1957}
1958
1959void WebContentsImpl::Focus() {
1960 view_->Focus();
1961}
1962
1963void WebContentsImpl::SetInitialFocus() {
1964 view_->SetInitialFocus();
1965}
1966
1967void WebContentsImpl::StoreFocus() {
1968 view_->StoreFocus();
1969}
1970
1971void WebContentsImpl::RestoreFocus() {
1972 view_->RestoreFocus();
1973}
1974
[email protected]b172aee2012-04-10 17:05:261975void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:271976 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:211977 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:541978 return;
1979 }
[email protected]9f76c1e2012-03-05 15:15:581980 GetRenderViewHostImpl()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:541981}
1982
[email protected]b172aee2012-04-10 17:05:261983bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211984 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:541985}
1986
[email protected]b172aee2012-04-10 17:05:261987InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:211988 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:221989}
1990
[email protected]b172aee2012-04-10 17:05:261991bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:161992 // WebKit creates Document object when MIME type is application/xhtml+xml,
1993 // so we also support this MIME type.
1994 return contents_mime_type_ == "text/html" ||
1995 contents_mime_type_ == "text/xml" ||
1996 contents_mime_type_ == "application/xhtml+xml" ||
1997 contents_mime_type_ == "text/plain" ||
1998 contents_mime_type_ == "text/css" ||
1999 net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str());
2000}
2001
[email protected]b172aee2012-04-10 17:05:262002void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592003 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162004 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552005 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
[email protected]3c71576ce2013-07-23 02:00:012006 SaveFrame(GetURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142007 return;
[email protected]c7dd2f62011-07-18 15:57:592008 }
2009
2010 Stop();
2011
2012 // Create the save package and possibly prompt the user for the name to save
2013 // the page as. The user prompt is an asynchronous operation that runs on
2014 // another thread.
2015 save_package_ = new SavePackage(this);
2016 save_package_->GetSaveInfo();
2017}
2018
2019// Used in automated testing to bypass prompting the user for file names.
2020// Instead, the names and paths are hard coded rather than running them through
2021// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342022bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2023 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212024 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592025 // Stop the page from navigating.
2026 Stop();
2027
2028 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212029 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592030}
2031
[email protected]3c71576ce2013-07-23 02:00:012032void WebContentsImpl::SaveFrame(const GURL& url,
2033 const Referrer& referrer) {
2034 if (!GetURL().is_valid())
2035 return;
2036 bool is_main_frame = (url == GetURL());
2037
2038 DownloadManager* dlm =
2039 BrowserContext::GetDownloadManager(GetBrowserContext());
2040 if (!dlm)
2041 return;
2042 int64 post_id = -1;
2043 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272044 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012045 if (entry)
2046 post_id = entry->GetPostID();
2047 }
2048 scoped_ptr<DownloadUrlParameters> params(
2049 DownloadUrlParameters::FromWebContents(this, url));
2050 params->set_referrer(referrer);
2051 params->set_post_id(post_id);
2052 params->set_prefer_cache(true);
2053 if (post_id >= 0)
2054 params->set_method("POST");
2055 params->set_prompt(true);
2056 dlm->DownloadUrl(params.Pass());
2057}
2058
[email protected]b172aee2012-04-10 17:05:262059void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342060 const base::FilePath& file,
[email protected]18516cf92013-08-28 18:19:482061 const base::Callback<void(int64)>& callback) {
2062 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122063}
2064
[email protected]6286a372013-10-09 04:03:272065// TODO(nasko): Rename this method to IsVisibleEntry.
[email protected]b172aee2012-04-10 17:05:262066bool WebContentsImpl::IsActiveEntry(int32 page_id) {
[email protected]6286a372013-10-09 04:03:272067 NavigationEntryImpl* visible_entry =
2068 NavigationEntryImpl::FromNavigationEntry(controller_.GetVisibleEntry());
2069 return (visible_entry != NULL &&
2070 visible_entry->site_instance() == GetSiteInstance() &&
2071 visible_entry->GetPageID() == page_id);
[email protected]420ae012009-04-24 05:16:322072}
2073
[email protected]b172aee2012-04-10 17:05:262074const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272075 return contents_mime_type_;
2076}
2077
[email protected]b172aee2012-04-10 17:05:262078bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272079 return notify_disconnection_;
2080}
2081
[email protected]b172aee2012-04-10 17:05:262082void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312083 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182084 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162085}
2086
[email protected]b172aee2012-04-10 17:05:262087void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542088 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182089 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162090}
2091
[email protected]8ff00d72012-10-23 19:12:212092RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272093 return &renderer_preferences_;
2094}
2095
[email protected]e35ccd52012-05-23 16:22:472096void WebContentsImpl::Close() {
2097 Close(GetRenderViewHost());
2098}
2099
[email protected]cf200a562013-05-03 16:24:292100void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462101 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292102 if (browser_plugin_embedder_.get())
2103 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2104 screen_x, screen_y, operation);
2105 if (GetRenderViewHost())
2106 GetRenderViewHostImpl()->DragSourceEndedAt(client_x, client_y,
2107 screen_x, screen_y, operation);
2108}
2109
[email protected]d60f3702013-12-26 16:30:242110void WebContentsImpl::DidGetResourceResponseStart(
2111 const ResourceRequestDetails& details) {
2112 controller_.ssl_manager()->DidStartResourceResponse(details);
2113
2114 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2115 DidGetResourceResponseStart(details));
2116
2117 // TODO(avi): Remove. http://crbug.com/170921
2118 NotificationService::current()->Notify(
2119 NOTIFICATION_RESOURCE_RESPONSE_STARTED,
2120 Source<WebContents>(this),
2121 Details<const ResourceRequestDetails>(&details));
2122}
2123
2124void WebContentsImpl::DidGetRedirectForResourceRequest(
2125 RenderViewHost* render_view_host,
2126 const ResourceRedirectDetails& details) {
2127 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2128
2129 FOR_EACH_OBSERVER(
2130 WebContentsObserver,
2131 observers_,
2132 DidGetRedirectForResourceRequest(render_view_host, details));
2133
2134 // TODO(avi): Remove. http://crbug.com/170921
2135 NotificationService::current()->Notify(
2136 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2137 Source<WebContents>(this),
2138 Details<const ResourceRedirectDetails>(&details));
2139}
2140
[email protected]b172aee2012-04-10 17:05:262141void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522142 if (GetRenderViewHost())
[email protected]9f76c1e2012-03-05 15:15:582143 GetRenderViewHostImpl()->DragSourceSystemDragEnded();
[email protected]6934a702011-12-20 00:04:512144 if (delegate_)
2145 delegate_->DragEnded();
[email protected]cf200a562013-05-03 16:24:292146 if (browser_plugin_embedder_.get())
2147 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342148}
2149
[email protected]e35ccd52012-05-23 16:22:472150void WebContentsImpl::UserGestureDone() {
2151 OnUserGesture();
2152}
2153
[email protected]b172aee2012-04-10 17:05:262154void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272155 closed_by_user_gesture_ = value;
2156}
2157
[email protected]b172aee2012-04-10 17:05:262158bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272159 return closed_by_user_gesture_;
2160}
2161
[email protected]b172aee2012-04-10 17:05:262162double WebContentsImpl::GetZoomLevel() const {
[email protected]5c9250872012-01-30 17:24:052163 HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>(
[email protected]5fe3713a2012-02-22 08:31:562164 HostZoomMap::GetForBrowserContext(GetBrowserContext()));
[email protected]b75b8292010-10-01 07:28:252165 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:172166 return 0;
[email protected]b75b8292010-10-01 07:28:252167
2168 double zoom_level;
2169 if (temporary_zoom_settings_) {
2170 zoom_level = zoom_map->GetTemporaryZoomLevel(
[email protected]9f76c1e2012-03-05 15:15:582171 GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID());
[email protected]b75b8292010-10-01 07:28:252172 } else {
[email protected]2ae88d12011-10-14 09:11:192173 GURL url;
[email protected]6286a372013-10-09 04:03:272174 NavigationEntry* entry = GetController().GetLastCommittedEntry();
[email protected]2ae88d12011-10-14 09:11:192175 // Since zoom map is updated using rewritten URL, use rewritten URL
2176 // to get the zoom level.
[email protected]6286a372013-10-09 04:03:272177 url = entry ? entry->GetURL() : GURL::EmptyGURL();
[email protected]367c5c1d2013-03-11 18:59:022178 zoom_level = zoom_map->GetZoomLevelForHostAndScheme(url.scheme(),
2179 net::GetHostOrSpecFromURL(url));
[email protected]b75b8292010-10-01 07:28:252180 }
[email protected]d0b8d092010-10-25 04:05:172181 return zoom_level;
2182}
[email protected]b75b8292010-10-01 07:28:252183
[email protected]b172aee2012-04-10 17:05:262184int WebContentsImpl::GetZoomPercent(bool* enable_increment,
[email protected]9a8408902012-09-26 16:17:592185 bool* enable_decrement) const {
[email protected]d0b8d092010-10-25 04:05:172186 *enable_decrement = *enable_increment = false;
[email protected]0f083402011-11-22 02:59:012187 // Calculate the zoom percent from the factor. Round up to the nearest whole
2188 // number.
[email protected]b75b8292010-10-01 07:28:252189 int percent = static_cast<int>(
[email protected]7940b8e2013-07-25 23:08:492190 ZoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5);
[email protected]b75b8292010-10-01 07:28:252191 *enable_decrement = percent > minimum_zoom_percent_;
2192 *enable_increment = percent < maximum_zoom_percent_;
2193 return percent;
2194}
2195
[email protected]b172aee2012-04-10 17:05:262196void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502197 if (!delegate_)
2198 return;
2199
[email protected]6286a372013-10-09 04:03:272200 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2201 if (!entry)
[email protected]1788e772010-12-15 16:40:502202 return;
2203
[email protected]6286a372013-10-09 04:03:272204 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122205}
2206
[email protected]b172aee2012-04-10 17:05:262207void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042208 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272209 if (!delegate_)
2210 return;
2211
[email protected]691aa2f2013-05-28 22:52:042212 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272213}
2214
[email protected]b172aee2012-04-10 17:05:262215int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272216 return minimum_zoom_percent_;
2217}
2218
[email protected]b172aee2012-04-10 17:05:262219int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272220 return maximum_zoom_percent_;
2221}
2222
[email protected]b172aee2012-04-10 17:05:262223gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492224 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232225}
2226
[email protected]b172aee2012-04-10 17:05:262227bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]0bfbf882011-12-22 18:19:272228 return GetRenderViewHost() ?
[email protected]9f76c1e2012-03-05 15:15:582229 GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false;
[email protected]0bfbf882011-12-22 18:19:272230}
2231
[email protected]b172aee2012-04-10 17:05:262232bool WebContentsImpl::HasOpener() const {
[email protected]14392a52012-05-02 20:28:442233 return opener_ != NULL;
[email protected]a0358d72012-03-09 14:06:502234}
2235
[email protected]cb805452013-05-22 15:16:212236void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482237 if (!color_chooser_info_.get())
2238 return;
2239 RenderFrameHost* rfh = RenderFrameHost::FromID(
2240 color_chooser_info_->render_process_id,
2241 color_chooser_info_->render_frame_id);
2242 if (!rfh)
2243 return;
2244
2245 rfh->Send(new FrameMsg_DidChooseColorResponse(
2246 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202247}
2248
[email protected]cb805452013-05-22 15:16:212249void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482250 if (!color_chooser_info_.get())
2251 return;
2252 RenderFrameHost* rfh = RenderFrameHost::FromID(
2253 color_chooser_info_->render_process_id,
2254 color_chooser_info_->render_frame_id);
2255 if (!rfh)
2256 return;
2257
2258 rfh->Send(new FrameMsg_DidEndColorChooser(
2259 rfh->GetRoutingID(), color_chooser_info_->identifier));
2260 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202261}
2262
[email protected]41225fe2013-03-29 05:32:022263int WebContentsImpl::DownloadImage(const GURL& url,
2264 bool is_favicon,
[email protected]263cb08f2013-09-18 00:26:302265 uint32_t max_bitmap_size,
[email protected]41225fe2013-03-29 05:32:022266 const ImageDownloadCallback& callback) {
[email protected]988ed7132014-03-31 16:25:582267 int id = StartDownload(GetMainFrame(), url, is_favicon, max_bitmap_size);
[email protected]41225fe2013-03-29 05:32:022268 image_download_map_[id] = callback;
[email protected]795c28972012-12-06 06:13:392269 return id;
2270}
2271
[email protected]5dcaf8e2013-12-28 01:31:422272bool WebContentsImpl::IsSubframe() const {
2273 return is_subframe_;
2274}
2275
[email protected]9649d492014-01-10 07:15:522276void WebContentsImpl::SetZoomLevel(double level) {
2277 Send(new ViewMsg_SetZoomLevel(GetRoutingID(), level));
2278 BrowserPluginEmbedder* embedder = GetBrowserPluginEmbedder();
2279 if (embedder)
2280 embedder->SetZoomLevel(level);
2281}
2282
[email protected]36ec24f2014-01-09 00:32:082283void WebContentsImpl::Find(int request_id,
2284 const base::string16& search_text,
2285 const blink::WebFindOptions& options) {
2286 Send(new ViewMsg_Find(GetRoutingID(), request_id, search_text, options));
2287}
2288
2289void WebContentsImpl::StopFinding(StopFindAction action) {
2290 Send(new ViewMsg_StopFinding(GetRoutingID(), action));
2291}
2292
[email protected]4fe53add2014-04-08 19:53:362293void WebContentsImpl::InsertCSS(const std::string& css) {
2294 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
2295 GetMainFrame()->GetRoutingID(), css));
2296}
2297
[email protected]b172aee2012-04-10 17:05:262298bool WebContentsImpl::FocusLocationBarByDefault() {
[email protected]6286a372013-10-09 04:03:272299 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]081dc522013-05-15 04:59:202300 if (entry && entry->GetURL() == GURL(kAboutBlankURL))
[email protected]0c9406632013-02-08 01:13:332301 return true;
2302 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:272303}
2304
[email protected]b172aee2012-04-10 17:05:262305void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:272306 if (delegate_)
2307 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:212308}
2309
[email protected]52913802013-12-10 05:52:182310void WebContentsImpl::DidStartProvisionalLoad(
2311 RenderFrameHostImpl* render_frame_host,
[email protected]501052ff2014-02-21 22:19:072312 int parent_routing_id,
[email protected]52913802013-12-10 05:52:182313 const GURL& validated_url,
2314 bool is_error_page,
2315 bool is_iframe_srcdoc) {
[email protected]61ac9e242014-03-21 20:55:262316 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]52913802013-12-10 05:52:182317 if (is_main_frame)
[email protected]d974a0a2013-01-10 01:43:572318 DidChangeLoadProgress(0);
2319
[email protected]0d60f0192011-04-14 12:40:102320 // Notify observers about the start of the provisional load.
[email protected]161eabd2014-03-19 19:47:272321 int render_frame_id = render_frame_host->GetRoutingID();
2322 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]d8c660432011-12-22 20:51:252323 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]501052ff2014-02-21 22:19:072324 DidStartProvisionalLoadForFrame(
[email protected]161eabd2014-03-19 19:47:272325 render_frame_id, parent_routing_id, is_main_frame,
2326 validated_url, is_error_page, is_iframe_srcdoc,
2327 render_view_host));
[email protected]400992b2012-06-14 00:03:542328
2329 if (is_main_frame) {
[email protected]52913802013-12-10 05:52:182330 FOR_EACH_OBSERVER(
2331 WebContentsObserver,
2332 observers_,
2333 ProvisionalChangeToMainFrameUrl(validated_url,
[email protected]66256d72014-01-10 22:41:582334 render_frame_host));
[email protected]400992b2012-06-14 00:03:542335 }
2336}
2337
[email protected]3109fbb72014-01-06 23:57:152338void WebContentsImpl::DidFailProvisionalLoadWithError(
2339 RenderFrameHostImpl* render_frame_host,
2340 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
2341 GURL validated_url(params.url);
[email protected]161eabd2014-03-19 19:47:272342 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262343 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272344 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3109fbb72014-01-06 23:57:152345 FOR_EACH_OBSERVER(
2346 WebContentsObserver,
2347 observers_,
[email protected]161eabd2014-03-19 19:47:272348 DidFailProvisionalLoad(render_frame_id,
[email protected]3109fbb72014-01-06 23:57:152349 params.frame_unique_name,
[email protected]61ac9e242014-03-21 20:55:262350 is_main_frame,
[email protected]3109fbb72014-01-06 23:57:152351 validated_url,
2352 params.error_code,
2353 params.error_description,
[email protected]161eabd2014-03-19 19:47:272354 render_view_host));
[email protected]3109fbb72014-01-06 23:57:152355}
2356
[email protected]b80624c2014-02-09 02:46:552357void WebContentsImpl::DidFailLoadWithError(
2358 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:552359 const GURL& url,
[email protected]b80624c2014-02-09 02:46:552360 int error_code,
2361 const base::string16& error_description) {
[email protected]161eabd2014-03-19 19:47:272362 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]61ac9e242014-03-21 20:55:262363 bool is_main_frame = render_frame_host->frame_tree_node()->IsMainFrame();
[email protected]161eabd2014-03-19 19:47:272364 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]b80624c2014-02-09 02:46:552365 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272366 DidFailLoad(render_frame_id, url, is_main_frame, error_code,
[email protected]61ac9e242014-03-21 20:55:262367 error_description, render_view_host));
[email protected]b80624c2014-02-09 02:46:552368}
2369
[email protected]52913802013-12-10 05:52:182370void WebContentsImpl::NotifyChangedNavigationState(
2371 InvalidateTypes changed_flags) {
2372 NotifyNavigationStateChanged(changed_flags);
2373}
2374
[email protected]3691e5cf2014-01-22 10:16:202375void WebContentsImpl::AboutToNavigateRenderFrame(
2376 RenderFrameHostImpl* render_frame_host) {
2377 // Notify observers that we will navigate in this RenderView.
[email protected]161eabd2014-03-19 19:47:272378 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]3691e5cf2014-01-22 10:16:202379 FOR_EACH_OBSERVER(
2380 WebContentsObserver,
2381 observers_,
[email protected]161eabd2014-03-19 19:47:272382 AboutToNavigateRenderView(render_view_host));
[email protected]3691e5cf2014-01-22 10:16:202383}
2384
2385void WebContentsImpl::DidStartNavigationToPendingEntry(
2386 RenderFrameHostImpl* render_frame_host,
2387 const GURL& url,
2388 NavigationController::ReloadType reload_type) {
2389 // Notify observers about navigation.
2390 FOR_EACH_OBSERVER(
2391 WebContentsObserver,
2392 observers_,
2393 DidStartNavigationToPendingEntry(url, reload_type));
2394}
2395
[email protected]8cb834e2014-03-06 14:23:232396void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
2397 const OpenURLParams& params) {
2398 int source_render_frame_id = render_frame_host->GetRoutingID();
[email protected]65920f332014-03-04 21:14:182399 WebContents* new_contents = OpenURL(params);
2400
2401 if (new_contents) {
2402 // Notify observers.
2403 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2404 DidOpenRequestedURL(new_contents,
2405 params.url,
2406 params.referrer,
2407 params.disposition,
2408 params.transition,
[email protected]8cb834e2014-03-06 14:23:232409 source_render_frame_id));
[email protected]65920f332014-03-04 21:14:182410 }
2411}
2412
[email protected]aa62afd2014-04-22 19:22:462413bool WebContentsImpl::ShouldPreserveAbortedURLs() {
2414 if (!delegate_)
2415 return false;
2416 return delegate_->ShouldPreserveAbortedURLs(this);
2417}
2418
[email protected]400992b2012-06-14 00:03:542419void WebContentsImpl::DidRedirectProvisionalLoad(
[email protected]66256d72014-01-10 22:41:582420 RenderFrameHostImpl* render_frame_host,
2421 const GURL& validated_target_url) {
[email protected]400992b2012-06-14 00:03:542422 // Notify observers about the provisional change in the main frame URL.
[email protected]66256d72014-01-10 22:41:582423 FOR_EACH_OBSERVER(
2424 WebContentsObserver,
2425 observers_,
2426 ProvisionalChangeToMainFrameUrl(validated_target_url,
2427 render_frame_host));
[email protected]724159a2010-12-30 01:11:182428}
2429
[email protected]37567b432014-02-12 01:12:222430void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:432431 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:222432 const base::string16& frame_unique_name,
2433 bool is_main_frame,
2434 const GURL& url,
[email protected]27dd82fd2014-03-03 22:11:432435 PageTransition transition_type) {
[email protected]27dd82fd2014-03-03 22:11:432436 int render_frame_id = render_frame_host->GetRoutingID();
[email protected]161eabd2014-03-19 19:47:272437 RenderViewHost* render_view_host = render_frame_host->render_view_host();
[email protected]37567b432014-02-12 01:12:222438 // Notify observers about the commit of the provisional load.
2439 FOR_EACH_OBSERVER(
2440 WebContentsObserver,
2441 observers_,
[email protected]27dd82fd2014-03-03 22:11:432442 DidCommitProvisionalLoadForFrame(render_frame_id,
[email protected]37567b432014-02-12 01:12:222443 frame_unique_name,
2444 is_main_frame,
2445 url,
2446 transition_type,
2447 render_view_host));
2448}
2449
[email protected]0d0f4c492014-04-02 06:42:572450void WebContentsImpl::DidNavigateMainFramePreCommit(
2451 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2452 // Ensure fullscreen mode is exited before committing the navigation to a
2453 // different page. The next page will not start out assuming it is in
2454 // fullscreen mode.
[email protected]dfc39cb2014-04-09 22:58:192455 if (controller_.IsURLInPageNavigation(params.url,
2456 params.was_within_same_page,
2457 NAVIGATION_TYPE_UNKNOWN)) {
2458 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:572459 return;
2460 }
2461 if (IsFullscreenForCurrentTab())
2462 GetRenderViewHost()->ExitFullscreen();
2463 DCHECK(!IsFullscreenForCurrentTab());
2464}
2465
[email protected]37567b432014-02-12 01:12:222466void WebContentsImpl::DidNavigateMainFramePostCommit(
2467 const LoadCommittedDetails& details,
2468 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
2469 if (details.is_navigation_to_different_page()) {
2470 // Clear the status bubble. This is a workaround for a bug where WebKit
2471 // doesn't let us know that the cursor left an element during a
2472 // transition (this is also why the mouse cursor remains as a hand after
2473 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2474 // clear the bubble when a user navigates to a named anchor in the same
2475 // page.
2476 UpdateTargetURL(details.entry->GetPageID(), GURL());
2477 }
2478
2479 if (!details.is_in_page) {
2480 // Once the main frame is navigated, we're no longer considered to have
2481 // displayed insecure content.
2482 displayed_insecure_content_ = false;
2483 SSLManager::NotifySSLInternalStateChanged(
2484 GetController().GetBrowserContext());
2485 }
2486
2487 // Notify observers about navigation.
2488 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2489 DidNavigateMainFrame(details, params));
2490
2491 if (delegate_) {
2492 delegate_->DidNavigateMainFramePostCommit(this);
2493 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
2494 }
2495}
2496
2497void WebContentsImpl::DidNavigateAnyFramePostCommit(
2498 RenderFrameHostImpl* render_frame_host,
2499 const LoadCommittedDetails& details,
2500 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:102501 // Now that something has committed, we don't need to track whether the
2502 // initial page has been accessed.
2503 has_accessed_initial_document_ = false;
2504
[email protected]37567b432014-02-12 01:12:222505 // If we navigate off the page, close all JavaScript dialogs.
2506 if (dialog_manager_ && !details.is_in_page)
2507 dialog_manager_->CancelActiveAndPendingDialogs(this);
2508
2509 // Notify observers about navigation.
2510 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2511 DidNavigateAnyFrame(details, params));
2512}
2513
2514void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
2515 contents_mime_type_ = mime_type;
2516}
2517
2518bool WebContentsImpl::CanOverscrollContent() {
2519 if (delegate_)
2520 return delegate_->CanOverscrollContent();
2521
2522 return false;
2523}
2524
[email protected]b172aee2012-04-10 17:05:262525void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:182526 const GURL& url,
[email protected]70435962011-08-02 20:13:282527 const std::string& security_info,
2528 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:182529 const std::string& mime_type,
[email protected]70435962011-08-02 20:13:282530 ResourceType::Type resource_type) {
[email protected]28620862011-03-22 23:07:192531 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:182532 cache.Increment();
2533
2534 // Send out a notification that we loaded a resource from our memory cache.
[email protected]70d66502011-09-23 00:55:082535 int cert_id = 0;
2536 net::CertStatus cert_status = 0;
2537 int security_bits = -1;
2538 int connection_status = 0;
[email protected]0bbd63b2013-11-29 00:02:122539 SignedCertificateTimestampIDStatusList signed_certificate_timestamp_ids;
[email protected]8ff00d72012-10-23 19:12:212540 DeserializeSecurityInfo(security_info, &cert_id, &cert_status,
[email protected]0bbd63b2013-11-29 00:02:122541 &security_bits, &connection_status,
2542 &signed_certificate_timestamp_ids);
2543 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details
[email protected]8ff00d72012-10-23 19:12:212544 LoadFromMemoryCacheDetails details(
[email protected]a02cf4c2012-06-20 01:02:002545 url, GetRenderProcessHost()->GetID(), cert_id, cert_status, http_method,
2546 mime_type, resource_type);
[email protected]724159a2010-12-30 01:11:182547
[email protected]b0f724c2013-09-05 04:21:132548 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
2549
2550 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2551 DidLoadResourceFromMemoryCache(details));
2552
[email protected]8bfc8272013-09-09 20:10:532553 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
2554 scoped_refptr<net::URLRequestContextGetter> request_context(
2555 resource_type == ResourceType::MEDIA ?
2556 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
2557 GetRenderProcessHost()->GetID()) :
2558 GetBrowserContext()->GetRequestContextForRenderProcess(
2559 GetRenderProcessHost()->GetID()));
2560 BrowserThread::PostTask(
2561 BrowserThread::IO,
2562 FROM_HERE,
2563 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
2564 }
[email protected]724159a2010-12-30 01:11:182565}
2566
[email protected]b172aee2012-04-10 17:05:262567void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:392568 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:182569 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192570 SSLManager::NotifySSLInternalStateChanged(
2571 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182572}
2573
[email protected]b172aee2012-04-10 17:05:262574void WebContentsImpl::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:022575 const std::string& security_origin, const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:582576 LOG(WARNING) << security_origin << " ran insecure content from "
2577 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:392578 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
[email protected]82114f52012-03-20 22:53:412579 if (EndsWith(security_origin, kDotGoogleDotCom, false))
[email protected]e6e30ac2014-01-13 21:24:392580 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:182581 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]f2b58c4d2011-06-01 23:29:412582 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:192583 SSLManager::NotifySSLInternalStateChanged(
2584 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:182585}
2586
[email protected]501052ff2014-02-21 22:19:072587void WebContentsImpl::OnDocumentLoadedInFrame() {
[email protected]1d62cf72014-02-07 21:31:572588 CHECK(render_frame_message_source_);
2589 CHECK(!render_view_message_source_);
2590 RenderFrameHostImpl* rfh =
2591 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
2592
[email protected]161eabd2014-03-19 19:47:272593 int render_frame_id = rfh->GetRoutingID();
2594 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]1d62cf72014-02-07 21:31:572595 FOR_EACH_OBSERVER(WebContentsObserver,
2596 observers_,
[email protected]161eabd2014-03-19 19:47:272597 DocumentLoadedInFrame(render_frame_id, render_view_host));
[email protected]724159a2010-12-30 01:11:182598}
2599
[email protected]b172aee2012-04-10 17:05:262600void WebContentsImpl::OnDidFinishLoad(
[email protected]61ac9e242014-03-21 20:55:262601 const GURL& url) {
[email protected]028053d42014-03-05 22:20:372602 if (!render_frame_message_source_) {
[email protected]8b3af1e2014-01-24 13:29:122603 RecordAction(base::UserMetricsAction("BadMessageTerminate_RVD2"));
2604 GetRenderProcessHost()->ReceivedBadMessage();
2605 return;
2606 }
[email protected]a1b99262013-12-27 21:56:222607
[email protected]8b3af1e2014-01-24 13:29:122608 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:442609 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:372610 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:422611 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:372612
[email protected]61ac9e242014-03-21 20:55:262613 RenderFrameHostImpl* rfh =
2614 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]161eabd2014-03-19 19:47:272615 int render_frame_id = rfh->GetRoutingID();
2616 RenderViewHost* render_view_host = rfh->render_view_host();
[email protected]61ac9e242014-03-21 20:55:262617 bool is_main_frame = rfh->frame_tree_node()->IsMainFrame();
[email protected]d8c660432011-12-22 20:51:252618 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]161eabd2014-03-19 19:47:272619 DidFinishLoad(render_frame_id, validated_url,
2620 is_main_frame, render_view_host));
[email protected]1a55c5be2011-11-29 11:36:312621}
2622
[email protected]b172aee2012-04-10 17:05:262623void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
[email protected]0449c3f2014-02-28 20:31:222624 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
2625 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:262626}
2627
[email protected]b172aee2012-04-10 17:05:262628void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
2629 int maximum_percent,
2630 bool remember) {
[email protected]216813952011-05-19 22:21:262631 minimum_zoom_percent_ = minimum_percent;
2632 maximum_zoom_percent_ = maximum_percent;
2633 temporary_zoom_settings_ = !remember;
2634}
2635
[email protected]b172aee2012-04-10 17:05:262636void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:342637 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:432638 if (!delegate_)
2639 return;
2640
[email protected]b9535422012-02-09 01:47:592641 ChildProcessSecurityPolicyImpl* policy =
2642 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:222643 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:592644 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:212645}
2646
[email protected]b172aee2012-04-10 17:05:262647void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
2648 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:262649 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:362650 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:432651 if (!delegate_)
2652 return;
2653
[email protected]b9535422012-02-09 01:47:592654 ChildProcessSecurityPolicyImpl* policy =
2655 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:322656 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:592657 return;
[email protected]8f810632013-06-06 22:33:322658
[email protected]c125e532014-05-10 20:39:062659 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:202660}
2661
[email protected]b172aee2012-04-10 17:05:262662void WebContentsImpl::OnFindReply(int request_id,
2663 int number_of_matches,
2664 const gfx::Rect& selection_rect,
2665 int active_match_ordinal,
2666 bool final_update) {
[email protected]e5f2de02012-07-20 22:15:432667 if (delegate_) {
2668 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
2669 active_match_ordinal, final_update);
2670 }
[email protected]b888919c2011-09-02 00:32:162671}
2672
[email protected]59363fc92012-09-05 03:46:312673#if defined(OS_ANDROID)
2674void WebContentsImpl::OnFindMatchRectsReply(
2675 int version,
2676 const std::vector<gfx::RectF>& rects,
2677 const gfx::RectF& active_rect) {
2678 if (delegate_)
2679 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
2680}
[email protected]583418cc2013-01-17 14:01:102681
[email protected]1ff427972013-02-07 21:14:072682void WebContentsImpl::OnOpenDateTimeDialog(
2683 const ViewHostMsg_DateTimeDialogValue_Params& value) {
[email protected]ee59cbec2013-08-16 14:59:092684 date_time_chooser_->ShowDialog(ContentViewCore::FromWebContents(this),
2685 GetRenderViewHost(),
2686 value.dialog_type,
[email protected]e8072562013-12-04 06:04:132687 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:092688 value.minimum,
2689 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:172690 value.step,
2691 value.suggestions);
[email protected]583418cc2013-01-17 14:01:102692}
2693
[email protected]59363fc92012-09-05 03:46:312694#endif
2695
[email protected]f114fa42013-12-06 17:06:442696void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
2697 const base::FilePath& path,
2698 bool is_hung) {
2699 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
2700
2701 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2702 PluginHungStatusChanged(plugin_child_id, path, is_hung));
2703}
2704
2705void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
[email protected]cf4d6e742013-01-10 14:06:422706 base::ProcessId plugin_pid) {
[email protected]3fc07c52012-04-20 00:27:442707 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]cf4d6e742013-01-10 14:06:422708 PluginCrashed(plugin_path, plugin_pid));
[email protected]d952a052011-09-06 18:42:452709}
2710
[email protected]cfa856d62014-02-22 07:58:402711void WebContentsImpl::OnDomOperationResponse(const std::string& json_string,
2712 int automation_id) {
2713 DomOperationNotificationDetails details(json_string, automation_id);
2714 NotificationService::current()->Notify(
2715 NOTIFICATION_DOM_OPERATION_RESPONSE,
2716 Source<WebContents>(this),
2717 Details<DomOperationNotificationDetails>(&details));
2718}
2719
[email protected]b172aee2012-04-10 17:05:262720void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
2721 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:102722 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:252723 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:102724 AppCacheAccessed(manifest_url, blocked_by_policy));
2725}
2726
[email protected]8bc5ff02013-11-29 06:34:032727void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:482728 int color_chooser_id,
2729 SkColor color,
2730 const std::vector<ColorSuggestion>& suggestions) {
[email protected]aa62afd2014-04-22 19:22:462731 ColorChooser* new_color_chooser = delegate_ ?
2732 delegate_->OpenColorChooser(this, color, suggestions) :
2733 NULL;
[email protected]820957a2014-01-14 14:56:302734 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:212735 return;
[email protected]8ed16472014-04-11 19:02:482736 if (color_chooser_info_.get())
2737 color_chooser_info_->chooser->End();
2738
2739 color_chooser_info_.reset(new ColorChooserInfo(
2740 render_frame_message_source_->GetProcess()->GetID(),
2741 render_frame_message_source_->GetRoutingID(),
2742 new_color_chooser,
2743 color_chooser_id));
[email protected]da8543762012-03-20 08:52:202744}
2745
[email protected]b172aee2012-04-10 17:05:262746void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:482747 if (color_chooser_info_ &&
2748 color_chooser_id == color_chooser_info_->identifier)
2749 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:202750}
2751
[email protected]b172aee2012-04-10 17:05:262752void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:322753 SkColor color) {
[email protected]8ed16472014-04-11 19:02:482754 if (color_chooser_info_ &&
2755 color_chooser_id == color_chooser_info_->identifier)
2756 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:202757}
2758
[email protected]d0759f492012-04-19 22:50:502759// This exists for render views that don't have a WebUI, but do have WebUI
2760// bindings enabled.
2761void WebContentsImpl::OnWebUISend(const GURL& source_url,
2762 const std::string& name,
2763 const base::ListValue& args) {
2764 if (delegate_)
2765 delegate_->WebUISend(this, source_url, name, args);
2766}
2767
[email protected]d8415ad92012-08-23 14:40:502768void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:442769 int routing_id,
[email protected]d8415ad92012-08-23 14:40:502770 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:342771 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:162772 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:442773 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162774 return;
[email protected]d8415ad92012-08-23 14:40:502775 }
2776
[email protected]8c8fc292012-11-23 18:57:162777 if (!delegate_->RequestPpapiBrokerPermission(
2778 this, url, plugin_path,
2779 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:442780 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:162781 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:442782 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:162783 }
[email protected]d8415ad92012-08-23 14:40:502784}
2785
[email protected]ea0309c2013-08-06 19:35:442786void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:502787 bool result) {
[email protected]ea0309c2013-08-06 19:35:442788 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:502789}
2790
[email protected]c4538072013-03-18 02:17:552791void WebContentsImpl::OnBrowserPluginMessage(const IPC::Message& message) {
[email protected]19be7a62012-10-01 23:03:372792 // This creates a BrowserPluginEmbedder, which handles all the BrowserPlugin
[email protected]b479912c2013-01-23 00:07:082793 // specific messages for this WebContents. This means that any message from
[email protected]c4538072013-03-18 02:17:552794 // a BrowserPlugin prior to this will be ignored.
[email protected]7a846df2012-09-20 19:17:392795 // For more info, see comment above classes BrowserPluginEmbedder and
2796 // BrowserPluginGuest.
2797 CHECK(!browser_plugin_embedder_.get());
[email protected]8eb04562013-03-06 03:41:142798 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
[email protected]b479912c2013-01-23 00:07:082799 browser_plugin_embedder_->OnMessageReceived(message);
[email protected]19be7a62012-10-01 23:03:372800}
2801
[email protected]41225fe2013-03-29 05:32:022802void WebContentsImpl::OnDidDownloadImage(
[email protected]795c28972012-12-06 06:13:392803 int id,
[email protected]749fadd2013-05-15 08:37:482804 int http_status_code,
[email protected]795c28972012-12-06 06:13:392805 const GURL& image_url,
[email protected]263cb08f2013-09-18 00:26:302806 const std::vector<SkBitmap>& bitmaps,
2807 const std::vector<gfx::Size>& original_bitmap_sizes) {
[email protected]229ef3b2014-01-21 07:46:132808 if (bitmaps.size() != original_bitmap_sizes.size())
2809 return;
2810
[email protected]41225fe2013-03-29 05:32:022811 ImageDownloadMap::iterator iter = image_download_map_.find(id);
2812 if (iter == image_download_map_.end()) {
[email protected]795c28972012-12-06 06:13:392813 // Currently WebContents notifies us of ANY downloads so that it is
2814 // possible to get here.
2815 return;
2816 }
2817 if (!iter->second.is_null()) {
[email protected]263cb08f2013-09-18 00:26:302818 iter->second.Run(
2819 id, http_status_code, image_url, bitmaps, original_bitmap_sizes);
[email protected]795c28972012-12-06 06:13:392820 }
[email protected]41225fe2013-03-29 05:32:022821 image_download_map_.erase(id);
[email protected]795c28972012-12-06 06:13:392822}
2823
2824void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:392825 const std::vector<FaviconURL>& candidates) {
2826 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292827 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:392828}
2829
[email protected]1dd0bb752014-02-01 01:16:262830void WebContentsImpl::OnMediaPlayingNotification(int64 player_cookie,
2831 bool has_video,
2832 bool has_audio) {
2833// Chrome OS does its own detection of audio and video.
2834#if !defined(OS_CHROMEOS)
2835 scoped_ptr<PowerSaveBlocker> blocker;
2836 if (has_video) {
2837 blocker = PowerSaveBlocker::Create(
2838 PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, "Playing video");
2839#if defined(OS_ANDROID)
2840 static_cast<PowerSaveBlockerImpl*>(blocker.get())
2841 ->InitDisplaySleepBlocker(GetView()->GetNativeView());
2842#endif
2843 } else if (has_audio) {
2844 blocker = PowerSaveBlocker::Create(
2845 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, "Playing audio");
2846 }
2847
2848 if (blocker) {
[email protected]96307312014-05-04 01:00:192849 power_save_blockers_[render_frame_message_source_][player_cookie] =
[email protected]1dd0bb752014-02-01 01:16:262850 blocker.release();
2851 }
2852#endif // !defined(OS_CHROMEOS)
2853}
2854
2855void WebContentsImpl::OnMediaPausedNotification(int64 player_cookie) {
[email protected]d9030b82013-07-19 08:26:062856 // Chrome OS does its own detection of audio and video.
2857#if !defined(OS_CHROMEOS)
[email protected]96307312014-05-04 01:00:192858 delete power_save_blockers_[render_frame_message_source_][player_cookie];
2859 power_save_blockers_[render_frame_message_source_].erase(player_cookie);
[email protected]d9030b82013-07-19 08:26:062860#endif // !defined(OS_CHROMEOS)
2861}
2862
[email protected]50279492014-05-05 23:24:292863void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:152864 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:292865 DidFirstVisuallyNonEmptyPaint());
[email protected]9f268072013-11-07 00:02:152866}
[email protected]d9030b82013-07-19 08:26:062867
[email protected]e67ebf32013-02-13 11:07:192868void WebContentsImpl::DidChangeVisibleSSLState() {
2869 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2870 DidChangeVisibleSSLState());
2871}
2872
[email protected]17e286e2013-03-01 23:29:392873void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
2874 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2875 BeforeFormRepostWarningShow());
2876}
2877
[email protected]ec6c05f2013-10-23 18:41:572878
2879void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
2880 Activate();
2881 if (delegate_)
2882 delegate_->ShowRepostFormWarningDialog(this);
2883}
2884
[email protected]b4c84012014-04-28 19:51:102885bool WebContentsImpl::HasAccessedInitialDocument() {
2886 return has_accessed_initial_document_;
2887}
2888
[email protected]96d185d2009-04-24 03:28:542889// Notifies the RenderWidgetHost instance about the fact that the page is
[email protected]91621872013-10-08 04:04:592890// loading, or done loading.
2891void WebContentsImpl::SetIsLoading(RenderViewHost* render_view_host,
2892 bool is_loading,
[email protected]e3b10d12014-03-28 16:06:092893 bool to_different_document,
[email protected]b172aee2012-04-10 17:05:262894 LoadNotificationDetails* details) {
[email protected]96d185d2009-04-24 03:28:542895 if (is_loading == is_loading_)
2896 return;
2897
2898 if (!is_loading) {
[email protected]fcf75d42013-12-03 20:11:262899 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
2900 base::string16());
[email protected]96d185d2009-04-24 03:28:542901 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:562902 upload_size_ = 0;
2903 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:542904 }
2905
[email protected]fa944cb82013-11-15 17:51:212906 GetRenderManager()->SetIsLoading(is_loading);
[email protected]96d185d2009-04-24 03:28:542907
2908 is_loading_ = is_loading;
2909 waiting_for_response_ = is_loading;
2910
[email protected]6ebdc9b2010-09-27 16:55:572911 if (delegate_)
[email protected]e3b10d12014-03-28 16:06:092912 delegate_->LoadingStateChanged(this, to_different_document);
[email protected]8ff00d72012-10-23 19:12:212913 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
[email protected]96d185d2009-04-24 03:28:542914
[email protected]eab61442013-11-14 18:35:482915 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
[email protected]91621872013-10-08 04:04:592916 if (is_loading) {
[email protected]eab61442013-11-14 18:35:482917 TRACE_EVENT_ASYNC_BEGIN1("browser", "WebContentsImpl Loading", this,
2918 "URL", url);
[email protected]91621872013-10-08 04:04:592919 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2920 DidStartLoading(render_view_host));
2921 } else {
[email protected]eab61442013-11-14 18:35:482922 TRACE_EVENT_ASYNC_END1("browser", "WebContentsImpl Loading", this,
2923 "URL", url);
[email protected]91621872013-10-08 04:04:592924 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2925 DidStopLoading(render_view_host));
2926 }
[email protected]66798902013-10-01 18:40:162927
2928 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212929 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
2930 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:542931 if (details)
[email protected]8ff00d72012-10-23 19:12:212932 det = Details<LoadNotificationDetails>(details);
2933 NotificationService::current()->Notify(
2934 type, Source<NavigationController>(&controller_), det);
[email protected]96d185d2009-04-24 03:28:542935}
2936
[email protected]959be4c2014-04-08 15:01:332937void WebContentsImpl::SelectRange(const gfx::Point& start,
2938 const gfx::Point& end) {
2939 RenderFrameHost* focused_frame = GetFocusedFrame();
2940 if (!focused_frame)
2941 return;
2942
2943 focused_frame->Send(
2944 new InputMsg_SelectRange(focused_frame->GetRoutingID(), start, end));
2945}
2946
[email protected]b172aee2012-04-10 17:05:262947void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:462948 // If we are creating a RVH for a restored controller, then we need to make
2949 // sure the RenderView starts with a next_page_id_ larger than the number
2950 // of restored entries. This must be called before the RenderView starts
2951 // navigating (to avoid a race between the browser updating max_page_id and
2952 // the renderer updating next_page_id_). Because of this, we only call this
2953 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:562954 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:582955 if (max_restored_page_id >
2956 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
2957 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
2958 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:322959}
2960
[email protected]b172aee2012-04-10 17:05:262961bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:262962 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:322963 // For file URLs without a title, use the pathname instead. In the case of a
2964 // synthesized title, we don't want the update to count toward the "one set
2965 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:262966 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:322967 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:512968 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:242969 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322970 explicit_set = false; // Don't count synthetic titles toward the set limit.
2971 } else {
[email protected]8af69c6c2014-03-03 19:05:312972 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322973 explicit_set = true;
2974 }
2975
[email protected]987fc3a2011-05-26 14:18:092976 // If a page is created via window.open and never navigated,
2977 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:552978 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:092979 if (entry) {
[email protected]36fc0392011-12-25 03:59:512980 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:092981 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:322982
[email protected]36fc0392011-12-25 03:59:512983 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:092984 } else {
2985 if (page_title_when_no_navigation_entry_ == final_title)
2986 return false; // Nothing changed, don't bother.
2987
2988 page_title_when_no_navigation_entry_ = final_title;
2989 }
[email protected]420ae012009-04-24 05:16:322990
[email protected]420ae012009-04-24 05:16:322991 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:232992 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:322993
[email protected]66798902013-10-01 18:40:162994 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:532995 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:162996
2997 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:212998 std::pair<NavigationEntry*, bool> details =
[email protected]2bb171882012-03-07 02:09:462999 std::make_pair(entry, explicit_set);
[email protected]8ff00d72012-10-23 19:12:213000 NotificationService::current()->Notify(
3001 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
3002 Source<WebContents>(this),
3003 Details<std::pair<NavigationEntry*, bool> >(&details));
[email protected]cbc0e1b2010-04-12 18:33:043004
[email protected]420ae012009-04-24 05:16:323005 return true;
3006}
3007
[email protected]7b712ee22013-10-03 00:57:283008void WebContentsImpl::NotifySwapped(RenderViewHost* old_host,
3009 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323010 // After sending out a swap notification, we need to send a disconnect
3011 // notification so that clients that pick up a pointer to |this| can NULL the
3012 // pointer. See Bug 1230284.
3013 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113014 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283015 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113016
3017 // TODO(avi): Remove. http://crbug.com/170921
[email protected]7b712ee22013-10-03 00:57:283018 std::pair<RenderViewHost*, RenderViewHost*> details =
3019 std::make_pair(old_host, new_host);
[email protected]8ff00d72012-10-23 19:12:213020 NotificationService::current()->Notify(
[email protected]7b712ee22013-10-03 00:57:283021 NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
[email protected]8ff00d72012-10-23 19:12:213022 Source<WebContents>(this),
[email protected]7b712ee22013-10-03 00:57:283023 Details<std::pair<RenderViewHost*, RenderViewHost*> >(&details));
[email protected]7a846df2012-09-20 19:17:393024
3025 // Ensure that the associated embedder gets cleared after a RenderViewHost
3026 // gets swapped, so we don't reuse the same embedder next time a
3027 // RenderViewHost is attached to this WebContents.
3028 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323029}
3030
[email protected]da7a7182013-09-06 08:11:113031// TODO(avi): Remove this entire function because this notification is already
3032// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263033void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323034 if (!notify_disconnection_)
3035 return;
3036
3037 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213038 NotificationService::current()->Notify(
3039 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3040 Source<WebContents>(this),
3041 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323042}
3043
[email protected]cbb1ef592013-06-05 19:49:463044void WebContentsImpl::NotifyNavigationEntryCommitted(
3045 const LoadCommittedDetails& load_details) {
3046 FOR_EACH_OBSERVER(
3047 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3048}
3049
[email protected]f114fa42013-12-06 17:06:443050bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3051 const IPC::Message& message) {
3052 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313053}
3054
[email protected]c31a84802014-04-03 15:55:493055const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3056 return GetLastCommittedURL();
3057}
3058
[email protected]b849847b2013-12-10 21:57:583059void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
3060 // Note this is only for subframes, the notification for the main frame
3061 // happens in RenderViewCreated.
3062 FOR_EACH_OBSERVER(WebContentsObserver,
3063 observers_,
3064 RenderFrameCreated(render_frame_host));
3065}
3066
3067void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
[email protected]96307312014-05-04 01:00:193068 ClearPowerSaveBlockers(render_frame_host);
[email protected]b849847b2013-12-10 21:57:583069 FOR_EACH_OBSERVER(WebContentsObserver,
3070 observers_,
3071 RenderFrameDeleted(render_frame_host));
3072}
3073
[email protected]a09d53ce2014-01-31 00:46:423074void WebContentsImpl::WorkerCrashed(RenderFrameHost* render_frame_host) {
[email protected]b765deb2013-12-18 06:43:303075 if (delegate_)
3076 delegate_->WorkerCrashed(this);
3077}
3078
[email protected]a09d53ce2014-01-31 00:46:423079void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3080 const ContextMenuParams& params) {
3081 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]63028f52014-02-10 16:45:403082 if (delegate_ && delegate_->HandleContextMenu(params))
[email protected]a09d53ce2014-01-31 00:46:423083 return;
3084
3085 render_view_host_delegate_view_->ShowContextMenu(render_frame_host, params);
3086}
3087
[email protected]87de04b02014-04-08 22:14:493088void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013089 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493090 const base::string16& message,
3091 const base::string16& default_prompt,
3092 const GURL& frame_url,
3093 JavaScriptMessageType javascript_message_type,
3094 IPC::Message* reply_msg) {
3095 // Suppress JavaScript dialogs when requested. Also suppress messages when
3096 // showing an interstitial as it's shown over the previous page and we don't
3097 // want the hidden page's dialogs to interfere with the interstitial.
3098 bool suppress_this_message =
[email protected]39f2f9252014-05-03 00:54:013099 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost())->
[email protected]87de04b02014-04-08 22:14:493100 IsSwappedOut() ||
3101 ShowingInterstitialPage() ||
3102 !delegate_ ||
3103 delegate_->ShouldSuppressDialogs() ||
3104 !delegate_->GetJavaScriptDialogManager();
3105
3106 if (!suppress_this_message) {
3107 std::string accept_lang = GetContentClient()->browser()->
3108 GetAcceptLangs(GetBrowserContext());
3109 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3110 dialog_manager_->RunJavaScriptDialog(
3111 this,
3112 frame_url.GetOrigin(),
3113 accept_lang,
3114 javascript_message_type,
3115 message,
3116 default_prompt,
3117 base::Bind(&WebContentsImpl::OnDialogClosed,
3118 base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013119 render_frame_host->GetProcess()->GetID(),
3120 render_frame_host->GetRoutingID(),
[email protected]87de04b02014-04-08 22:14:493121 reply_msg,
3122 false),
3123 &suppress_this_message);
3124 }
3125
3126 if (suppress_this_message) {
3127 // If we are suppressing messages, just reply as if the user immediately
3128 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013129 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3130 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283131 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493132 }
3133
3134 // OnDialogClosed (two lines up) may have caused deletion of this object (see
3135 // http://crbug.com/288961 ). The only safe thing to do here is return.
3136}
3137
3138void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:013139 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493140 const base::string16& message,
3141 bool is_reload,
3142 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:013143 RenderFrameHostImpl* rfhi =
3144 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:493145 RenderViewHostImpl* rvhi =
[email protected]39f2f9252014-05-03 00:54:013146 static_cast<RenderViewHostImpl*>(render_frame_host->GetRenderViewHost());
[email protected]87de04b02014-04-08 22:14:493147 if (delegate_)
3148 delegate_->WillRunBeforeUnloadConfirm();
3149
3150 bool suppress_this_message =
3151 rvhi->rvh_state() != RenderViewHostImpl::STATE_DEFAULT ||
3152 !delegate_ ||
3153 delegate_->ShouldSuppressDialogs() ||
3154 !delegate_->GetJavaScriptDialogManager();
3155 if (suppress_this_message) {
3156 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
3157 return;
3158 }
3159
3160 is_showing_before_unload_dialog_ = true;
3161 dialog_manager_ = delegate_->GetJavaScriptDialogManager();
3162 dialog_manager_->RunBeforeUnloadDialog(
3163 this, message, is_reload,
3164 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013165 render_frame_host->GetProcess()->GetID(),
3166 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283167 false));
[email protected]87de04b02014-04-08 22:14:493168}
3169
[email protected]a86c0e962013-12-17 17:10:393170WebContents* WebContentsImpl::GetAsWebContents() {
3171 return this;
3172}
3173
[email protected]7912e822014-04-16 02:37:033174bool WebContentsImpl::IsNeverVisible() {
3175 if (!delegate_)
3176 return false;
3177 return delegate_->IsNeverVisible(this);
3178}
3179
[email protected]5a3bdf52012-05-24 15:12:573180RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
3181 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:323182}
3183
[email protected]8ff00d72012-10-23 19:12:213184RendererPreferences WebContentsImpl::GetRendererPrefs(
3185 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:463186 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:513187}
3188
[email protected]b172aee2012-04-10 17:05:263189gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const {
[email protected]b7a756d42012-01-23 18:08:173190 if (delegate_)
3191 return delegate_->GetRootWindowResizerRect();
3192 return gfx::Rect();
3193}
3194
[email protected]7a846df2012-09-20 19:17:393195void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:273196 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:393197 browser_plugin_embedder_.reset();
3198}
3199
[email protected]b172aee2012-04-10 17:05:263200void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:443201 // Don't send notifications if we are just creating a swapped-out RVH for
3202 // the opener chain. These won't be used for view-source or WebUI, so it's
3203 // ok to return early.
[email protected]21b41c7e892014-02-28 01:52:243204 if (static_cast<RenderViewHostImpl*>(render_view_host)->IsSwappedOut())
[email protected]14392a52012-05-02 20:28:443205 return;
3206
[email protected]86f98a22013-03-20 14:35:003207 if (delegate_)
3208 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:083209
[email protected]8ff00d72012-10-23 19:12:213210 NotificationService::current()->Notify(
3211 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
3212 Source<WebContents>(this),
3213 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:323214
3215 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:353216 // use the pending Web UI rather than any possibly existing committed one.
[email protected]fa944cb82013-11-15 17:51:213217 if (GetRenderManager()->pending_web_ui())
3218 GetRenderManager()->pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:323219
[email protected]6286a372013-10-09 04:03:273220 NavigationEntry* entry = controller_.GetPendingEntry();
[email protected]e770b1e92013-08-29 14:26:333221 if (entry && entry->IsViewSourceMode()) {
[email protected]420ae012009-04-24 05:16:323222 // Put the renderer in view source mode.
[email protected]6b618e62012-08-16 12:59:183223 render_view_host->Send(
[email protected]9f76c1e2012-03-05 15:15:583224 new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID()));
[email protected]420ae012009-04-24 05:16:323225 }
[email protected]0666aef2009-05-13 19:48:083226
[email protected]60780f412013-02-25 16:34:103227 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:263228
3229 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:253230 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]b849847b2013-12-10 21:57:583231
3232 // We tell the observers now instead of when the main RenderFrameHostImpl is
3233 // constructed because otherwise it would be too early (i.e. IPCs sent to the
3234 // frame would be dropped because it's not created yet).
[email protected]b370ceb2014-02-28 01:53:363235 RenderFrameHost* main_frame = render_view_host->GetMainFrame();
[email protected]b849847b2013-12-10 21:57:583236 FOR_EACH_OBSERVER(
3237 WebContentsObserver, observers_, RenderFrameCreated(main_frame));
[email protected]420ae012009-04-24 05:16:323238}
3239
[email protected]b172aee2012-04-10 17:05:263240void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:523241 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323242 // Don't notify the world, since this came from a renderer in the
3243 // background.
3244 return;
3245 }
3246
[email protected]da7a7182013-09-06 08:11:113247 notify_disconnection_ = true;
3248 // TODO(avi): Remove. http://crbug.com/170921
3249 NotificationService::current()->Notify(
3250 NOTIFICATION_WEB_CONTENTS_CONNECTED,
3251 Source<WebContents>(this),
3252 NotificationService::NoDetails());
3253
[email protected]be1f56ab2011-12-22 06:55:313254 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:233255 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:303256
3257 // Restore the focus to the tab (otherwise the focus will be on the top
3258 // window).
[email protected]484ae5912010-09-29 19:16:143259 if (was_crashed && !FocusLocationBarByDefault() &&
3260 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:063261 view_->Focus();
[email protected]484ae5912010-09-29 19:16:143262 }
[email protected]32ded2212011-11-10 18:51:433263
[email protected]d8c660432011-12-22 20:51:253264 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:323265}
3266
[email protected]ec6a7eb2013-04-22 17:34:223267void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
3268 base::TerminationStatus status,
3269 int error_code) {
[email protected]151a63d2011-12-20 22:32:523270 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:323271 // The pending page's RenderViewHost is gone.
3272 return;
3273 }
3274
[email protected]2fcdcc32014-03-05 02:14:073275 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
3276 // renderer may not have made a clean exit.
3277 if (IsFullscreenForCurrentTab())
3278 ToggleFullscreenMode(false);
3279
[email protected]698191dc2014-02-25 01:06:133280 // Cancel any visible dialogs so they are not left dangling over the sad tab.
3281 if (dialog_manager_)
3282 dialog_manager_->CancelActiveAndPendingDialogs(this);
3283
[email protected]e3b10d12014-03-28 16:06:093284 SetIsLoading(rvh, false, true, NULL);
[email protected]420ae012009-04-24 05:16:323285 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:233286 SetIsCrashed(status, error_code);
[email protected]fc2b46b2014-05-03 16:33:453287
3288#if defined(OS_ANDROID)
3289 if (GetRenderViewHostImpl()->media_player_manager())
3290 GetRenderViewHostImpl()->media_player_manager()->DestroyAllMediaPlayers();
3291#endif
[email protected]420ae012009-04-24 05:16:323292
[email protected]d8c660432011-12-22 20:51:253293 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:273294 observers_,
[email protected]58d5cfe2013-07-10 02:40:523295 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:323296}
3297
[email protected]b172aee2012-04-10 17:05:263298void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:253299 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:063300}
3301
[email protected]b172aee2012-04-10 17:05:263302void WebContentsImpl::UpdateState(RenderViewHost* rvh,
3303 int32 page_id,
[email protected]691aa2f2013-05-28 22:52:043304 const PageState& page_state) {
[email protected]992db4c2011-05-12 15:37:153305 // Ensure that this state update comes from either the active RVH or one of
3306 // the swapped out RVHs. We don't expect to hear from any other RVHs.
[email protected]94d0cc12013-12-18 00:07:413307 // TODO(nasko): This should go through RenderFrameHost.
3308 // TODO(creis): We can't update state for cross-process subframes until we
3309 // have FrameNavigationEntries. Once we do, this should be a DCHECK.
3310 if (rvh != GetRenderViewHost() &&
3311 !GetRenderManager()->IsRVHOnSwappedOutList(
3312 static_cast<RenderViewHostImpl*>(rvh)))
3313 return;
[email protected]420ae012009-04-24 05:16:323314
3315 // We must be prepared to handle state updates for any page, these occur
3316 // when the user is scrolling and entering form data, as well as when we're
3317 // leaving a page, in which case our state may have already been moved to
3318 // the next page. The navigation controller will look up the appropriate
3319 // NavigationEntry and update it when it is notified via the delegate.
3320
3321 int entry_index = controller_.GetEntryIndexWithPageID(
[email protected]9f76c1e2012-03-05 15:15:583322 rvh->GetSiteInstance(), page_id);
[email protected]420ae012009-04-24 05:16:323323 if (entry_index < 0)
3324 return;
[email protected]10f417c52011-12-28 21:04:233325 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
[email protected]420ae012009-04-24 05:16:323326
[email protected]691aa2f2013-05-28 22:52:043327 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:323328 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:043329 entry->SetPageState(page_state);
[email protected]420ae012009-04-24 05:16:323330 controller_.NotifyEntryChanged(entry, entry_index);
3331}
3332
[email protected]b172aee2012-04-10 17:05:263333void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) {
[email protected]6934a702011-12-20 00:04:513334 if (delegate_)
3335 delegate_->UpdateTargetURL(this, page_id, url);
[email protected]420ae012009-04-24 05:16:323336}
3337
[email protected]b172aee2012-04-10 17:05:263338void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:103339#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:293340 // The UI may be in an event-tracking loop, such as between the
3341 // mouse-down and mouse-up in text selection or a button click.
3342 // Defer the close until after tracking is complete, so that we
3343 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:293344 // TODO(shess): This could get more fine-grained. For instance,
3345 // closing a tab in another window while selecting text in the
3346 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:103347 if (view_->IsEventTracking()) {
3348 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:293349 return;
3350 }
[email protected]60780f412013-02-25 16:34:103351#endif
[email protected]07707302009-11-06 00:50:293352
[email protected]420ae012009-04-24 05:16:323353 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:523354 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:513355 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:323356}
3357
[email protected]66bbadaf2014-03-28 16:25:543358void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:573359 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
3360 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:573361}
3362
[email protected]b172aee2012-04-10 17:05:263363void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:513364 if (delegate_ && delegate_->IsPopupOrPanel(this))
3365 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:323366}
3367
[email protected]e3b10d12014-03-28 16:06:093368void WebContentsImpl::DidStartLoading(RenderFrameHost* render_frame_host,
3369 bool to_different_document) {
3370 SetIsLoading(render_frame_host->GetRenderViewHost(), true,
3371 to_different_document, NULL);
[email protected]420ae012009-04-24 05:16:323372}
3373
[email protected]723971b2014-02-12 11:08:253374void WebContentsImpl::DidStopLoading(RenderFrameHost* render_frame_host) {
[email protected]420ae012009-04-24 05:16:323375 scoped_ptr<LoadNotificationDetails> details;
3376
[email protected]9595fd82013-04-19 21:28:493377 // Use the last committed entry rather than the active one, in case a
3378 // pending entry has been created.
3379 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:203380 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:493381
[email protected]420ae012009-04-24 05:16:323382 // An entry may not exist for a stop when loading an initial blank page or
3383 // if an iframe injected by script into a blank page finishes loading.
3384 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:203385 base::TimeDelta elapsed =
3386 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:323387
3388 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:513389 entry->GetVirtualURL(),
3390 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:323391 elapsed,
3392 &controller_,
3393 controller_.GetCurrentEntryIndex()));
3394 }
3395
[email protected]e3b10d12014-03-28 16:06:093396 SetIsLoading(render_frame_host->GetRenderViewHost(), false, true,
3397 details.get());
[email protected]420ae012009-04-24 05:16:323398}
3399
[email protected]b172aee2012-04-10 17:05:263400void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:163401 controller_.DiscardNonCommittedEntries();
3402
3403 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:213404 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:163405}
3406
[email protected]b172aee2012-04-10 17:05:263407void WebContentsImpl::DidChangeLoadProgress(double progress) {
[email protected]6934a702011-12-20 00:04:513408 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:133409 delegate_->LoadProgressChanged(this, progress);
[email protected]1a3c3cb2010-12-16 21:03:403410}
3411
[email protected]59167c22013-06-03 18:07:323412void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:103413 has_accessed_initial_document_ = true;
3414
[email protected]d1371bf8e2014-04-19 03:26:243415 // We may have left a failed browser-initiated navigation in the address bar
3416 // to let the user edit it and try again. Clear it now that content might
3417 // show up underneath it.
3418 if (!IsLoading() && controller_.GetPendingEntry())
3419 controller_.DiscardPendingEntry();
3420
[email protected]59167c22013-06-03 18:07:323421 // Update the URL display.
3422 NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL);
3423}
3424
[email protected]3f19f1a2014-05-02 05:23:273425void WebContentsImpl::DidDisownOpener(RenderFrameHost* render_frame_host) {
3426 if (opener_) {
3427 // Clear our opener so that future cross-process navigations don't have an
3428 // opener assigned.
3429 RemoveDestructionObserver(opener_);
3430 opener_ = NULL;
3431 }
3432
3433 // Notify all swapped out RenderViewHosts for this tab. This is important
3434 // in case we go back to them, or if another window in those processes tries
3435 // to access window.opener.
3436 GetRenderManager()->DidDisownOpener(render_frame_host->GetRenderViewHost());
3437}
3438
[email protected]39f2f9252014-05-03 00:54:013439void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:293440 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:093441 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293442 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:093443
3444 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:213445 NotificationService::current()->Notify(
3446 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
3447 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:293448 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:083449}
3450
[email protected]ef3adfc2014-05-11 00:04:543451void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
3452 int32 page_id,
3453 const base::string16& title,
3454 base::i18n::TextDirection title_direction) {
3455 RenderViewHost* rvh = render_frame_host->GetRenderViewHost();
3456
3457 // If we have a title, that's a pretty good indication that we've started
3458 // getting useful data.
3459 SetNotWaitingForResponse();
3460
3461 // Try to find the navigation entry, which might not be the current one.
3462 // For example, it might be from a pending RVH for the pending entry.
3463 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
3464 rvh->GetSiteInstance(), page_id);
3465
3466 // We can handle title updates when we don't have an entry in
3467 // UpdateTitleForEntry, but only if the update is from the current RVH.
3468 // TODO(avi): Change to make decisions based on the RenderFrameHost.
3469 if (!entry && rvh != GetRenderViewHost())
3470 return;
3471
3472 // TODO(evan): make use of title_direction.
3473 // http://code.google.com/p/chromium/issues/detail?id=27094
3474 if (!UpdateTitleForEntry(entry, title))
3475 return;
3476
3477 // Broadcast notifications when the UI should be updated.
3478 if (entry == controller_.GetEntryAtOffset(0))
3479 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
3480}
3481
3482void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
3483 const std::string& encoding) {
3484 SetEncoding(encoding);
3485}
3486
[email protected]39f2f9252014-05-03 00:54:013487void WebContentsImpl::DocumentAvailableInMainFrame(
3488 RenderViewHost* render_view_host) {
3489 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3490 DocumentAvailableInMainFrame());
3491}
[email protected]e1c3a552012-05-04 20:51:323492void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
3493 // Tell the active RenderViewHost to run unload handlers and close, as long
3494 // as the request came from a RenderViewHost in the same BrowsingInstance.
3495 // In most cases, we receive this from a swapped out RenderViewHost.
3496 // It is possible to receive it from one that has just been swapped in,
3497 // in which case we might as well deliver the message anyway.
3498 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
3499 GetRenderViewHost()->ClosePage();
3500}
3501
[email protected]f546640b2012-05-15 00:03:493502void WebContentsImpl::RouteMessageEvent(
3503 RenderViewHost* rvh,
3504 const ViewMsg_PostMessage_Params& params) {
3505 // Only deliver the message to the active RenderViewHost if the request
[email protected]0eba810b2012-10-18 03:19:363506 // came from a RenderViewHost in the same BrowsingInstance or if this
3507 // WebContents is dedicated to a browser plugin guest.
3508 // Note: This check means that an embedder could theoretically receive a
3509 // postMessage from anyone (not just its own guests). However, this is
3510 // probably not a risk for apps since other pages won't have references
3511 // to App windows.
3512 if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()) &&
3513 !GetBrowserPluginGuest() && !GetBrowserPluginEmbedder())
[email protected]f546640b2012-05-15 00:03:493514 return;
3515
3516 ViewMsg_PostMessage_Params new_params(params);
3517
[email protected]0bc7f3542013-10-21 15:05:533518 if (!params.message_port_ids.empty()) {
3519 MessagePortMessageFilter* message_port_message_filter =
3520 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost())
3521 ->message_port_message_filter();
[email protected]76ad75f2014-05-09 01:48:093522 message_port_message_filter->UpdateMessagePortsWithNewRoutes(
3523 params.message_port_ids,
3524 &new_params.new_routing_ids);
[email protected]0bc7f3542013-10-21 15:05:533525 }
3526
[email protected]f546640b2012-05-15 00:03:493527 // If there is a source_routing_id, translate it to the routing ID for
3528 // the equivalent swapped out RVH in the target process. If we need
3529 // to create a swapped out RVH for the source tab, we create its opener
3530 // chain as well, since those will also be accessible to the target page.
3531 if (new_params.source_routing_id != MSG_ROUTING_NONE) {
3532 // Try to look up the WebContents for the source page.
3533 WebContentsImpl* source_contents = NULL;
3534 RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID(
3535 rvh->GetProcess()->GetID(), params.source_routing_id);
3536 if (source_rvh) {
3537 source_contents = static_cast<WebContentsImpl*>(
3538 source_rvh->GetDelegate()->GetAsWebContents());
3539 }
3540
3541 if (source_contents) {
[email protected]0eba810b2012-10-18 03:19:363542 if (GetBrowserPluginGuest()) {
3543 // We create a swapped out RenderView for the embedder in the guest's
3544 // render process but we intentionally do not expose the embedder's
3545 // opener chain to it.
3546 new_params.source_routing_id =
3547 source_contents->CreateSwappedOutRenderView(GetSiteInstance());
3548 } else {
3549 new_params.source_routing_id =
3550 source_contents->CreateOpenerRenderViews(GetSiteInstance());
3551 }
[email protected]f546640b2012-05-15 00:03:493552 } else {
3553 // We couldn't find it, so don't pass a source frame.
3554 new_params.source_routing_id = MSG_ROUTING_NONE;
3555 }
3556 }
3557
3558 // In most cases, we receive this from a swapped out RenderViewHost.
3559 // It is possible to receive it from one that has just been swapped in,
3560 // in which case we might as well deliver the message anyway.
[email protected]6b618e62012-08-16 12:59:183561 Send(new ViewMsg_PostMessageEvent(GetRoutingID(), new_params));
[email protected]f546640b2012-05-15 00:03:493562}
3563
[email protected]a796f202012-05-30 14:14:253564bool WebContentsImpl::AddMessageToConsole(int32 level,
[email protected]fcf75d42013-12-03 20:11:263565 const base::string16& message,
[email protected]a796f202012-05-30 14:14:253566 int32 line_no,
[email protected]fcf75d42013-12-03 20:11:263567 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:253568 if (!delegate_)
3569 return false;
3570 return delegate_->AddMessageToConsole(this, level, message, line_no,
3571 source_id);
3572}
3573
[email protected]b172aee2012-04-10 17:05:263574WebPreferences WebContentsImpl::GetWebkitPrefs() {
[email protected]6286a372013-10-09 04:03:273575 // We want to base the page config off of the actual URL, rather than the
3576 // virtual URL.
3577 // TODO(nasko): Investigate how to remove the GetActiveEntry usage here,
3578 // as it is deprecated and can be out of sync with GetRenderViewHost().
[email protected]34b565c2013-09-23 20:14:003579 GURL url = controller_.GetActiveEntry()
3580 ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL();
[email protected]947bb3902013-10-28 18:03:153581
[email protected]fa944cb82013-11-15 17:51:213582 return GetRenderManager()->current_host()->GetWebkitPrefs(url);
[email protected]420ae012009-04-24 05:16:323583}
3584
[email protected]0eba810b2012-10-18 03:19:363585int WebContentsImpl::CreateSwappedOutRenderView(
[email protected]8ff00d72012-10-23 19:12:213586 SiteInstance* instance) {
[email protected]94d0cc12013-12-18 00:07:413587 return GetRenderManager()->CreateRenderFrame(instance, MSG_ROUTING_NONE,
3588 true, true);
[email protected]0eba810b2012-10-18 03:19:363589}
3590
[email protected]b172aee2012-04-10 17:05:263591void WebContentsImpl::OnUserGesture() {
[email protected]ddb85052011-05-18 14:40:273592 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253593 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture());
[email protected]686493142011-07-15 21:47:223594
[email protected]ea114722012-03-12 01:11:253595 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
[email protected]b39e7a88b2012-01-10 21:43:173596 if (rdh) // NULL in unittests.
3597 rdh->OnUserGesture(this);
[email protected]7d472472011-01-22 01:30:253598}
3599
[email protected]b172aee2012-04-10 17:05:263600void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:443601 // Notify observers.
[email protected]d8c660432011-12-22 20:51:253602 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:443603}
3604
[email protected]b172aee2012-04-10 17:05:263605void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh,
[email protected]2e9d79f2013-08-16 05:45:563606 bool is_during_beforeunload,
[email protected]b172aee2012-04-10 17:05:263607 bool is_during_unload) {
[email protected]992db4c2011-05-12 15:37:153608 // Don't show hung renderer dialog for a swapped out RVH.
[email protected]151a63d2011-12-20 22:32:523609 if (rvh != GetRenderViewHost())
[email protected]992db4c2011-05-12 15:37:153610 return;
3611
[email protected]9f76c1e2012-03-05 15:15:583612 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
3613
[email protected]e5fc1632011-08-08 07:51:533614 // Ignore renderer unresponsive event if debugger is attached to the tab
3615 // since the event may be a result of the renderer sitting on a breakpoint.
3616 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:363617 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:533618 return;
3619
[email protected]2e9d79f2013-08-16 05:45:563620 if (is_during_beforeunload || is_during_unload) {
[email protected]420ae012009-04-24 05:16:323621 // Hang occurred while firing the beforeunload/unload handler.
3622 // Pretend the handler fired so tab closing continues as if it had.
[email protected]9f76c1e2012-03-05 15:15:583623 rvhi->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323624
[email protected]fa944cb82013-11-15 17:51:213625 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:323626 return;
3627
3628 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:563629 // nothing we can do to recover. If the hang is in the beforeunload handler,
3630 // pretend the beforeunload listeners have all fired and allow the delegate
3631 // to continue closing; the user will not have the option of cancelling the
3632 // close. Otherwise, pretend the unload listeners have all fired and close
3633 // the tab.
3634 bool close = true;
[email protected]aa62afd2014-04-22 19:22:463635 if (is_during_beforeunload && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:563636 delegate_->BeforeUnloadFired(this, true, &close);
3637 }
3638 if (close)
3639 Close(rvh);
[email protected]420ae012009-04-24 05:16:323640 return;
3641 }
3642
[email protected]9f76c1e2012-03-05 15:15:583643 if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:473644 return;
3645
[email protected]6934a702011-12-20 00:04:513646 if (delegate_)
3647 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:323648}
3649
[email protected]b172aee2012-04-10 17:05:263650void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]6934a702011-12-20 00:04:513651 if (delegate_)
3652 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:323653}
3654
[email protected]b172aee2012-04-10 17:05:263655void WebContentsImpl::LoadStateChanged(
3656 const GURL& url,
3657 const net::LoadStateWithParam& load_state,
3658 uint64 upload_position,
3659 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323660 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563661 upload_position_ = upload_position;
3662 upload_size_ = upload_size;
[email protected]04866c42011-05-03 20:03:503663 load_state_host_ = net::IDNToUnicode(url.host(),
[email protected]8ff00d72012-10-23 19:12:213664 GetContentClient()->browser()->GetAcceptLangs(
[email protected]627e0512011-12-21 22:55:303665 GetBrowserContext()));
[email protected]9c235f042011-08-10 22:28:213666 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:323667 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:463668 if (IsLoading()) {
[email protected]8ff00d72012-10-23 19:12:213669 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB);
[email protected]d9083482012-01-06 00:38:463670 }
[email protected]420ae012009-04-24 05:16:323671}
3672
[email protected]b172aee2012-04-10 17:05:263673void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:553674 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:323675 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:123676 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3677 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:513678 if (delegate_)
3679 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:093680 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:323681}
3682
[email protected]58d5cfe2013-07-10 02:40:523683void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:543684 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233685 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:223686 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543687}
3688
[email protected]b172aee2012-04-10 17:05:263689void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:103690 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:213691 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:263692 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3693 // here during container initialization and normal window size will be set
3694 // later. In case of tab duplication this resizing to 0x0 prevents setting
3695 // normal size later so just ignore it.
3696 if (!size.IsEmpty())
3697 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323698}
3699
[email protected]af905902013-10-01 21:38:513700void WebContentsImpl::CancelModalDialogsForRenderManager() {
3701 // We need to cancel modal dialogs when doing a process swap, since the load
3702 // deferrer would prevent us from swapping out.
3703 if (dialog_manager_)
3704 dialog_manager_->CancelActiveAndPendingDialogs(this);
3705}
3706
[email protected]7b712ee22013-10-03 00:57:283707void WebContentsImpl::NotifySwappedFromRenderManager(RenderViewHost* old_host,
3708 RenderViewHost* new_host) {
3709 NotifySwapped(old_host, new_host);
[email protected]a6b73c62013-02-11 23:05:083710
3711 // Make sure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:003712 if (delegate_)
3713 view_->SetOverscrollControllerEnabled(delegate_->CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:393714
[email protected]7b712ee22013-10-03 00:57:283715 view_->RenderViewSwappedIn(new_host);
[email protected]3a3d47472010-07-15 21:03:543716}
3717
[email protected]14392a52012-05-02 20:28:443718int WebContentsImpl::CreateOpenerRenderViewsForRenderManager(
3719 SiteInstance* instance) {
3720 if (!opener_)
3721 return MSG_ROUTING_NONE;
3722
3723 // Recursively create RenderViews for anything else in the opener chain.
3724 return opener_->CreateOpenerRenderViews(instance);
3725}
3726
3727int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) {
3728 int opener_route_id = MSG_ROUTING_NONE;
3729
3730 // If this tab has an opener, ensure it has a RenderView in the given
3731 // SiteInstance as well.
3732 if (opener_)
3733 opener_route_id = opener_->CreateOpenerRenderViews(instance);
3734
[email protected]45a22ad2013-02-21 03:25:003735 // If any of the renderers (current, pending, or swapped out) for this
3736 // WebContents has the same SiteInstance, use it.
[email protected]fa944cb82013-11-15 17:51:213737 if (GetRenderManager()->current_host()->GetSiteInstance() == instance)
3738 return GetRenderManager()->current_host()->GetRoutingID();
[email protected]0720b532012-08-28 19:23:373739
[email protected]fa944cb82013-11-15 17:51:213740 if (GetRenderManager()->pending_render_view_host() &&
3741 GetRenderManager()->pending_render_view_host()->GetSiteInstance() ==
3742 instance)
3743 return GetRenderManager()->pending_render_view_host()->GetRoutingID();
[email protected]45a22ad2013-02-21 03:25:003744
[email protected]fa944cb82013-11-15 17:51:213745 RenderViewHostImpl* rvh = GetRenderManager()->GetSwappedOutRenderViewHost(
[email protected]0720b532012-08-28 19:23:373746 instance);
3747 if (rvh)
3748 return rvh->GetRoutingID();
3749
[email protected]14392a52012-05-02 20:28:443750 // Create a swapped out RenderView in the given SiteInstance if none exists,
3751 // setting its opener to the given route_id. Return the new view's route_id.
[email protected]94d0cc12013-12-18 00:07:413752 return GetRenderManager()->CreateRenderFrame(instance, opener_route_id,
3753 true, true);
[email protected]14392a52012-05-02 20:28:443754}
3755
[email protected]b172aee2012-04-10 17:05:263756NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:193757 return GetController();
[email protected]3a3d47472010-07-15 21:03:543758}
3759
[email protected]b172aee2012-04-10 17:05:263760WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) {
[email protected]d2353452012-01-19 19:53:563761 return static_cast<WebUIImpl*>(CreateWebUI(url));
[email protected]420ae012009-04-24 05:16:323762}
3763
[email protected]10f417c52011-12-28 21:04:233764NavigationEntry*
[email protected]b172aee2012-04-10 17:05:263765 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:323766 return controller_.GetLastCommittedEntry();
3767}
3768
[email protected]b172aee2012-04-10 17:05:263769bool WebContentsImpl::CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:163770 RenderViewHost* render_view_host,
3771 int opener_route_id,
3772 CrossProcessFrameConnector* frame_connector) {
[email protected]e11f0e92013-06-12 15:12:033773 TRACE_EVENT0("browser", "WebContentsImpl::CreateRenderViewForRenderManager");
[email protected]245f7d52011-11-28 15:36:443774 // Can be NULL during tests.
[email protected]cfd80b02014-05-01 17:46:483775 RenderWidgetHostViewBase* rwh_view;
[email protected]bffc8302014-01-23 20:52:163776 // TODO(kenrb): RenderWidgetHostViewChildFrame special casing is temporary
3777 // until RenderWidgetHost is attached to RenderFrameHost. We need to special
3778 // case this because RWH is still a base class of RenderViewHost, and child
3779 // frame RWHVs are unique in that they do not have their own WebContents.
3780 if (frame_connector) {
3781 RenderWidgetHostViewChildFrame* rwh_view_child =
3782 new RenderWidgetHostViewChildFrame(render_view_host);
3783 frame_connector->set_view(rwh_view_child);
3784 rwh_view = rwh_view_child;
3785 } else {
3786 rwh_view = view_->CreateViewForWidget(render_view_host);
3787 }
[email protected]1a98a932009-11-17 00:12:523788
[email protected]420ae012009-04-24 05:16:323789 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:443790 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:213791 rwh_view->SetSize(GetSizeForNewRenderView());
[email protected]420ae012009-04-24 05:16:323792
[email protected]74ce1ad2011-12-16 21:51:463793 // Make sure we use the correct starting page_id in the new RenderView.
3794 UpdateMaxPageIDIfNecessary(render_view_host);
3795 int32 max_page_id =
[email protected]9f76c1e2012-03-05 15:15:583796 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:463797
[email protected]9f76c1e2012-03-05 15:15:583798 if (!static_cast<RenderViewHostImpl*>(
[email protected]fcf75d42013-12-03 20:11:263799 render_view_host)->CreateRenderView(base::string16(),
[email protected]51dbd1c2012-05-16 00:36:493800 opener_route_id,
[email protected]c7c0d822014-04-16 20:19:493801 max_page_id,
3802 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:523803 return false;
[email protected]14392a52012-05-02 20:28:443804 }
[email protected]a4127722011-04-27 23:13:523805
[email protected]a220b5932013-09-21 03:47:443806#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:503807 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
3808 // linux. See crbug.com/83941.
[email protected]245f7d52011-11-28 15:36:443809 if (rwh_view) {
3810 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
3811 render_widget_host->WasResized();
3812 }
[email protected]f8233cc2011-05-31 20:24:503813#endif
3814
[email protected]420ae012009-04-24 05:16:323815 return true;
3816}
3817
[email protected]7d244f12013-08-22 21:41:513818#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:453819
[email protected]155c7f22013-12-09 17:07:183820base::android::ScopedJavaLocalRef<jobject>
3821WebContentsImpl::GetJavaWebContents() {
3822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3823
3824 WebContentsAndroid* web_contents_android =
3825 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
3826 if (!web_contents_android) {
3827 web_contents_android = new WebContentsAndroid(this);
3828 SetUserData(kWebContentsAndroidKey, web_contents_android);
3829 }
3830 return web_contents_android->GetJavaObject();
3831}
3832
[email protected]7d244f12013-08-22 21:41:513833bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
3834 return CreateRenderViewForRenderManager(GetRenderViewHost(),
[email protected]bffc8302014-01-23 20:52:163835 MSG_ROUTING_NONE,
3836 NULL);
[email protected]7d244f12013-08-22 21:41:513837}
[email protected]fc2b46b2014-05-03 16:33:453838
3839#elif defined(OS_MACOSX)
3840
3841void WebContentsImpl::SetAllowOverlappingViews(bool overlapping) {
3842 view_->SetAllowOverlappingViews(overlapping);
3843}
3844
3845bool WebContentsImpl::GetAllowOverlappingViews() {
3846 return view_->GetAllowOverlappingViews();
3847}
3848
3849void WebContentsImpl::SetOverlayView(WebContents* overlay,
3850 const gfx::Point& offset) {
3851 view_->SetOverlayView(static_cast<WebContentsImpl*>(overlay)->GetView(),
3852 offset);
3853}
3854
3855void WebContentsImpl::RemoveOverlayView() {
3856 view_->RemoveOverlayView();
3857}
3858
[email protected]7d244f12013-08-22 21:41:513859#endif
3860
[email protected]6fba26d2014-04-29 09:38:283861void WebContentsImpl::OnDialogClosed(int render_process_id,
3862 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:263863 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:493864 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:263865 bool success,
[email protected]fcf75d42013-12-03 20:11:263866 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:283867 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
3868 render_frame_id);
[email protected]87de04b02014-04-08 22:14:493869 last_dialog_suppressed_ = dialog_was_suppressed;
3870
[email protected]beb440c2009-11-06 04:08:543871 if (is_showing_before_unload_dialog_ && !success) {
3872 // If a beforeunload dialog is canceled, we need to stop the throbber from
3873 // spinning, since we forced it to start spinning in Navigate.
[email protected]6fba26d2014-04-29 09:38:283874 if (rfh)
3875 DidStopLoading(rfh);
[email protected]15d160c02012-07-04 10:52:353876 controller_.DiscardNonCommittedEntries();
[email protected]ec8e8b02013-06-19 04:57:103877
[email protected]6d65a462013-06-21 21:29:123878 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3879 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:543880 }
[email protected]87de04b02014-04-08 22:14:493881
[email protected]beb440c2009-11-06 04:08:543882 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:283883 if (rfh) {
3884 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
3885 dialog_was_suppressed);
3886 } else {
3887 // Don't leak the sync IPC reply if the RFH or process is gone.
3888 delete reply_msg;
3889 }
[email protected]beb440c2009-11-06 04:08:543890}
3891
[email protected]b172aee2012-04-10 17:05:263892void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:543893 if (encoding == last_reported_encoding_)
3894 return;
3895 last_reported_encoding_ = encoding;
3896
3897 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:123898 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:103899}
[email protected]f45d2a72010-03-08 23:28:353900
[email protected]b172aee2012-04-10 17:05:263901void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
[email protected]cfd80b02014-05-01 17:46:483902 RenderWidgetHostViewBase* rwh_view = view_->CreateViewForWidget(rvh);
[email protected]245f7d52011-11-28 15:36:443903 // Can be NULL during tests.
3904 if (rwh_view)
[email protected]fc2b46b2014-05-03 16:33:453905 rwh_view->SetSize(GetContainerBounds().size());
[email protected]33f74972010-12-08 16:40:363906}
[email protected]9f76c1e2012-03-05 15:15:583907
[email protected]1ac10dca2013-08-20 20:47:043908bool WebContentsImpl::IsHidden() {
3909 return capturer_count_ == 0 && !should_normally_be_visible_;
3910}
3911
[email protected]b0936d22013-11-28 06:47:363912RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:213913 return frame_tree_.root()->render_manager();
3914}
3915
[email protected]b172aee2012-04-10 17:05:263916RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() {
[email protected]9f76c1e2012-03-05 15:15:583917 return static_cast<RenderViewHostImpl*>(GetRenderViewHost());
3918}
[email protected]7900bfdb2012-05-24 19:31:243919
[email protected]f8497342013-02-05 22:15:023920BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:393921 return browser_plugin_guest_.get();
3922}
3923
[email protected]738f57a2013-06-29 21:06:543924void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
3925 CHECK(!browser_plugin_guest_);
3926 browser_plugin_guest_.reset(guest);
3927}
3928
[email protected]f8497342013-02-05 22:15:023929BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:393930 return browser_plugin_embedder_.get();
3931}
[email protected]8ff00d72012-10-23 19:12:213932
[email protected]d9030b82013-07-19 08:26:063933void WebContentsImpl::ClearPowerSaveBlockers(
[email protected]96307312014-05-04 01:00:193934 RenderFrameHost* render_frame_host) {
3935 STLDeleteValues(&power_save_blockers_[render_frame_host]);
3936 power_save_blockers_.erase(render_frame_host);
[email protected]d9030b82013-07-19 08:26:063937}
3938
3939void WebContentsImpl::ClearAllPowerSaveBlockers() {
3940 for (PowerSaveBlockerMap::iterator i(power_save_blockers_.begin());
3941 i != power_save_blockers_.end(); ++i)
3942 STLDeleteValues(&power_save_blockers_[i->first]);
3943 power_save_blockers_.clear();
3944}
3945
[email protected]fc2b46b2014-05-03 16:33:453946gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:213947 gfx::Size size;
3948 if (delegate_)
3949 size = delegate_->GetSizeForNewRenderView(this);
3950 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:453951 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:213952 return size;
3953}
3954
[email protected]9b159a52013-10-03 17:24:553955void WebContentsImpl::OnFrameRemoved(
3956 RenderViewHostImpl* render_view_host,
[email protected]58faf942014-02-20 21:03:583957 int frame_routing_id) {
[email protected]9b159a52013-10-03 17:24:553958 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]58faf942014-02-20 21:03:583959 FrameDetached(render_view_host, frame_routing_id));
[email protected]9b159a52013-10-03 17:24:553960}
3961
[email protected]222f5822014-02-05 23:40:493962void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
3963 if (!delegate_)
3964 return;
3965 const gfx::Size new_size = GetPreferredSize();
3966 if (new_size != old_size)
3967 delegate_->UpdatePreferredSize(this, new_size);
3968}
3969
[email protected]8ff00d72012-10-23 19:12:213970} // namespace content