blob: 306adc50cec73382ec26602516eef75bd7765de5 [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
avib7348942015-12-25 20:57:107#include <stddef.h>
8
w.shackleton49bcd392016-01-06 17:38:229#include <cmath>
[email protected]2bb171882012-03-07 02:09:4610#include <utility>
[email protected]b75b8292010-10-01 07:28:2511
[email protected]36fb2c7c2011-04-04 15:49:0812#include "base/command_line.h"
[email protected]cbb1ef592013-06-05 19:49:4613#include "base/lazy_instance.h"
skyostil95082a62015-06-05 19:53:0714#include "base/location.h"
[email protected]6d636e62013-07-31 03:15:5615#include "base/logging.h"
avib7348942015-12-25 20:57:1016#include "base/macros.h"
dmazzonid95ae842016-04-12 21:17:3917#include "base/memory/ref_counted.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]04cbd3d2013-12-04 04:58:2019#include "base/process/process.h"
erikchen35629cc2015-03-10 20:43:2220#include "base/profiler/scoped_tracker.h"
skyostil95082a62015-06-05 19:53:0721#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5122#include "base/strings/string16.h"
23#include "base/strings/string_number_conversions.h"
24#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0025#include "base/strings/utf_string_conversions.h"
skyostil95082a62015-06-05 19:53:0726#include "base/thread_task_runner_handle.h"
[email protected]a43858f2013-06-28 15:18:3727#include "base/time/time.h"
ssid3e765612015-01-28 04:03:4228#include "base/trace_event/trace_event.h"
avib7348942015-12-25 20:57:1029#include "build/build_config.h"
rsleevic327b48f82015-04-30 02:03:2530#include "components/mime_util/mime_util.h"
rsleevi24f64dc22015-08-07 21:39:2131#include "components/url_formatter/url_formatter.h"
[email protected]95640212014-07-26 18:14:3032#include "content/browser/accessibility/accessibility_mode_helper.h"
33#include "content/browser/accessibility/browser_accessibility_state_impl.h"
jamescookda2505812015-03-20 18:01:1834#include "content/browser/bad_message.h"
[email protected]7a846df2012-09-20 19:17:3935#include "content/browser/browser_plugin/browser_plugin_embedder.h"
36#include "content/browser/browser_plugin/browser_plugin_guest.h"
[email protected]b9535422012-02-09 01:47:5937#include "content/browser/child_process_security_policy_impl.h"
[email protected]5f2aa722013-08-07 16:59:4138#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0439#include "content/browser/dom_storage/session_storage_namespace_impl.h"
[email protected]8bd9e562011-08-16 23:55:4640#include "content/browser/download/download_stats.h"
[email protected]aa4f3972012-03-01 18:12:1241#include "content/browser/download/mhtml_generation_manager.h"
[email protected]a53209b2012-01-20 16:48:1642#include "content/browser/download/save_package.h"
paulmeyerc0b762b2016-04-13 11:55:1743#include "content/browser/find_request_manager.h"
[email protected]bffc8302014-01-23 20:52:1644#include "content/browser/frame_host/cross_process_frame_connector.h"
[email protected]d4a8ca482013-10-30 21:06:4045#include "content/browser/frame_host/interstitial_page_impl.h"
46#include "content/browser/frame_host/navigation_entry_impl.h"
clamy0e119882015-07-31 16:12:3347#include "content/browser/frame_host/navigation_handle_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0148#include "content/browser/frame_host/navigator_impl.h"
[email protected]52913802013-12-10 05:52:1849#include "content/browser/frame_host/render_frame_host_impl.h"
lfgdb5c4ed2016-03-04 23:09:0750#include "content/browser/frame_host/render_frame_proxy_host.h"
[email protected]bffc8302014-01-23 20:52:1651#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
blundellc57b93f2014-10-29 13:19:5752#include "content/browser/geolocation/geolocation_service_context.h"
[email protected]5c9250872012-01-30 17:24:0553#include "content/browser/host_zoom_map_impl.h"
[email protected]678c0362012-12-05 08:02:4454#include "content/browser/loader/resource_dispatcher_host_impl.h"
mlamouriefdca9d2014-09-16 16:55:4055#include "content/browser/manifest/manifest_manager_host.h"
dalecurtisbc6572e12014-09-12 19:22:3056#include "content/browser/media/audio_stream_monitor.h"
miu50f97892014-09-22 22:49:5257#include "content/browser/media/capture/web_contents_audio_muter.h"
dalecurtis88c240072015-12-09 02:11:1858#include "content/browser/media/media_web_contents_observer.h"
mlamouri918734092016-03-12 04:47:5259#include "content/browser/media/session/media_session.h"
[email protected]0bc7f3542013-10-21 15:05:5360#include "content/browser/message_port_message_filter.h"
tommyclieb25b2a2014-11-03 19:45:0961#include "content/browser/plugin_content_origin_whitelist.h"
[email protected]f3b1a082011-11-18 00:34:3062#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]21161032014-05-05 16:56:5063#include "content/browser/renderer_host/render_view_host_delegate_view.h"
[email protected]b3c41c0b2012-03-06 15:48:3264#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]bafe6cd2012-05-23 23:09:5065#include "content/browser/renderer_host/render_widget_host_impl.h"
kenrb2a565f82015-09-02 20:24:5966#include "content/browser/renderer_host/render_widget_host_input_event_router.h"
[email protected]cfd80b02014-05-01 17:46:4867#include "content/browser/renderer_host/render_widget_host_view_base.h"
jonross74971522014-09-15 14:16:0968#include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h"
[email protected]b6583592012-01-25 19:52:3369#include "content/browser/site_instance_impl.h"
alogvinovf50445a2015-10-30 13:00:1270#include "content/browser/wake_lock/wake_lock_service_context.h"
lfgc740d4b22016-04-15 16:45:3371#include "content/browser/web_contents/web_contents_view_child_frame.h"
[email protected]b5a40842012-11-28 15:26:1172#include "content/browser/web_contents/web_contents_view_guest.h"
[email protected]eb2ef212013-01-29 04:27:5873#include "content/browser/webui/generic_handler.h"
[email protected]86a0a6e2013-01-28 06:33:0374#include "content/browser/webui/web_ui_controller_factory_registry.h"
[email protected]d2353452012-01-19 19:53:5675#include "content/browser/webui/web_ui_impl.h"
[email protected]8eb04562013-03-06 03:41:1476#include "content/common/browser_plugin/browser_plugin_constants.h"
[email protected]703dd662013-03-05 07:37:4277#include "content/common/browser_plugin/browser_plugin_messages.h"
[email protected]f114fa42013-12-06 17:06:4478#include "content/common/frame_messages.h"
[email protected]1f3fc1d2014-04-03 14:50:1779#include "content/common/input_messages.h"
lfgdb5c4ed2016-03-04 23:09:0780#include "content/common/page_messages.h"
avi286019ce2015-07-29 01:26:5881#include "content/common/site_isolation_policy.h"
[email protected]35be7ec2012-02-12 20:42:5182#include "content/common/ssl_status_serialization.h"
ekaramad2bd4a2f2016-04-06 20:12:4683#include "content/common/text_input_state.h"
[email protected]2c5569662011-03-22 20:45:0284#include "content/common/view_messages.h"
[email protected]31a71eaf2014-03-13 01:47:3685#include "content/public/browser/ax_event_notification_details.h"
[email protected]ccb797302011-12-15 16:55:1186#include "content/public/browser/browser_context.h"
[email protected]139355f2014-05-11 14:21:2887#include "content/public/browser/browser_plugin_guest_manager.h"
[email protected]87f3c082011-10-19 18:07:4488#include "content/public/browser/content_browser_client.h"
[email protected]98f66112012-12-25 12:59:3689#include "content/public/browser/devtools_agent_host.h"
[email protected]e582fdd2011-12-20 16:48:1790#include "content/public/browser/download_manager.h"
[email protected]c5a5c0842012-05-04 20:05:1491#include "content/public/browser/download_url_parameters.h"
[email protected]d9083482012-01-06 00:38:4692#include "content/public/browser/invalidate_type.h"
[email protected]71a88bb2013-02-01 22:05:1593#include "content/public/browser/javascript_dialog_manager.h"
[email protected]a02cf4c2012-06-20 01:02:0094#include "content/public/browser/load_from_memory_cache_details.h"
[email protected]09d31d52012-03-11 22:30:2795#include "content/public/browser/load_notification_details.h"
[email protected]5b96836f2011-12-22 07:39:0096#include "content/public/browser/navigation_details.h"
[email protected]375fa1b2012-05-22 22:05:3797#include "content/public/browser/notification_details.h"
[email protected]be2510c02012-05-28 14:52:1498#include "content/public/browser/notification_service.h"
[email protected]95640212014-07-26 18:14:3099#include "content/public/browser/render_widget_host_iterator.h"
[email protected]55578b0a2012-04-18 14:31:32100#include "content/public/browser/resource_request_details.h"
jonross74971522014-09-15 14:16:09101#include "content/public/browser/screen_orientation_dispatcher_host.h"
estark5ea80e52015-06-19 18:43:12102#include "content/public/browser/security_style_explanations.h"
[email protected]4c3a23582012-08-18 08:54:34103#include "content/public/browser/storage_partition.h"
[email protected]7f6f44c2011-12-14 13:23:38104#include "content/public/browser/user_metrics.h"
[email protected]674bc592011-12-20 23:00:42105#include "content/public/browser/web_contents_delegate.h"
[email protected]e091df82011-10-11 18:13:21106#include "content/public/common/bindings_policy.h"
nickd30fd962015-07-27 21:51:08107#include "content/public/common/browser_plugin_guest_mode.h"
carloskd80262f52015-12-16 14:40:35108#include "content/public/common/browser_side_navigation_policy.h"
[email protected]54087fe2011-10-28 22:02:48109#include "content/public/common/content_constants.h"
[email protected]64d69de42012-02-06 00:19:54110#include "content/public/common/content_switches.h"
[email protected]7940b8e2013-07-25 23:08:49111#include "content/public/common/page_zoom.h"
[email protected]04cbd3d2013-12-04 04:58:20112#include "content/public/common/result_codes.h"
lgarron662dd522015-06-08 23:20:01113#include "content/public/common/security_style.h"
[email protected]a1d29162011-10-14 17:14:03114#include "content/public/common/url_constants.h"
[email protected]f16cc6782013-12-16 23:42:57115#include "content/public/common/url_utils.h"
[email protected]b3a97b52014-07-09 06:25:05116#include "content/public/common/web_preferences.h"
halton.huoca2eabd2015-07-06 08:17:40117#include "mojo/common/url_type_converters.h"
118#include "mojo/converters/geometry/geometry_type_converters.h"
[email protected]8bfc8272013-09-09 20:10:53119#include "net/http/http_cache.h"
120#include "net/http/http_transaction_factory.h"
121#include "net/url_request/url_request_context.h"
[email protected]abe2c032011-03-31 18:49:34122#include "net/url_request/url_request_context_getter.h"
halton.huoca2eabd2015-07-06 08:17:40123#include "skia/public/type_converters.h"
alexmosaedfc6f2016-01-21 23:57:38124#include "third_party/WebKit/public/web/WebSandboxFlags.h"
halton.huoca2eabd2015-07-06 08:17:40125#include "third_party/skia/include/core/SkBitmap.h"
dmazzonid95ae842016-04-12 21:17:39126#include "ui/accessibility/ax_tree_combiner.h"
[email protected]a08412b62012-05-29 21:28:56127#include "ui/base/layout.h"
[email protected]7da9c4c2012-06-12 14:43:01128#include "ui/gfx/display.h"
[email protected]d353541f2012-05-03 22:45:41129#include "ui/gfx/screen.h"
[email protected]66bd5512012-08-01 02:02:52130#include "ui/gl/gl_switches.h"
[email protected]3c733bde2010-12-21 19:56:31131
[email protected]583418cc2013-01-17 14:01:10132#if defined(OS_ANDROID)
hugo.holgersson61288e6c2015-01-28 17:04:40133#include "content/browser/android/content_video_view.h"
mfomitchev2b8b066a2016-01-28 19:23:15134#include "content/browser/android/date_time_chooser_android.h"
dalecurtisc85ed632016-01-13 00:22:46135#include "content/browser/media/android/media_web_contents_observer_android.h"
[email protected]155c7f22013-12-09 17:07:18136#include "content/browser/web_contents/web_contents_android.h"
mfomitchev2b8b066a2016-01-28 19:23:15137#endif // OS_ANDROID
[email protected]583418cc2013-01-17 14:01:10138
[email protected]f66df822012-05-18 16:52:17139#if defined(OS_MACOSX)
[email protected]bafe6cd2012-05-23 23:09:50140#include "base/mac/foundation_util.h"
[email protected]38b098f2012-03-14 21:11:57141#endif
[email protected]3e45ba92009-02-20 21:09:00142
fsamuel9cf7bdf2015-11-20 02:19:32143#if defined(MOJO_SHELL_CLIENT)
144#include "content/browser/web_contents/web_contents_view_mus.h"
145#include "content/public/common/mojo_shell_connection.h"
fsamuel6c6da0232015-11-26 05:13:46146#include "ui/aura/mus/mus_util.h"
fsamuel9cf7bdf2015-11-20 02:19:32147#endif
148
[email protected]8ff00d72012-10-23 19:12:21149namespace content {
[email protected]420ae012009-04-24 05:16:32150namespace {
151
[email protected]960b0372014-05-19 18:01:00152const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
[email protected]82114f52012-03-20 22:53:41153const char kDotGoogleDotCom[] = ".google.com";
[email protected]ca406032011-07-19 21:53:05154
[email protected]155c7f22013-12-09 17:07:18155#if defined(OS_ANDROID)
156const char kWebContentsAndroidKey[] = "web_contents_android";
157#endif // OS_ANDROID
158
[email protected]e4abd3b42013-11-12 18:28:47159base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
[email protected]cbb1ef592013-06-05 19:49:46160g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
161
[email protected]8bfc8272013-09-09 20:10:53162void NotifyCacheOnIO(
163 scoped_refptr<net::URLRequestContextGetter> request_context,
164 const GURL& url,
165 const std::string& http_method) {
gunsche668855c2015-03-05 02:37:58166 net::HttpCache* cache = request_context->GetURLRequestContext()->
167 http_transaction_factory()->GetCache();
168 if (cache)
169 cache->OnExternalCacheHit(url, http_method);
[email protected]8bfc8272013-09-09 20:10:53170}
171
dcheng57e39e22016-01-21 00:25:38172bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
173 for (FrameTreeNode* node : tree->Nodes()) {
174 if (node->current_frame_host()->GetProcess()->GetID() == render_process_id)
175 return true;
alexmos4cf2aa32015-07-15 23:40:43176 }
dcheng57e39e22016-01-21 00:25:38177 return false;
[email protected]95640212014-07-26 18:14:30178}
179
[email protected]95640212014-07-26 18:14:30180void SetAccessibilityModeOnFrame(AccessibilityMode mode,
181 RenderFrameHost* frame_host) {
182 static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode);
183}
184
dtseng0dd3fa12015-07-22 19:00:52185void ResetAccessibility(RenderFrameHost* rfh) {
186 static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset();
187}
188
dmazzonid95ae842016-04-12 21:17:39189using AXTreeSnapshotCallback =
190 base::Callback<void(const ui::AXTreeUpdate&)>;
191
192// Helper class used by WebContentsImpl::RequestAXTreeSnapshot.
193// Handles the callbacks from parallel snapshot requests to each frame,
194// and feeds the results to an AXTreeCombiner, which converts them into a
195// single combined accessibility tree.
196class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> {
197 public:
198 explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback)
199 : callback_(callback) {
200 }
201
202 AXTreeSnapshotCallback AddFrame(bool is_root) {
203 // Adds a reference to |this|.
204 return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot,
205 this,
206 is_root);
207 }
208
209 void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) {
210 combiner_.AddTree(snapshot, is_root);
211 }
212
213 private:
214 friend class base::RefCounted<AXTreeSnapshotCombiner>;
215
216 // This is called automatically after the last call to ReceiveSnapshot
217 // when there are no more references to this object.
218 ~AXTreeSnapshotCombiner() {
219 combiner_.Combine();
220 callback_.Run(combiner_.combined());
221 }
222
223 ui::AXTreeCombiner combiner_;
224 AXTreeSnapshotCallback callback_;
225};
226
[email protected]420ae012009-04-24 05:16:32227} // namespace
228
[email protected]54944cde2012-12-09 09:24:59229WebContents* WebContents::Create(const WebContents::CreateParams& params) {
alexmose201c7cd2015-06-10 17:14:21230 FrameTreeNode* opener_node = nullptr;
231 if (params.opener_render_frame_id != MSG_ROUTING_NONE) {
232 RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID(
233 params.opener_render_process_id, params.opener_render_frame_id);
234 if (opener_rfh)
235 opener_node = opener_rfh->frame_tree_node();
236 }
237 return WebContentsImpl::CreateWithOpener(params, opener_node);
[email protected]d1198fd2012-08-13 22:50:19238}
239
240WebContents* WebContents::CreateWithSessionStorage(
[email protected]54944cde2012-12-09 09:24:59241 const WebContents::CreateParams& params,
[email protected]fdac6ade2013-07-20 01:06:30242 const SessionStorageNamespaceMap& session_storage_namespace_map) {
alexmose201c7cd2015-06-10 17:14:21243 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]fdac6ade2013-07-20 01:06:30244
245 for (SessionStorageNamespaceMap::const_iterator it =
246 session_storage_namespace_map.begin();
247 it != session_storage_namespace_map.end();
248 ++it) {
249 new_contents->GetController()
250 .SetSessionStorageNamespace(it->first, it->second.get());
251 }
252
[email protected]54944cde2012-12-09 09:24:59253 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19254 return new_contents;
[email protected]a81343d232011-12-27 07:39:20255}
[email protected]746d3052012-05-22 15:15:47256
nickf9acfbe2014-12-23 19:12:37257void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting(
258 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46259 g_created_callbacks.Get().push_back(callback);
260}
261
nickf9acfbe2014-12-23 19:12:37262void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting(
263 const CreatedCallback& callback) {
[email protected]cbb1ef592013-06-05 19:49:46264 for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) {
265 if (g_created_callbacks.Get().at(i).Equals(callback)) {
266 g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i);
267 return;
268 }
269 }
270}
271
avidf38c952015-10-27 13:45:13272WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) {
273 if (!rvh)
274 return nullptr;
[email protected]746d3052012-05-22 15:15:47275 return rvh->GetDelegate()->GetAsWebContents();
276}
277
[email protected]a86c0e962013-12-17 17:10:39278WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) {
avidf38c952015-10-27 13:45:13279 if (!rfh)
280 return nullptr;
281 return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents();
[email protected]a86c0e962013-12-17 17:10:39282}
283
[email protected]7fff43e2013-05-21 20:21:10284// WebContentsImpl::DestructionObserver ----------------------------------------
285
286class WebContentsImpl::DestructionObserver : public WebContentsObserver {
287 public:
288 DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents)
289 : WebContentsObserver(watched_contents),
290 owner_(owner) {
291 }
292
293 // WebContentsObserver:
dchengc2282aa2014-10-21 12:07:58294 void WebContentsDestroyed() override {
[email protected]12a46832014-05-09 13:35:58295 owner_->OnWebContentsDestroyed(
296 static_cast<WebContentsImpl*>(web_contents()));
[email protected]7fff43e2013-05-21 20:21:10297 }
298
299 private:
300 WebContentsImpl* owner_;
301
302 DISALLOW_COPY_AND_ASSIGN(DestructionObserver);
303};
304
[email protected]8ed16472014-04-11 19:02:48305WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id,
306 int render_frame_id,
307 ColorChooser* chooser,
308 int identifier)
309 : render_process_id(render_process_id),
310 render_frame_id(render_frame_id),
311 chooser(chooser),
312 identifier(identifier) {
313}
314
315WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() {
316}
317
lazyboy6ec48b2a2015-06-29 15:18:14318// WebContentsImpl::WebContentsTreeNode ----------------------------------------
319WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode()
320 : outer_web_contents_(nullptr),
321 outer_contents_frame_tree_node_id_(
nick2482a2d2015-12-18 01:39:37322 FrameTreeNode::kFrameTreeNodeInvalidId) {
lazyboy6ec48b2a2015-06-29 15:18:14323}
324
325WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() {
326 // Remove child pointer from our parent.
327 if (outer_web_contents_) {
328 ChildrenSet& child_ptrs_in_parent =
329 outer_web_contents_->node_->inner_web_contents_tree_nodes_;
330 ChildrenSet::iterator iter = child_ptrs_in_parent.find(this);
331 DCHECK(iter != child_ptrs_in_parent.end());
332 child_ptrs_in_parent.erase(this);
333 }
334
335 // Remove parent pointers from our children.
336 // TODO(lazyboy): We should destroy the children WebContentses too. If the
337 // children do not manage their own lifetime, then we would leak their
338 // WebContentses.
339 for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_)
340 child->outer_web_contents_ = nullptr;
341}
342
343void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents(
344 WebContentsImpl* outer_web_contents,
345 RenderFrameHostImpl* outer_contents_frame) {
346 outer_web_contents_ = outer_web_contents;
347 outer_contents_frame_tree_node_id_ =
348 outer_contents_frame->frame_tree_node()->frame_tree_node_id();
349
350 if (!outer_web_contents_->node_)
351 outer_web_contents_->node_.reset(new WebContentsTreeNode());
352
353 outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this);
354}
355
[email protected]b172aee2012-04-10 17:05:26356// WebContentsImpl -------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32357
alexmose201c7cd2015-06-10 17:14:21358WebContentsImpl::WebContentsImpl(BrowserContext* browser_context)
[email protected]b680ad22009-04-15 23:19:42359 : delegate_(NULL),
[email protected]69e797f2013-04-30 01:10:22360 controller_(this, browser_context),
[email protected]5a3bdf52012-05-24 15:12:57361 render_view_host_delegate_view_(NULL),
alexmose201c7cd2015-06-10 17:14:21362 created_with_opener_(false),
[email protected]6ea6bdf2013-12-06 13:35:01363 frame_tree_(new NavigatorImpl(&controller_, this),
blundellc57b93f2014-10-29 13:19:57364 this,
365 this,
366 this,
367 this),
[email protected]6dfed692014-05-22 04:18:03368 is_load_to_different_document_(false),
[email protected]443b80e2010-12-14 00:42:23369 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
370 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34371 waiting_for_response_(false),
[email protected]fcf75d42013-12-03 20:11:26372 load_state_(net::LOAD_STATE_IDLE, base::string16()),
[email protected]094e5b22009-09-25 04:23:56373 upload_size_(0),
374 upload_position_(0),
dfalcantarae6b7b46752015-07-10 18:14:16375 is_resume_pending_(false),
[email protected]f17a0ee2010-05-17 17:38:47376 displayed_insecure_content_(false),
[email protected]b4c84012014-04-28 19:51:10377 has_accessed_initial_document_(false),
yusufod41c5f92015-03-06 00:14:28378 theme_color_(SK_ColorTRANSPARENT),
379 last_sent_theme_color_(SK_ColorTRANSPARENT),
peter90afaba2015-06-01 12:05:29380 did_first_visually_non_empty_paint_(false),
[email protected]54597982013-02-06 01:59:55381 capturer_count_(0),
382 should_normally_be_visible_(true),
tapted65ff2ea72016-03-01 23:39:00383 did_first_set_visible_(false),
[email protected]fdd61c62009-04-22 19:22:57384 is_being_destroyed_(false),
385 notify_disconnection_(false),
[email protected]71a88bb2013-02-01 22:05:15386 dialog_manager_(NULL),
[email protected]7ab1e7d62009-10-14 23:32:01387 is_showing_before_unload_dialog_(false),
gab0dccfef2015-05-20 18:43:39388 last_active_time_(base::TimeTicks::Now()),
[email protected]ebf40a72010-07-22 01:46:38389 closed_by_user_gesture_(false),
[email protected]8ff00d72012-10-23 19:12:21390 minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)),
391 maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)),
w.shackleton49bcd392016-01-06 17:38:22392 zoom_scroll_remainder_(0),
[email protected]f114fa42013-12-06 17:06:44393 render_view_message_source_(NULL),
mukai1db093762015-01-27 20:06:55394 render_frame_message_source_(NULL),
[email protected]5dcaf8e2013-12-28 01:31:42395 fullscreen_widget_routing_id_(MSG_ROUTING_NONE),
[email protected]0b431992014-06-24 00:08:03396 fullscreen_widget_had_focus_at_shutdown_(false),
[email protected]87de04b02014-04-08 22:14:49397 is_subframe_(false),
[email protected]34ff1cfc2014-08-20 06:16:05398 force_disable_overscroll_content_(false),
[email protected]95640212014-07-26 18:14:30399 last_dialog_suppressed_(false),
blundellc57b93f2014-10-29 13:19:57400 geolocation_service_context_(new GeolocationServiceContext()),
waffles1c12bf402016-02-10 17:45:48401 accessibility_mode_(
402 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
avayvodcc85bbd2015-08-28 19:11:15403 audio_stream_monitor_(this),
ortunodf4d7982016-04-08 02:33:35404 bluetooth_connected_device_count_(0),
mohan.reddyaae039a2014-11-21 17:39:50405 virtual_keyboard_requested_(false),
mcnee432e47d2015-11-09 19:37:46406 page_scale_factor_is_one_(true),
ekaramad2bd4a2f2016-04-06 20:12:46407 text_input_state_(new TextInputState()),
pkotwicz75ca8ffd2016-02-16 23:10:19408 loading_weak_factory_(this),
409 weak_factory_(this) {
[email protected]9b159a52013-10-03 17:24:55410 frame_tree_.SetFrameRemoveListener(
411 base::Bind(&WebContentsImpl::OnFrameRemoved,
412 base::Unretained(this)));
dalecurtisc85ed632016-01-13 00:22:46413#if defined(OS_ANDROID)
414 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
415#else
qinmin58567c82015-01-07 21:00:20416 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
dalecurtisc85ed632016-01-13 00:22:46417#endif
csharrisona2280cd2016-02-03 23:21:15418 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
alogvinovf50445a2015-10-30 13:00:12419 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
[email protected]332af7732009-03-11 13:21:35420}
initial.commit09911bf2008-07-26 23:55:29421
[email protected]b172aee2012-04-10 17:05:26422WebContentsImpl::~WebContentsImpl() {
[email protected]420ae012009-04-24 05:16:32423 is_being_destroyed_ = true;
424
kenrb2a565f82015-09-02 20:24:59425 rwh_input_event_router_.reset();
426
dcheng72be33c2016-01-21 04:11:31427 for (FrameTreeNode* node : frame_tree_.Nodes()) {
428 // Delete all RFHs pending shutdown, which will lead the corresponding RVHs
429 // to be shutdown and be deleted as well.
dcheng57e39e22016-01-21 00:25:38430 node->render_manager()->ClearRFHsPendingShutdown();
dcheng57e39e22016-01-21 00:25:38431 node->render_manager()->ClearWebUIInstances();
dcheng72be33c2016-01-21 04:11:31432 }
carlosk35f35af2015-12-01 10:55:40433
dcheng57e39e22016-01-21 00:25:38434 for (RenderWidgetHostImpl* widget : created_widgets_)
435 widget->DetachDelegate();
[email protected]b24b68a2012-09-24 21:57:26436 created_widgets_.clear();
437
[email protected]3ab9cb82011-06-03 18:02:07438 // Clear out any JavaScript state.
[email protected]71a88bb2013-02-01 22:05:15439 if (dialog_manager_)
avi2460c762015-04-17 15:21:54440 dialog_manager_->ResetDialogState(this);
[email protected]3ab9cb82011-06-03 18:02:07441
[email protected]8ed16472014-04-11 19:02:48442 if (color_chooser_info_.get())
443 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:20444
[email protected]420ae012009-04-24 05:16:32445 NotifyDisconnected();
[email protected]420ae012009-04-24 05:16:32446
[email protected]ca13a442012-04-17 14:00:12447 // Notify any observer that have a reference on this WebContents.
[email protected]8ff00d72012-10-23 19:12:21448 NotificationService::current()->Notify(
449 NOTIFICATION_WEB_CONTENTS_DESTROYED,
450 Source<WebContents>(this),
451 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:32452
[email protected]df0c843f2014-05-23 20:37:23453 // Destroy all frame tree nodes except for the root; this notifies observers.
nick53d5cbf2015-04-23 22:50:14454 frame_tree_.root()->ResetForNewProcess();
[email protected]df0c843f2014-05-23 20:37:23455 GetRenderManager()->ResetProxyHosts();
[email protected]c06c58c2014-03-12 20:31:59456
clamy0e119882015-07-31 16:12:33457 // Manually call the observer methods for the root frame tree node. It is
458 // necessary to manually delete all objects tracking navigations
459 // (NavigationHandle, NavigationRequest) for observers to be properly
460 // notified of these navigations stopping before the WebContents is
461 // destroyed.
[email protected]df0c843f2014-05-23 20:37:23462 RenderFrameHostManager* root = GetRenderManager();
naskob21fe4872015-02-24 14:15:56463
clamy0e119882015-07-31 16:12:33464 if (root->pending_frame_host()) {
naskob21fe4872015-02-24 14:15:56465 root->pending_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33466 root->pending_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08467 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33468 }
naskob21fe4872015-02-24 14:15:56469 root->current_frame_host()->SetRenderFrameCreated(false);
clamy0e119882015-07-31 16:12:33470 root->current_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08471 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33472
473 // PlzNavigate: clear up state specific to browser-side navigation.
carloskd80262f52015-12-16 14:40:35474 if (IsBrowserSideNavigationEnabled()) {
clamy82a2f4d2016-02-02 14:20:41475 // Do not update state as the WebContents is being destroyed.
476 frame_tree_.root()->ResetNavigationRequest(true);
clamy0e119882015-07-31 16:12:33477 if (root->speculative_frame_host()) {
478 root->speculative_frame_host()->SetRenderFrameCreated(false);
479 root->speculative_frame_host()->SetNavigationHandle(
dcheng59716272016-04-09 05:19:08480 std::unique_ptr<NavigationHandleImpl>());
clamy0e119882015-07-31 16:12:33481 }
482 }
[email protected]f273ee52013-10-18 16:05:27483
naskoa83483fb2015-02-27 16:57:10484 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
485 FrameDeleted(root->current_frame_host()));
486
[email protected]df0c843f2014-05-23 20:37:23487 if (root->pending_render_view_host()) {
488 FOR_EACH_OBSERVER(WebContentsObserver,
489 observers_,
490 RenderViewDeleted(root->pending_render_view_host()));
491 }
[email protected]c06c58c2014-03-12 20:31:59492
[email protected]f273ee52013-10-18 16:05:27493 FOR_EACH_OBSERVER(WebContentsObserver,
494 observers_,
[email protected]df0c843f2014-05-23 20:37:23495 RenderViewDeleted(root->current_host()));
[email protected]f273ee52013-10-18 16:05:27496
[email protected]2db9bd72012-04-13 20:20:56497 FOR_EACH_OBSERVER(WebContentsObserver,
498 observers_,
[email protected]12a46832014-05-09 13:35:58499 WebContentsDestroyed());
500
501 FOR_EACH_OBSERVER(WebContentsObserver,
502 observers_,
503 ResetWebContents());
[email protected]232a5812011-03-04 22:42:08504
[email protected]6934a702011-12-20 00:04:51505 SetDelegate(NULL);
[email protected]7fff43e2013-05-21 20:21:10506
507 STLDeleteContainerPairSecondPointers(destruction_observers_.begin(),
508 destruction_observers_.end());
[email protected]b5a1d11c2011-02-17 03:09:42509}
510
[email protected]d1198fd2012-08-13 22:50:19511WebContentsImpl* WebContentsImpl::CreateWithOpener(
[email protected]54944cde2012-12-09 09:24:59512 const WebContents::CreateParams& params,
alexmose201c7cd2015-06-10 17:14:21513 FrameTreeNode* opener) {
[email protected]e11f0e92013-06-12 15:12:03514 TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener");
alexmose201c7cd2015-06-10 17:14:21515 WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context);
[email protected]d1198fd2012-08-13 22:50:19516
alexmosaedfc6f2016-01-21 23:57:38517 FrameTreeNode* new_root = new_contents->GetFrameTree()->root();
518
alexmose201c7cd2015-06-10 17:14:21519 if (!params.opener_suppressed && opener) {
alexmosaedfc6f2016-01-21 23:57:38520 new_root->SetOpener(opener);
alexmose201c7cd2015-06-10 17:14:21521 new_contents->created_with_opener_ = true;
522 }
523
alexmosaedfc6f2016-01-21 23:57:38524 // If the opener is sandboxed, a new popup must inherit the opener's sandbox
525 // flags, and these flags take effect immediately. An exception is if the
526 // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts
527 // bit (which is controlled by the "allow-popups-to-escape-sandbox" token).
528 // See https://html.spec.whatwg.org/#attr-iframe-sandbox.
529 if (opener) {
530 blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags();
531 const blink::WebSandboxFlags inherit_flag =
532 blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts;
533 if ((opener_flags & inherit_flag) == inherit_flag) {
534 new_root->SetPendingSandboxFlags(opener_flags);
535 new_root->CommitPendingSandboxFlags();
536 }
537 }
538
alexmose201c7cd2015-06-10 17:14:21539 // This may be true even when opener is null, such as when opening blocked
540 // popups.
alexmos090fae8e2015-05-28 17:09:28541 if (params.created_with_opener)
542 new_contents->created_with_opener_ = true;
543
[email protected]4858e432014-06-23 18:14:17544 if (params.guest_delegate) {
[email protected]83100cd2014-05-10 11:50:06545 // This makes |new_contents| act as a guest.
546 // For more info, see comment above class BrowserPluginGuest.
[email protected]2101c4c2014-08-22 00:16:16547 BrowserPluginGuest::Create(new_contents, params.guest_delegate);
[email protected]83100cd2014-05-10 11:50:06548 // We are instantiating a WebContents for browser plugin. Set its subframe
549 // bit to true.
550 new_contents->is_subframe_ = true;
551 }
[email protected]54944cde2012-12-09 09:24:59552 new_contents->Init(params);
[email protected]d1198fd2012-08-13 22:50:19553 return new_contents;
554}
555
[email protected]95640212014-07-26 18:14:30556// static
557std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() {
558 std::vector<WebContentsImpl*> result;
dcheng59716272016-04-09 05:19:08559 std::unique_ptr<RenderWidgetHostIterator> widgets(
[email protected]95640212014-07-26 18:14:30560 RenderWidgetHostImpl::GetRenderWidgetHosts());
[email protected]95640212014-07-26 18:14:30561 while (RenderWidgetHost* rwh = widgets->GetNextHost()) {
[email protected]95640212014-07-26 18:14:30562 RenderViewHost* rvh = RenderViewHost::From(rwh);
563 if (!rvh)
564 continue;
565 WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
566 if (!web_contents)
567 continue;
avidf38c952015-10-27 13:45:13568 if (web_contents->GetRenderViewHost() != rvh)
569 continue;
570 // Because a WebContents can only have one current RVH at a time, there will
571 // be no duplicate WebContents here.
572 result.push_back(static_cast<WebContentsImpl*>(web_contents));
[email protected]95640212014-07-26 18:14:30573 }
574 return result;
575}
576
clamya16aa8172015-05-26 13:07:25577// static
578WebContentsImpl* WebContentsImpl::FromFrameTreeNode(
579 FrameTreeNode* frame_tree_node) {
580 return static_cast<WebContentsImpl*>(
581 WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host()));
582}
583
clamy0d32d6d2015-11-24 11:16:26584// static
585WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id,
586 int render_frame_host_id) {
587 DCHECK_CURRENTLY_ON(BrowserThread::UI);
588 RenderFrameHost* render_frame_host =
589 RenderFrameHost::FromID(render_process_host_id, render_frame_host_id);
590 if (!render_frame_host)
591 return nullptr;
592
593 return WebContents::FromRenderFrameHost(render_frame_host);
594}
595
[email protected]b0936d22013-11-28 06:47:36596RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() {
[email protected]fa944cb82013-11-15 17:51:21597 return GetRenderManager();
[email protected]765187182012-01-11 23:59:28598}
599
[email protected]7bb761892012-07-20 09:32:47600bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
601 const IPC::Message& message) {
[email protected]f114fa42013-12-06 17:06:44602 return OnMessageReceived(render_view_host, NULL, message);
603}
604
605bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host,
606 RenderFrameHost* render_frame_host,
607 const IPC::Message& message) {
608 DCHECK(render_view_host || render_frame_host);
[email protected]d2353452012-01-19 19:53:56609 if (GetWebUI() &&
610 static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) {
[email protected]f82d57b52011-04-27 19:13:17611 return true;
[email protected]d2353452012-01-19 19:53:56612 }
[email protected]f82d57b52011-04-27 19:13:17613
brettw5a1613dc2015-06-02 05:34:43614 base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_);
[email protected]d8c660432011-12-22 20:51:25615 WebContentsObserver* observer;
[email protected]64ffefa2014-05-10 12:06:33616 if (render_frame_host) {
617 while ((observer = it.GetNext()) != NULL)
618 if (observer->OnMessageReceived(message, render_frame_host))
619 return true;
620 } else {
621 while ((observer = it.GetNext()) != NULL)
622 if (observer->OnMessageReceived(message))
623 return true;
624 }
[email protected]403415a2011-01-10 18:57:53625
[email protected]1d62cf72014-02-07 21:31:57626 // Message handlers should be aware of which
627 // RenderViewHost/RenderFrameHost sent the message, which is temporarily
628 // stored in render_(view|frame)_message_source_.
[email protected]b3f957e62014-08-08 10:09:02629 if (render_frame_host)
[email protected]1d62cf72014-02-07 21:31:57630 render_frame_message_source_ = render_frame_host;
[email protected]b3f957e62014-08-08 10:09:02631 else
[email protected]1d62cf72014-02-07 21:31:57632 render_view_message_source_ = render_view_host;
633
[email protected]724159a2010-12-30 01:11:18634 bool handled = true;
[email protected]e44d1342014-05-16 21:29:33635 IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message)
[email protected]cfa856d62014-02-22 07:58:40636 IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse,
637 OnDomOperationResponse)
[email protected]37b64c52014-07-11 21:14:05638 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor,
639 OnThemeColorChanged)
[email protected]8ed16472014-04-11 19:02:48640 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad,
641 OnDocumentLoadedInFrame)
642 IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad)
643 IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser)
644 IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser)
645 IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser,
646 OnSetSelectedColorInColorChooser)
dglazkov79c426102015-08-31 21:22:43647 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint,
[email protected]586871b2014-07-22 17:05:11648 OnFirstVisuallyNonEmptyPaint)
avi7830c852015-08-31 23:46:25649 IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache,
[email protected]724159a2010-12-30 01:11:18650 OnDidLoadResourceFromMemoryCache)
avi3a3332622015-09-01 01:18:54651 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent,
[email protected]724159a2010-12-30 01:11:18652 OnDidDisplayInsecureContent)
avi3a3332622015-09-01 01:18:54653 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent,
[email protected]724159a2010-12-30 01:11:18654 OnDidRunInsecureContent)
estark910b4572015-12-09 20:55:41655 IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors,
656 OnDidDisplayContentWithCertificateErrors)
657 IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors,
658 OnDidRunContentWithCertificateErrors)
[email protected]7d472472011-01-22 01:30:25659 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]216813952011-05-19 22:21:26660 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits)
mcnee432e47d2015-11-09 19:37:46661 IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged,
662 OnPageScaleFactorChanged)
[email protected]3a29a6e2011-08-24 18:26:21663 IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory)
avia23e16b2015-07-09 14:18:48664 IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler,
665 OnRegisterProtocolHandler)
666 IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler,
667 OnUnregisterProtocolHandler)
kouhei40f03cb2015-09-24 07:47:01668 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals,
669 OnUpdatePageImportanceSignals)
paulmeyer5d0a5f02016-01-21 20:15:52670 IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply)
[email protected]7fc4bbb2011-09-08 21:23:10671 IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed)
[email protected]d0759f492012-04-19 22:50:50672 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend)
thestigc4cac8f2014-09-04 21:17:50673#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:00674 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated,
675 OnPepperInstanceCreated)
676 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted,
677 OnPepperInstanceDeleted)
tommyclie6633ca72014-10-31 00:40:42678 IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung)
679 IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed)
[email protected]d8415ad92012-08-23 14:40:50680 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission,
681 OnRequestPpapiBrokerPermission)
[email protected]c4538072013-03-18 02:17:55682 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach,
fsamuel833ee7c2015-02-13 23:40:40683 OnBrowserPluginMessage(render_frame_host,
684 message))
thestigc4cac8f2014-09-04 21:17:50685#endif
[email protected]41225fe2013-03-29 05:32:02686 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]edc3af82013-12-12 21:24:07687 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage,
688 OnShowValidationMessage)
689 IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage,
690 OnHideValidationMessage)
691 IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage,
692 OnMoveValidationMessage)
mfomitchev2b8b066a2016-01-28 19:23:15693#if defined(OS_ANDROID)
paulmeyer5d0a5f02016-01-21 20:15:52694 IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply,
[email protected]8ed16472014-04-11 19:02:48695 OnFindMatchRectsReply)
696 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog,
697 OnOpenDateTimeDialog)
[email protected]8ed16472014-04-11 19:02:48698#endif
[email protected]724159a2010-12-30 01:11:18699 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]e44d1342014-05-16 21:29:33700 IPC_END_MESSAGE_MAP()
[email protected]f114fa42013-12-06 17:06:44701 render_view_message_source_ = NULL;
[email protected]1d62cf72014-02-07 21:31:57702 render_frame_message_source_ = NULL;
[email protected]724159a2010-12-30 01:11:18703
[email protected]724159a2010-12-30 01:11:18704 return handled;
705}
706
nasko907fcb62015-01-28 04:24:11707bool WebContentsImpl::HasValidFrameSource() {
708 if (!render_frame_message_source_) {
709 DCHECK(render_view_message_source_);
jamescookda2505812015-03-20 18:01:18710 bad_message::ReceivedBadMessage(GetRenderProcessHost(),
711 bad_message::WC_INVALID_FRAME_SOURCE);
nasko907fcb62015-01-28 04:24:11712 return false;
713 }
714
715 return true;
716}
717
[email protected]b172aee2012-04-10 17:05:26718void WebContentsImpl::RunFileChooser(
[email protected]6c2e472f2011-08-24 23:26:18719 RenderViewHost* render_view_host,
[email protected]8ff00d72012-10-23 19:12:21720 const FileChooserParams& params) {
[email protected]e5f2de02012-07-20 22:15:43721 if (delegate_)
722 delegate_->RunFileChooser(this, params);
[email protected]6c2e472f2011-08-24 23:26:18723}
724
[email protected]d1198fd2012-08-13 22:50:19725NavigationControllerImpl& WebContentsImpl::GetController() {
[email protected]f5fa20e2011-12-21 22:35:56726 return controller_;
727}
728
[email protected]d1198fd2012-08-13 22:50:19729const NavigationControllerImpl& WebContentsImpl::GetController() const {
[email protected]f5fa20e2011-12-21 22:35:56730 return controller_;
731}
732
[email protected]8ff00d72012-10-23 19:12:21733BrowserContext* WebContentsImpl::GetBrowserContext() const {
[email protected]a26023822011-12-29 00:23:55734 return controller_.GetBrowserContext();
[email protected]627e0512011-12-21 22:55:30735}
736
[email protected]b172aee2012-04-10 17:05:26737const GURL& WebContentsImpl::GetURL() const {
[email protected]c854a7e2013-05-21 16:42:24738 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32739 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]36fc0392011-12-25 03:59:51740 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
[email protected]be1f56ab2011-12-22 06:55:31741}
742
[email protected]a093ce02013-07-22 20:53:14743const GURL& WebContentsImpl::GetVisibleURL() const {
[email protected]c854a7e2013-05-21 16:42:24744 // We may not have a navigation entry yet.
[email protected]59167c22013-06-03 18:07:32745 NavigationEntry* entry = controller_.GetVisibleEntry();
[email protected]c854a7e2013-05-21 16:42:24746 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
747}
748
749const GURL& WebContentsImpl::GetLastCommittedURL() const {
750 // We may not have a navigation entry yet.
751 NavigationEntry* entry = controller_.GetLastCommittedEntry();
752 return entry ? entry->GetVirtualURL() : GURL::EmptyGURL();
753}
754
[email protected]8ff00d72012-10-23 19:12:21755WebContentsDelegate* WebContentsImpl::GetDelegate() {
[email protected]be1f56ab2011-12-22 06:55:31756 return delegate_;
757}
758
[email protected]8ff00d72012-10-23 19:12:21759void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) {
[email protected]be1f56ab2011-12-22 06:55:31760 // TODO(cbentzel): remove this debugging code?
761 if (delegate == delegate_)
762 return;
763 if (delegate_)
764 delegate_->Detach(this);
765 delegate_ = delegate;
[email protected]a6b73c62013-02-11 23:05:08766 if (delegate_) {
[email protected]be1f56ab2011-12-22 06:55:31767 delegate_->Attach(this);
[email protected]a6b73c62013-02-11 23:05:08768 // Ensure the visible RVH reflects the new delegate's preferences.
[email protected]86f98a22013-03-20 14:35:00769 if (view_)
[email protected]e85165c642014-06-10 14:34:31770 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:08771 }
[email protected]be1f56ab2011-12-22 06:55:31772}
773
[email protected]8ff00d72012-10-23 19:12:21774RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const {
[email protected]fa944cb82013-11-15 17:51:21775 RenderViewHostImpl* host = GetRenderManager()->current_host();
[email protected]82114f52012-03-20 22:53:41776 return host ? host->GetProcess() : NULL;
[email protected]8cb5d5b2010-02-09 11:36:16777}
778
clamydf1975e2015-02-05 19:12:24779RenderFrameHostImpl* WebContentsImpl::GetMainFrame() {
[email protected]94d0cc12013-12-18 00:07:41780 return frame_tree_.root()->current_frame_host();
[email protected]60eca4eb2013-12-06 00:02:16781}
782
nick53d5cbf2015-04-23 22:50:14783RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() {
784 FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame();
785 if (!focused_node)
786 return nullptr;
787 return focused_node->current_frame_host();
[email protected]9c9343b2014-03-08 02:56:07788}
789
rob3e2a0732016-01-06 21:22:09790RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId(
791 int frame_tree_node_id) {
792 FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id);
793 return frame ? frame->current_frame_host() : nullptr;
794}
795
[email protected]a86c0e962013-12-17 17:10:39796void WebContentsImpl::ForEachFrame(
797 const base::Callback<void(RenderFrameHost*)>& on_frame) {
dcheng57e39e22016-01-21 00:25:38798 for (FrameTreeNode* node : frame_tree_.Nodes()) {
799 on_frame.Run(node->current_frame_host());
800 }
[email protected]a86c0e962013-12-17 17:10:39801}
802
dchengafb53e22016-02-04 08:11:08803std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() {
804 std::vector<RenderFrameHost*> frame_hosts;
805 for (FrameTreeNode* node : frame_tree_.Nodes())
806 frame_hosts.push_back(node->current_frame_host());
807 return frame_hosts;
808}
809
lukaszacbdf52e2016-01-15 21:19:51810int WebContentsImpl::SendToAllFrames(IPC::Message* message) {
811 int number_of_messages = 0;
dchengafb53e22016-02-04 08:11:08812 for (RenderFrameHost* rfh : GetAllFrames()) {
lukasza1a9ab2422016-03-02 18:47:25813 if (!rfh->IsRenderFrameLive())
814 continue;
815
dchengafb53e22016-02-04 08:11:08816 ++number_of_messages;
817 IPC::Message* message_copy = new IPC::Message(*message);
818 message_copy->set_routing_id(rfh->GetRoutingID());
819 rfh->Send(message_copy);
820 }
[email protected]a86c0e962013-12-17 17:10:39821 delete message;
lukaszacbdf52e2016-01-15 21:19:51822 return number_of_messages;
[email protected]a86c0e962013-12-17 17:10:39823}
824
lfgdb5c4ed2016-03-04 23:09:07825void WebContentsImpl::SendPageMessage(IPC::Message* msg) {
826 frame_tree_.root()->render_manager()->SendPageMessage(msg);
827}
828
creisc014b402015-04-23 16:41:45829RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const {
[email protected]fa944cb82013-11-15 17:51:21830 return GetRenderManager()->current_host();
[email protected]be1f56ab2011-12-22 06:55:31831}
832
[email protected]6b618e62012-08-16 12:59:18833int WebContentsImpl::GetRoutingID() const {
834 if (!GetRenderViewHost())
835 return MSG_ROUTING_NONE;
836
837 return GetRenderViewHost()->GetRoutingID();
838}
839
creis89a0f782015-05-27 16:13:17840void WebContentsImpl::CancelActiveAndPendingDialogs() {
841 if (dialog_manager_)
842 dialog_manager_->CancelActiveAndPendingDialogs(this);
843 if (browser_plugin_embedder_)
844 browser_plugin_embedder_->CancelGuestDialogs();
845}
846
[email protected]44470a22013-01-24 01:21:54847int WebContentsImpl::GetFullscreenWidgetRoutingID() const {
848 return fullscreen_widget_routing_id_;
849}
850
naskoc0fceff2015-04-30 15:53:52851void WebContentsImpl::ClosePage() {
852 GetRenderViewHost()->ClosePage();
853}
854
[email protected]b172aee2012-04-10 17:05:26855RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const {
[email protected]fa944cb82013-11-15 17:51:21856 return GetRenderManager()->GetRenderWidgetHostView();
[email protected]be1f56ab2011-12-22 06:55:31857}
858
[email protected]4aebbca2013-09-17 22:26:49859RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView()
860 const {
861 RenderWidgetHost* const widget_host =
862 RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(),
863 GetFullscreenWidgetRoutingID());
864 return widget_host ? widget_host->GetView() : NULL;
865}
866
[email protected]8ff00d72012-10-23 19:12:21867WebContentsView* WebContentsImpl::GetView() const {
[email protected]be1f56ab2011-12-22 06:55:31868 return view_.get();
869}
870
yusufod41c5f92015-03-06 00:14:28871SkColor WebContentsImpl::GetThemeColor() const {
872 return theme_color_;
873}
874
[email protected]95640212014-07-26 18:14:30875void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) {
876 if (mode == accessibility_mode_)
877 return;
878
879 accessibility_mode_ = mode;
dcheng57e39e22016-01-21 00:25:38880
881 for (FrameTreeNode* node : frame_tree_.Nodes()) {
882 SetAccessibilityModeOnFrame(mode, node->current_frame_host());
883 RenderFrameHost* pending_frame_host =
884 node->render_manager()->pending_frame_host();
885 if (pending_frame_host)
886 SetAccessibilityModeOnFrame(mode, pending_frame_host);
887 }
[email protected]95640212014-07-26 18:14:30888}
889
890void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50891 SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30892}
893
894void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) {
thestigc4cac8f2014-09-04 21:17:50895 SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode));
[email protected]95640212014-07-26 18:14:30896}
897
dmazzoni83ba5c82015-04-14 07:11:51898void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) {
dmazzonid95ae842016-04-12 21:17:39899 // Send a request to each of the frames in parallel. Each one will return
900 // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine
901 // them into a single tree and call |callback| with that result, then
902 // delete |combiner|.
903 AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback);
904 for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) {
905 bool is_root = frame_tree_node->parent() == nullptr;
906 frame_tree_node->current_frame_host()->RequestAXTreeSnapshot(
907 combiner->AddFrame(is_root));
908 }
dmazzoni83ba5c82015-04-14 07:11:51909}
910
dbeama1b926a2015-08-31 23:17:51911WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url,
912 const std::string& frame_name) {
913 DCHECK(!frame_name.empty());
914 return CreateWebUI(url, frame_name);
[email protected]c63cedf22012-01-17 18:42:22915}
916
[email protected]8ff00d72012-10-23 19:12:21917WebUI* WebContentsImpl::GetWebUI() const {
carlosk35f35af2015-12-01 10:55:40918 WebUI* commited_web_ui = GetCommittedWebUI();
919 return commited_web_ui ? commited_web_ui
920 : GetRenderManager()->GetNavigatingWebUI();
[email protected]be1f56ab2011-12-22 06:55:31921}
922
[email protected]8ff00d72012-10-23 19:12:21923WebUI* WebContentsImpl::GetCommittedWebUI() const {
carlosk35f35af2015-12-01 10:55:40924 return frame_tree_.root()->current_frame_host()->web_ui();
[email protected]d5f942ba2008-09-26 19:30:34925}
926
[email protected]86ef6a392012-05-11 22:03:11927void WebContentsImpl::SetUserAgentOverride(const std::string& override) {
[email protected]bf70edce2012-06-20 22:32:22928 if (GetUserAgentOverride() == override)
929 return;
930
931 renderer_preferences_.user_agent_override = override;
932
933 // Send the new override string to the renderer.
934 RenderViewHost* host = GetRenderViewHost();
935 if (host)
936 host->SyncRendererPrefs();
937
938 // Reload the page if a load is currently in progress to avoid having
939 // different parts of the page loaded using different user agents.
[email protected]6286a372013-10-09 04:03:27940 NavigationEntry* entry = controller_.GetVisibleEntry();
clamy44e84ce2016-02-22 15:38:25941 if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent())
toyoshim7dad4b1182016-04-01 14:28:05942 controller_.ReloadBypassingCache(true);
[email protected]8d0f3312012-08-18 01:47:53943
944 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
945 UserAgentOverrideSet(override));
[email protected]86ef6a392012-05-11 22:03:11946}
947
948const std::string& WebContentsImpl::GetUserAgentOverride() const {
[email protected]bf70edce2012-06-20 22:32:22949 return renderer_preferences_.user_agent_override;
[email protected]86ef6a392012-05-11 22:03:11950}
951
[email protected]95640212014-07-26 18:14:30952void WebContentsImpl::EnableTreeOnlyAccessibilityMode() {
dchengafb53e22016-02-04 08:11:08953 if (GetAccessibilityMode() != AccessibilityModeOff) {
954 for (RenderFrameHost* rfh : GetAllFrames())
955 ResetAccessibility(rfh);
956 } else {
dtseng0dd3fa12015-07-22 19:00:52957 AddAccessibilityMode(AccessibilityModeTreeOnly);
dchengafb53e22016-02-04 08:11:08958 }
[email protected]95640212014-07-26 18:14:30959}
960
961bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const {
962 return accessibility_mode_ == AccessibilityModeTreeOnly;
963}
964
965bool WebContentsImpl::IsFullAccessibilityModeForTesting() const {
966 return accessibility_mode_ == AccessibilityModeComplete;
967}
968
kouhei40f03cb2015-09-24 07:47:01969const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const {
970 return page_importance_signals_;
971}
972
[email protected]fcf75d42013-12-03 20:11:26973const base::string16& WebContentsImpl::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55974 // Transient entries take precedence. They are used for interstitial pages
975 // that are shown on top of existing pages.
[email protected]10f417c52011-12-28 21:04:23976 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23977 if (entry) {
jshin1fb76462016-04-05 22:13:03978 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:23979 }
carlosk35f35af2015-12-01 10:55:40980
981 WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI();
982 WebUI* our_web_ui = navigating_web_ui
983 ? navigating_web_ui
984 : GetRenderManager()->current_frame_host()->web_ui();
985
[email protected]7ade2732011-02-10 00:13:58986 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54987 // Don't override the title in view source mode.
[email protected]59167c22013-06-03 18:07:32988 entry = controller_.GetVisibleEntry();
[email protected]96d185d2009-04-24 03:28:54989 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35990 // Give the Web UI the chance to override our title.
[email protected]fcf75d42013-12-03 20:11:26991 const base::string16& title = our_web_ui->GetOverriddenTitle();
[email protected]96d185d2009-04-24 03:28:54992 if (!title.empty())
993 return title;
994 }
995 }
996
997 // We use the title for the last committed entry rather than a pending
998 // navigation entry. For example, when the user types in a URL, we want to
999 // keep the old page's title until the new load has committed and we get a new
1000 // title.
[email protected]96d185d2009-04-24 03:28:541001 entry = controller_.GetLastCommittedEntry();
[email protected]59167c22013-06-03 18:07:321002
creis072b61f2015-09-28 20:52:241003 // We make an exception for initial navigations. We only want to use the title
1004 // from the visible entry if:
1005 // 1. The pending entry has been explicitly assigned a title to display.
1006 // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back),
1007 // which case there is a pending entry index other than -1.
1008 //
1009 // Otherwise, we want to stick with the last committed entry's title during
1010 // new navigations, which have pending entries at index -1 with no title.
1011 if (controller_.IsInitialNavigation() &&
1012 ((controller_.GetVisibleEntry() &&
1013 !controller_.GetVisibleEntry()->GetTitle().empty()) ||
1014 controller_.GetPendingEntryIndex() != -1)) {
1015 entry = controller_.GetVisibleEntry();
[email protected]9eeafc012013-11-25 23:49:471016 }
[email protected]59167c22013-06-03 18:07:321017
[email protected]45d0ef7f2011-01-05 13:46:231018 if (entry) {
jshin1fb76462016-04-05 22:13:031019 return entry->GetTitleForDisplay();
[email protected]45d0ef7f2011-01-05 13:46:231020 }
[email protected]987fc3a2011-05-26 14:18:091021
1022 // |page_title_when_no_navigation_entry_| is finally used
1023 // if no title cannot be retrieved.
1024 return page_title_when_no_navigation_entry_;
[email protected]96d185d2009-04-24 03:28:541025}
1026
avib7348942015-12-25 20:57:101027int32_t WebContentsImpl::GetMaxPageID() {
[email protected]74ce1ad2011-12-16 21:51:461028 return GetMaxPageIDForSiteInstance(GetSiteInstance());
1029}
1030
avib7348942015-12-25 20:57:101031int32_t WebContentsImpl::GetMaxPageIDForSiteInstance(
[email protected]b172aee2012-04-10 17:05:261032 SiteInstance* site_instance) {
[email protected]b6583592012-01-25 19:52:331033 if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end())
1034 max_page_ids_[site_instance->GetId()] = -1;
[email protected]74ce1ad2011-12-16 21:51:461035
[email protected]b6583592012-01-25 19:52:331036 return max_page_ids_[site_instance->GetId()];
[email protected]d5f942ba2008-09-26 19:30:341037}
1038
avib7348942015-12-25 20:57:101039void WebContentsImpl::UpdateMaxPageID(int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461040 UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id);
1041}
1042
[email protected]b172aee2012-04-10 17:05:261043void WebContentsImpl::UpdateMaxPageIDForSiteInstance(
avib7348942015-12-25 20:57:101044 SiteInstance* site_instance,
1045 int32_t page_id) {
[email protected]74ce1ad2011-12-16 21:51:461046 if (GetMaxPageIDForSiteInstance(site_instance) < page_id)
[email protected]b6583592012-01-25 19:52:331047 max_page_ids_[site_instance->GetId()] = page_id;
[email protected]d5f942ba2008-09-26 19:30:341048}
1049
[email protected]ec6c05f2013-10-23 18:41:571050void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) {
1051 WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents);
1052 max_page_ids_ = contents->max_page_ids_;
[email protected]91854cd2012-01-10 19:43:571053}
1054
creiscce56cd2014-09-29 22:45:221055SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const {
[email protected]fa944cb82013-11-15 17:51:211056 return GetRenderManager()->current_host()->GetSiteInstance();
[email protected]96d185d2009-04-24 03:28:541057}
1058
creiscce56cd2014-09-29 22:45:221059SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const {
1060 RenderViewHostImpl* dest_rvh =
1061 GetRenderManager()->pending_render_view_host() ?
1062 GetRenderManager()->pending_render_view_host() :
1063 GetRenderManager()->current_host();
[email protected]9f76c1e2012-03-05 15:15:581064 return dest_rvh->GetSiteInstance();
[email protected]77362eb2011-08-01 17:18:381065}
1066
[email protected]b172aee2012-04-10 17:05:261067bool WebContentsImpl::IsLoading() const {
clamy44e84ce2016-02-22 15:38:251068 return frame_tree_.IsLoading() &&
1069 !(ShowingInterstitialPage() &&
1070 GetRenderManager()->interstitial_page()->pause_throbber());
[email protected]3c9e1872010-11-18 16:17:491071}
1072
[email protected]6dfed692014-05-22 04:18:031073bool WebContentsImpl::IsLoadingToDifferentDocument() const {
clamy44e84ce2016-02-22 15:38:251074 return IsLoading() && is_load_to_different_document_;
[email protected]6dfed692014-05-22 04:18:031075}
1076
[email protected]b172aee2012-04-10 17:05:261077bool WebContentsImpl::IsWaitingForResponse() const {
[email protected]6dfed692014-05-22 04:18:031078 return waiting_for_response_ && is_load_to_different_document_;
[email protected]be1f56ab2011-12-22 06:55:311079}
1080
[email protected]b172aee2012-04-10 17:05:261081const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const {
[email protected]be1f56ab2011-12-22 06:55:311082 return load_state_;
1083}
1084
[email protected]fcf75d42013-12-03 20:11:261085const base::string16& WebContentsImpl::GetLoadStateHost() const {
[email protected]be1f56ab2011-12-22 06:55:311086 return load_state_host_;
1087}
1088
avib7348942015-12-25 20:57:101089uint64_t WebContentsImpl::GetUploadSize() const {
[email protected]be1f56ab2011-12-22 06:55:311090 return upload_size_;
1091}
1092
avib7348942015-12-25 20:57:101093uint64_t WebContentsImpl::GetUploadPosition() const {
[email protected]be1f56ab2011-12-22 06:55:311094 return upload_position_;
1095}
1096
[email protected]b172aee2012-04-10 17:05:261097const std::string& WebContentsImpl::GetEncoding() const {
[email protected]ef3adfc2014-05-11 00:04:541098 return canonical_encoding_;
[email protected]be1f56ab2011-12-22 06:55:311099}
1100
[email protected]b172aee2012-04-10 17:05:261101bool WebContentsImpl::DisplayedInsecureContent() const {
[email protected]be1f56ab2011-12-22 06:55:311102 return displayed_insecure_content_;
1103}
1104
[email protected]222f5822014-02-05 23:40:491105void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) {
[email protected]5a652232013-02-12 06:15:251106 DCHECK(!is_being_destroyed_);
[email protected]54597982013-02-06 01:59:551107 ++capturer_count_;
1108 DVLOG(1) << "There are now " << capturer_count_
1109 << " capturing(s) of WebContentsImpl@" << this;
[email protected]222f5822014-02-05 23:40:491110
1111 // Note: This provides a hint to upstream code to size the views optimally
1112 // for quality (e.g., to avoid scaling).
1113 if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) {
1114 preferred_size_for_capture_ = capture_size;
1115 OnPreferredSizeChanged(preferred_size_);
1116 }
ccameron8807c38f2015-01-17 00:29:191117
1118 // Ensure that all views are un-occluded before capture begins.
1119 WasUnOccluded();
[email protected]54597982013-02-06 01:59:551120}
1121
1122void WebContentsImpl::DecrementCapturerCount() {
1123 --capturer_count_;
1124 DVLOG(1) << "There are now " << capturer_count_
1125 << " capturing(s) of WebContentsImpl@" << this;
1126 DCHECK_LE(0, capturer_count_);
1127
[email protected]5a652232013-02-12 06:15:251128 if (is_being_destroyed_)
1129 return;
1130
[email protected]222f5822014-02-05 23:40:491131 if (capturer_count_ == 0) {
1132 const gfx::Size old_size = preferred_size_for_capture_;
1133 preferred_size_for_capture_ = gfx::Size();
1134 OnPreferredSizeChanged(old_size);
1135 }
1136
[email protected]1ac10dca2013-08-20 20:47:041137 if (IsHidden()) {
[email protected]54597982013-02-06 01:59:551138 DVLOG(1) << "Executing delayed WasHidden().";
1139 WasHidden();
1140 }
[email protected]be1f56ab2011-12-22 06:55:311141}
1142
[email protected]f2bd40812013-07-20 04:30:441143int WebContentsImpl::GetCapturerCount() const {
1144 return capturer_count_;
1145}
1146
miu50f97892014-09-22 22:49:521147bool WebContentsImpl::IsAudioMuted() const {
1148 return audio_muter_.get() && audio_muter_->is_muting();
1149}
1150
1151void WebContentsImpl::SetAudioMuted(bool mute) {
1152 DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted()
1153 << " for WebContentsImpl@" << this;
1154
1155 if (mute == IsAudioMuted())
1156 return;
1157
1158 if (mute) {
1159 if (!audio_muter_)
1160 audio_muter_.reset(new WebContentsAudioMuter(this));
1161 audio_muter_->StartMuting();
1162 } else {
1163 DCHECK(audio_muter_);
1164 audio_muter_->StopMuting();
1165 }
1166
wjmaclean2f797c782016-01-07 14:52:031167 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1168 DidUpdateAudioMutingState(mute));
1169
miu50f97892014-09-22 22:49:521170 // Notification for UI updates in response to the changed muting state.
1171 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1172}
1173
ortunodf4d7982016-04-08 02:33:351174void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() {
1175 // Notify for UI updates if the state changes.
1176 bluetooth_connected_device_count_++;
1177 if (bluetooth_connected_device_count_ == 1) {
1178 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1179 }
ortuno32e7db3c2016-03-29 16:14:201180}
1181
ortunodf4d7982016-04-08 02:33:351182void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() {
1183 // Notify for UI updates if the state changes.
1184 DCHECK(bluetooth_connected_device_count_ != 0);
1185 bluetooth_connected_device_count_--;
1186 if (bluetooth_connected_device_count_ == 0) {
1187 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
1188 }
1189}
1190
1191bool WebContentsImpl::IsConnectedToBluetoothDevice() const {
1192 return bluetooth_connected_device_count_ > 0;
ortuno32e7db3c2016-03-29 16:14:201193}
1194
[email protected]b172aee2012-04-10 17:05:261195bool WebContentsImpl::IsCrashed() const {
[email protected]be1f56ab2011-12-22 06:55:311196 return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED ||
1197 crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION ||
wfh0d9532a2015-09-02 23:18:581198 crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ||
oshima620225722015-06-04 19:45:271199#if defined(OS_CHROMEOS)
wfh0d9532a2015-09-02 23:18:581200 crashed_status_ ==
1201 base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM ||
oshima620225722015-06-04 19:45:271202#endif
wfh0d9532a2015-09-02 23:18:581203 crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED
oshima620225722015-06-04 19:45:271204 );
[email protected]3c9e1872010-11-18 16:17:491205}
1206
[email protected]b172aee2012-04-10 17:05:261207void WebContentsImpl::SetIsCrashed(base::TerminationStatus status,
1208 int error_code) {
[email protected]443b80e2010-12-14 00:42:231209 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:341210 return;
1211
[email protected]443b80e2010-12-14 00:42:231212 crashed_status_ = status;
1213 crashed_error_code_ = error_code;
[email protected]8ff00d72012-10-23 19:12:211214 NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB);
[email protected]d5f942ba2008-09-26 19:30:341215}
1216
[email protected]b172aee2012-04-10 17:05:261217base::TerminationStatus WebContentsImpl::GetCrashedStatus() const {
[email protected]be1f56ab2011-12-22 06:55:311218 return crashed_status_;
1219}
1220
afakhry98241832016-03-11 19:27:471221int WebContentsImpl::GetCrashedErrorCode() const {
1222 return crashed_error_code_;
1223}
1224
[email protected]b172aee2012-04-10 17:05:261225bool WebContentsImpl::IsBeingDestroyed() const {
[email protected]be1f56ab2011-12-22 06:55:311226 return is_being_destroyed_;
1227}
1228
[email protected]7f924832014-08-09 05:57:221229void WebContentsImpl::NotifyNavigationStateChanged(
1230 InvalidateTypes changed_flags) {
erikchen174b78c62015-03-11 22:02:541231 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
1232 // is fixed.
1233 tracked_objects::ScopedTracker tracking_profile(
1234 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1235 "466285 WebContentsImpl::NotifyNavigationStateChanged"));
dalecurtis88c240072015-12-09 02:11:181236 // Notify the media observer of potential audibility changes.
1237 if (changed_flags & INVALIDATE_TYPE_TAB) {
mlamouri44e4ef42016-01-20 18:42:271238 media_web_contents_observer_->MaybeUpdateAudibleState();
dalecurtisbc6572e12014-09-12 19:22:301239 }
1240
[email protected]d5f942ba2008-09-26 19:30:341241 if (delegate_)
1242 delegate_->NavigationStateChanged(this, changed_flags);
1243}
1244
gab0dccfef2015-05-20 18:43:391245base::TimeTicks WebContentsImpl::GetLastActiveTime() const {
[email protected]9a890452014-02-13 22:21:021246 return last_active_time_;
[email protected]3e324142012-06-25 18:26:331247}
1248
georgesak5582cbe2015-05-22 22:08:071249void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) {
1250 last_active_time_ = last_active_time;
1251}
1252
[email protected]9e2e4632012-07-27 16:38:411253void WebContentsImpl::WasShown() {
[email protected]96d185d2009-04-24 03:28:541254 controller_.SetActive(true);
[email protected]de3c5d82014-05-28 22:12:591255
ccameron8807c38f2015-01-17 00:29:191256 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1257 if (view) {
1258 view->Show();
[email protected]789e9152009-08-04 21:59:431259#if defined(OS_MACOSX)
ccameron8807c38f2015-01-17 00:29:191260 view->SetActive(true);
[email protected]789e9152009-08-04 21:59:431261#endif
[email protected]de3c5d82014-05-28 22:12:591262 }
[email protected]789e9152009-08-04 21:59:431263 }
[email protected]96d185d2009-04-24 03:28:541264
gab0dccfef2015-05-20 18:43:391265 last_active_time_ = base::TimeTicks::Now();
[email protected]3e69bc82011-05-26 23:22:381266
[email protected]b9769d82012-02-10 00:23:591267 // The resize rect might have changed while this was inactive -- send the new
1268 // one to make sure it's up to date.
creisc014b402015-04-23 16:41:451269 RenderViewHostImpl* rvh = GetRenderViewHost();
avic3aa8422015-11-09 20:57:221270 if (rvh) {
1271 rvh->GetWidget()->ResizeRectChanged(
1272 GetRootWindowResizerRect(rvh->GetWidget()));
1273 }
[email protected]96d185d2009-04-24 03:28:541274
[email protected]c0d9d5672013-10-09 07:38:031275 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown());
1276
[email protected]54597982013-02-06 01:59:551277 should_normally_be_visible_ = true;
[email protected]be1f56ab2011-12-22 06:55:311278}
1279
[email protected]b172aee2012-04-10 17:05:261280void WebContentsImpl::WasHidden() {
[email protected]54597982013-02-06 01:59:551281 // If there are entities capturing screenshots or video (e.g., mirroring),
1282 // don't activate the "disable rendering" optimization.
1283 if (capturer_count_ == 0) {
[email protected]151a63d2011-12-20 22:32:521284 // |GetRenderViewHost()| can be NULL if the user middle clicks a link to
[email protected]54597982013-02-06 01:59:551285 // open a tab in the background, then closes the tab before selecting it.
[email protected]b172aee2012-04-10 17:05:261286 // This is because closing the tab calls WebContentsImpl::Destroy(), which
[email protected]151a63d2011-12-20 22:32:521287 // removes the |GetRenderViewHost()|; then when we actually destroy the
[email protected]3e324142012-06-25 18:26:331288 // window, OnWindowPosChanged() notices and calls WasHidden() (which
[email protected]151a63d2011-12-20 22:32:521289 // calls us).
ccameron8807c38f2015-01-17 00:29:191290 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1291 if (view)
1292 view->Hide();
[email protected]de3c5d82014-05-28 22:12:591293 }
[email protected]96d185d2009-04-24 03:28:541294 }
1295
[email protected]c0d9d5672013-10-09 07:38:031296 FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden());
1297
[email protected]54597982013-02-06 01:59:551298 should_normally_be_visible_ = false;
[email protected]375fa1b2012-05-22 22:05:371299}
1300
ccameron8807c38f2015-01-17 00:29:191301void WebContentsImpl::WasOccluded() {
1302 if (capturer_count_ > 0)
1303 return;
1304
1305 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1306 if (view)
1307 view->WasOccluded();
1308 }
1309}
1310
1311void WebContentsImpl::WasUnOccluded() {
1312 for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) {
1313 if (view)
1314 view->WasUnOccluded();
1315 }
1316}
1317
[email protected]b172aee2012-04-10 17:05:261318bool WebContentsImpl::NeedToFireBeforeUnload() {
[email protected]be1f56ab2011-12-22 06:55:311319 // TODO(creis): Should we fire even for interstitial pages?
creisc014b402015-04-23 16:41:451320 return WillNotifyDisconnection() && !ShowingInterstitialPage() &&
1321 !GetRenderViewHost()->SuddenTerminationAllowed();
[email protected]be1f56ab2011-12-22 06:55:311322}
1323
[email protected]1c3f80bd2014-04-08 23:02:061324void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) {
creisc014b402015-04-23 16:41:451325 GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition);
[email protected]1c3f80bd2014-04-08 23:02:061326}
1327
lazyboy6ec48b2a2015-06-29 15:18:141328void WebContentsImpl::AttachToOuterWebContentsFrame(
1329 WebContents* outer_web_contents,
1330 RenderFrameHost* outer_contents_frame) {
nickd30fd962015-07-27 21:51:081331 CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests());
lfg91a79e12016-04-01 23:52:191332 RenderFrameHostManager* render_manager = GetRenderManager();
1333
1334 // When the WebContents being initialized has an opener, the browser side
1335 // Render{View,Frame}Host must be initialized and the RenderWidgetHostView
1336 // created. This is needed because the usual initialization happens during
1337 // the first navigation, but when attaching a new window we don't navigate
1338 // before attaching. If the browser side is already initialized, the calls
1339 // below will just early return.
1340 render_manager->InitRenderView(GetRenderViewHost(), nullptr);
1341 GetMainFrame()->Init();
1342 if (!render_manager->GetRenderWidgetHostView())
1343 CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
1344
lazyboy6ec48b2a2015-06-29 15:18:141345 // Create a link to our outer WebContents.
1346 node_.reset(new WebContentsTreeNode());
1347 node_->ConnectToOuterWebContents(
1348 static_cast<WebContentsImpl*>(outer_web_contents),
1349 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1350
1351 DCHECK(outer_contents_frame);
1352
1353 // Create a proxy in top-level RenderFrameHostManager, pointing to the
1354 // SiteInstance of the outer WebContents. The proxy will be used to send
1355 // postMessage to the inner WebContents.
lfg91a79e12016-04-01 23:52:191356 render_manager->CreateOuterDelegateProxy(
lazyboy6ec48b2a2015-06-29 15:18:141357 outer_contents_frame->GetSiteInstance(),
1358 static_cast<RenderFrameHostImpl*>(outer_contents_frame));
1359
lfg91a79e12016-04-01 23:52:191360 render_manager->SetRWHViewForInnerContents(
1361 render_manager->GetRenderWidgetHostView());
wjmacleanfab616a2016-03-02 18:40:391362
1363 static_cast<RenderWidgetHostViewChildFrame*>(
lfg91a79e12016-04-01 23:52:191364 render_manager->GetRenderWidgetHostView())
wjmacleanfab616a2016-03-02 18:40:391365 ->RegisterSurfaceNamespaceId();
lazyboy6ec48b2a2015-06-29 15:18:141366}
1367
[email protected]b172aee2012-04-10 17:05:261368void WebContentsImpl::Stop() {
dcheng57e39e22016-01-21 00:25:381369 for (FrameTreeNode* node : frame_tree_.Nodes())
1370 node->StopLoading();
[email protected]d16609c2013-08-23 06:01:401371 FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped());
[email protected]0bfbf882011-12-22 18:19:271372}
1373
[email protected]b172aee2012-04-10 17:05:261374WebContents* WebContentsImpl::Clone() {
[email protected]14392a52012-05-02 20:28:441375 // We use our current SiteInstance since the cloned entry will use it anyway.
alexmose201c7cd2015-06-10 17:14:211376 // We pass our own opener so that the cloned page can access it if it was set
[email protected]ed245db2012-12-18 08:00:451377 // before.
[email protected]54944cde2012-12-09 09:24:591378 CreateParams create_params(GetBrowserContext(), GetSiteInstance());
[email protected]fc2b46b2014-05-03 16:33:451379 create_params.initial_size = GetContainerBounds().size();
alexmose201c7cd2015-06-10 17:14:211380 WebContentsImpl* tc =
1381 CreateWithOpener(create_params, frame_tree_.root()->opener());
[email protected]d1198fd2012-08-13 22:50:191382 tc->GetController().CopyStateFrom(controller_);
[email protected]7381d9f2012-09-12 20:26:221383 FOR_EACH_OBSERVER(WebContentsObserver,
1384 observers_,
1385 DidCloneToNewWebContents(this, tc));
[email protected]0bfbf882011-12-22 18:19:271386 return tc;
1387}
1388
[email protected]14392a52012-05-02 20:28:441389void WebContentsImpl::Observe(int type,
[email protected]8ff00d72012-10-23 19:12:211390 const NotificationSource& source,
1391 const NotificationDetails& details) {
[email protected]14392a52012-05-02 20:28:441392 switch (type) {
[email protected]8ff00d72012-10-23 19:12:211393 case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: {
1394 RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr();
[email protected]0b431992014-06-24 00:08:031395 RenderWidgetHostView* view = host->GetView();
1396 if (view == GetFullscreenRenderWidgetHostView()) {
1397 // We cannot just call view_->RestoreFocus() here. On some platforms,
1398 // attempting to focus the currently-invisible WebContentsView will be
1399 // flat-out ignored. Therefore, this boolean is used to track whether
1400 // we will request focus after the fullscreen widget has been
1401 // destroyed.
1402 fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus());
1403 } else {
1404 for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
1405 i != pending_widget_views_.end(); ++i) {
1406 if (host->GetView() == i->second) {
1407 pending_widget_views_.erase(i);
1408 break;
1409 }
[email protected]bafe6cd2012-05-23 23:09:501410 }
1411 }
1412 break;
1413 }
[email protected]14392a52012-05-02 20:28:441414 default:
1415 NOTREACHED();
1416 }
1417}
1418
[email protected]ec6c05f2013-10-23 18:41:571419WebContents* WebContentsImpl::GetWebContents() {
1420 return this;
1421}
1422
[email protected]54944cde2012-12-09 09:24:591423void WebContentsImpl::Init(const WebContents::CreateParams& params) {
[email protected]fa944cb82013-11-15 17:51:211424 // This is set before initializing the render manager since
[email protected]b0936d22013-11-28 06:47:361425 // RenderFrameHostManager::Init calls back into us via its delegate to ask if
[email protected]fa944cb82013-11-15 17:51:211426 // it should be hidden.
[email protected]d6fa88f2013-10-18 16:00:431427 should_normally_be_visible_ = !params.initially_hidden;
1428
dcheng3ce04b62015-10-26 23:30:551429 // The routing ids must either all be set or all be unset.
avic2c29d782014-12-12 00:23:541430 DCHECK((params.routing_id == MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551431 params.main_frame_routing_id == MSG_ROUTING_NONE &&
1432 params.main_frame_widget_routing_id == MSG_ROUTING_NONE) ||
avic2c29d782014-12-12 00:23:541433 (params.routing_id != MSG_ROUTING_NONE &&
dcheng3ce04b62015-10-26 23:30:551434 params.main_frame_routing_id != MSG_ROUTING_NONE &&
1435 params.main_frame_widget_routing_id != MSG_ROUTING_NONE));
1436
1437 scoped_refptr<SiteInstance> site_instance = params.site_instance;
1438 if (!site_instance)
1439 site_instance = SiteInstance::Create(params.browser_context);
1440
1441 // A main RenderFrameHost always has a RenderWidgetHost, since it is always a
1442 // local root by definition.
1443 // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no
1444 // longer be necessary to eagerly grab a routing ID for the view.
1445 // https://crbug.com/545684
1446 int32_t view_routing_id = params.routing_id;
1447 int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id;
1448 if (main_frame_widget_routing_id == MSG_ROUTING_NONE) {
1449 view_routing_id = main_frame_widget_routing_id =
1450 site_instance->GetProcess()->GetNextRoutingID();
1451 }
1452
1453 GetRenderManager()->Init(site_instance.get(), view_routing_id,
1454 params.main_frame_routing_id,
1455 main_frame_widget_routing_id);
lukasza464d8692016-02-22 19:26:321456
1457 // blink::FrameTree::setName uses |name| as the |unique_name| for the main
1458 // frame - let's do the same thing here.
1459 std::string unique_name = params.main_frame_name;
1460 frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name);
[email protected]d1198fd2012-08-13 22:50:191461
[email protected]fc2b46b2014-05-03 16:33:451462 WebContentsViewDelegate* delegate =
1463 GetContentClient()->browser()->GetWebContentsViewDelegate(this);
1464
fsamueladb0033602015-12-09 19:20:411465#if defined(MOJO_SHELL_CLIENT)
1466 if (MojoShellConnection::Get() &&
1467 base::CommandLine::ForCurrentProcess()->HasSwitch(
1468 switches::kUseMusInRenderer)) {
1469 mus::Window* mus_window = aura::GetMusWindow(params.context);
1470 if (mus_window) {
1471 view_.reset(new WebContentsViewMus(mus_window, this, delegate,
1472 &render_view_host_delegate_view_));
1473 }
1474 }
1475#endif
1476
1477 if (!view_) {
lfgc740d4b22016-04-15 16:45:331478 if (browser_plugin_guest_ &&
1479 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
1480 view_.reset(new WebContentsViewChildFrame(
1481 this, delegate, &render_view_host_delegate_view_));
1482 } else {
1483 view_.reset(CreateWebContentsView(this, delegate,
1484 &render_view_host_delegate_view_));
1485 }
fsamueladb0033602015-12-09 19:20:411486 }
fsamuel9cf7bdf2015-11-20 02:19:321487
lazyboy6ec48b2a2015-06-29 15:18:141488 if (browser_plugin_guest_ &&
nickd30fd962015-07-27 21:51:081489 !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
fsamuel9cf7bdf2015-11-20 02:19:321490 view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(),
dcheng36b6aec92015-12-26 06:16:361491 std::move(view_),
fsamuel9cf7bdf2015-11-20 02:19:321492 &render_view_host_delegate_view_));
[email protected]d1198fd2012-08-13 22:50:191493 }
[email protected]fc2b46b2014-05-03 16:33:451494 CHECK(render_view_host_delegate_view_);
[email protected]d1198fd2012-08-13 22:50:191495 CHECK(view_.get());
1496
[email protected]ed245db2012-12-18 08:00:451497 gfx::Size initial_size = params.initial_size;
[email protected]54944cde2012-12-09 09:24:591498 view_->CreateView(initial_size, params.context);
[email protected]d1198fd2012-08-13 22:50:191499
tommyclieb25b2a2014-11-03 19:45:091500#if defined(ENABLE_PLUGINS)
1501 plugin_content_origin_whitelist_.reset(
1502 new PluginContentOriginWhitelist(this));
1503#endif
1504
[email protected]d1198fd2012-08-13 22:50:191505 registrar_.Add(this,
[email protected]8ff00d72012-10-23 19:12:211506 NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
1507 NotificationService::AllBrowserContextsAndSources());
[email protected]f28ef9a32014-05-12 16:36:101508
[email protected]01f83f92014-06-17 14:41:541509 screen_orientation_dispatcher_host_.reset(
jonross74971522014-09-15 14:16:091510 new ScreenOrientationDispatcherHostImpl(this));
[email protected]01f83f92014-06-17 14:41:541511
mlamouriefdca9d2014-09-16 16:55:401512 manifest_manager_host_.reset(new ManifestManagerHost(this));
1513
mfomitchev2b8b066a2016-01-28 19:23:151514#if defined(OS_ANDROID)
[email protected]583418cc2013-01-17 14:01:101515 date_time_chooser_.reset(new DateTimeChooserAndroid());
1516#endif
fsamuel7310a4262014-12-05 05:06:441517
1518 // BrowserPluginGuest::Init needs to be called after this WebContents has
1519 // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above.
1520 if (browser_plugin_guest_)
1521 browser_plugin_guest_->Init();
nickf9acfbe2014-12-23 19:12:371522
1523 for (size_t i = 0; i < g_created_callbacks.Get().size(); i++)
1524 g_created_callbacks.Get().at(i).Run(this);
naskob21fe4872015-02-24 14:15:561525
1526 // If the WebContents creation was renderer-initiated, it means that the
1527 // corresponding RenderView and main RenderFrame have already been created.
1528 // Ensure observers are notified about this.
1529 if (params.renderer_initiated_creation) {
avi3627ecac2015-10-16 17:40:431530 GetRenderViewHost()->GetWidget()->set_renderer_initialized(true);
naskob21fe4872015-02-24 14:15:561531 RenderViewCreated(GetRenderViewHost());
1532 GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true);
1533 }
naskof5940b9f2015-03-02 23:04:051534
1535 // Ensure that observers are notified of the creation of this WebContents's
1536 // main RenderFrameHost. It must be done here for main frames, since the
1537 // NotifySwappedFromRenderManager expects view_ to already be created and that
1538 // happens after RenderFrameHostManager::Init.
1539 NotifySwappedFromRenderManager(
1540 nullptr, GetRenderManager()->current_frame_host(), true);
[email protected]d1198fd2012-08-13 22:50:191541}
1542
[email protected]7fff43e2013-05-21 20:21:101543void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) {
1544 RemoveDestructionObserver(web_contents);
1545
[email protected]ceee8cd2013-03-08 04:59:511546 // Clear a pending contents that has been closed before being shown.
1547 for (PendingContents::iterator iter = pending_contents_.begin();
1548 iter != pending_contents_.end();
1549 ++iter) {
1550 if (iter->second != web_contents)
1551 continue;
1552 pending_contents_.erase(iter);
[email protected]ceee8cd2013-03-08 04:59:511553 return;
1554 }
1555 NOTREACHED();
[email protected]14392a52012-05-02 20:28:441556}
1557
[email protected]7fff43e2013-05-21 20:21:101558void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) {
1559 if (!ContainsKey(destruction_observers_, web_contents)) {
1560 destruction_observers_[web_contents] =
1561 new DestructionObserver(this, web_contents);
1562 }
1563}
1564
1565void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) {
1566 DestructionObservers::iterator iter =
1567 destruction_observers_.find(web_contents);
1568 if (iter != destruction_observers_.end()) {
1569 delete destruction_observers_[web_contents];
1570 destruction_observers_.erase(iter);
1571 }
1572}
1573
[email protected]b172aee2012-04-10 17:05:261574void WebContentsImpl::AddObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311575 observers_.AddObserver(observer);
1576}
1577
[email protected]b172aee2012-04-10 17:05:261578void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) {
[email protected]be1f56ab2011-12-22 06:55:311579 observers_.RemoveObserver(observer);
1580}
1581
[email protected]948481d2014-06-11 18:32:221582std::set<RenderWidgetHostView*>
1583WebContentsImpl::GetRenderWidgetHostViewsInTree() {
1584 std::set<RenderWidgetHostView*> set;
1585 if (ShowingInterstitialPage()) {
1586 set.insert(GetRenderWidgetHostView());
1587 } else {
dchengafb53e22016-02-04 08:11:081588 for (RenderFrameHost* rfh : GetAllFrames()) {
1589 RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh)
1590 ->frame_tree_node()
1591 ->render_manager()
1592 ->GetRenderWidgetHostView();
1593 set.insert(rwhv);
1594 }
[email protected]948481d2014-06-11 18:32:221595 }
[email protected]de3c5d82014-05-28 22:12:591596 return set;
1597}
1598
[email protected]b172aee2012-04-10 17:05:261599void WebContentsImpl::Activate() {
[email protected]d5f942ba2008-09-26 19:30:341600 if (delegate_)
1601 delegate_->ActivateContents(this);
1602}
1603
avi3e4b8512015-11-11 01:55:491604void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) {
1605 if (!RenderViewHostImpl::From(render_widget_host))
1606 return;
1607
[email protected]63954792011-07-11 04:17:481608 if (delegate_)
1609 delegate_->LostCapture();
1610}
1611
lazyboy63f5b312015-11-23 20:19:521612void WebContentsImpl::RenderWidgetCreated(
1613 RenderWidgetHostImpl* render_widget_host) {
1614 created_widgets_.insert(render_widget_host);
1615}
1616
[email protected]b24b68a2012-09-24 21:57:261617void WebContentsImpl::RenderWidgetDeleted(
1618 RenderWidgetHostImpl* render_widget_host) {
lazyboy63f5b312015-11-23 20:19:521619 // Note that |is_being_destroyed_| can be true at this point as
1620 // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead
1621 // us here.
1622 created_widgets_.erase(render_widget_host);
[email protected]b24b68a2012-09-24 21:57:261623
lazyboy63f5b312015-11-23 20:19:521624 if (is_being_destroyed_)
1625 return;
[email protected]44470a22013-01-24 01:21:541626
1627 if (render_widget_host &&
1628 render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) {
[email protected]4aebbca2013-09-17 22:26:491629 if (delegate_ && delegate_->EmbedsFullscreenWidget())
mlamouri7a78d6fd2015-01-17 13:23:531630 delegate_->ExitFullscreenModeForTab(this);
[email protected]44470a22013-01-24 01:21:541631 FOR_EACH_OBSERVER(WebContentsObserver,
1632 observers_,
1633 DidDestroyFullscreenWidget(
1634 fullscreen_widget_routing_id_));
1635 fullscreen_widget_routing_id_ = MSG_ROUTING_NONE;
[email protected]0b431992014-06-24 00:08:031636 if (fullscreen_widget_had_focus_at_shutdown_)
1637 view_->RestoreFocus();
[email protected]44470a22013-01-24 01:21:541638 }
[email protected]b24b68a2012-09-24 21:57:261639}
1640
miu9e14e492014-10-25 02:39:041641void WebContentsImpl::RenderWidgetGotFocus(
1642 RenderWidgetHostImpl* render_widget_host) {
calamity7fe55ce2015-04-10 03:59:371643 // Notify the observers if an embedded fullscreen widget was focused.
1644 if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() &&
1645 render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) {
1646 NotifyWebContentsFocused();
1647 }
miu9e14e492014-10-25 02:39:041648}
1649
estaded0a0c992015-01-21 14:12:061650void WebContentsImpl::RenderWidgetWasResized(
rouslan2f5993f2015-01-29 00:18:311651 RenderWidgetHostImpl* render_widget_host,
1652 bool width_changed) {
creisc014b402015-04-23 16:41:451653 RenderFrameHostImpl* rfh = GetMainFrame();
estadece344ec2015-01-23 00:12:291654 if (!rfh || render_widget_host != rfh->GetRenderWidgetHost())
estaded0a0c992015-01-21 14:12:061655 return;
estaded0a0c992015-01-21 14:12:061656
rouslan2f5993f2015-01-29 00:18:311657 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
1658 MainFrameWasResized(width_changed));
estaded0a0c992015-01-21 14:12:061659}
1660
paulmeyer9ef6e4462015-02-24 19:15:101661void WebContentsImpl::ScreenInfoChanged() {
1662 if (browser_plugin_embedder_)
1663 browser_plugin_embedder_->ScreenInfoChanged();
1664}
1665
[email protected]b172aee2012-04-10 17:05:261666bool WebContentsImpl::PreHandleKeyboardEvent(
1667 const NativeWebKeyboardEvent& event,
1668 bool* is_keyboard_shortcut) {
[email protected]63954792011-07-11 04:17:481669 return delegate_ &&
[email protected]b3996ba2012-08-08 00:39:131670 delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut);
[email protected]63954792011-07-11 04:17:481671}
1672
[email protected]b172aee2012-04-10 17:05:261673void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
[email protected]0b094002014-08-20 18:28:101674 if (browser_plugin_embedder_ &&
1675 browser_plugin_embedder_->HandleKeyboardEvent(event)) {
1676 return;
1677 }
[email protected]63954792011-07-11 04:17:481678 if (delegate_)
[email protected]b3996ba2012-08-08 00:39:131679 delegate_->HandleKeyboardEvent(this, event);
[email protected]63954792011-07-11 04:17:481680}
1681
[email protected]d92026ef2014-03-03 21:04:131682bool WebContentsImpl::HandleWheelEvent(
[email protected]180ef242013-11-07 06:50:461683 const blink::WebMouseWheelEvent& event) {
[email protected]bccc4472013-04-18 16:37:191684#if !defined(OS_MACOSX)
lanweia93644f2015-01-21 22:00:331685 // On platforms other than Mac, control+mousewheel may change zoom. On Mac,
1686 // this isn't done for two reasons:
[email protected]bccc4472013-04-18 16:37:191687 // -the OS already has a gesture to do this through pinch-zoom
1688 // -if a user starts an inertial scroll, let's go, and presses control
1689 // (i.e. control+tab) then the OS's buffered scroll events will come in
1690 // with control key set which isn't what the user wants
lanweia93644f2015-01-21 22:00:331691 if (delegate_ && event.wheelTicksY &&
[email protected]5a24f5802014-04-22 22:39:551692 (event.modifiers & blink::WebInputEvent::ControlKey) &&
lanweia93644f2015-01-21 22:00:331693 !event.canScroll) {
w.shackleton49bcd392016-01-06 17:38:221694 // Count only integer cumulative scrolls as zoom events; this handles
1695 // smooth scroll and regular scroll device behavior.
1696 zoom_scroll_remainder_ += event.wheelTicksY;
1697 int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_);
1698 zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_;
1699 if (whole_zoom_scroll_remainder_ != 0) {
1700 delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0);
1701 }
[email protected]fb3f066e2013-02-12 19:12:521702 return true;
1703 }
[email protected]bccc4472013-04-18 16:37:191704#endif
[email protected]fb3f066e2013-02-12 19:12:521705 return false;
1706}
1707
[email protected]04bce562014-01-30 05:34:541708bool WebContentsImpl::PreHandleGestureEvent(
1709 const blink::WebGestureEvent& event) {
[email protected]28042d32014-02-03 14:10:031710 return delegate_ && delegate_->PreHandleGestureEvent(this, event);
[email protected]04bce562014-01-30 05:34:541711}
1712
kenrb2a565f82015-09-02 20:24:591713RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() {
wjmacleane31234f2015-12-14 17:20:451714 if (!is_being_destroyed_ && GetOuterWebContents())
1715 return GetOuterWebContents()->GetInputEventRouter();
1716
1717 if (!rwh_input_event_router_.get() && !is_being_destroyed_)
kenrb2a565f82015-09-02 20:24:591718 rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter);
1719 return rwh_input_event_router_.get();
1720}
1721
alexmos3fcd0ca2015-10-23 18:18:331722void WebContentsImpl::ReplicatePageFocus(bool is_focused) {
1723 // Focus loss may occur while this WebContents is being destroyed. Don't
1724 // send the message in this case, as the main frame's RenderFrameHost and
1725 // other state has already been cleared.
1726 if (is_being_destroyed_)
1727 return;
1728
1729 frame_tree_.ReplicatePageFocus(is_focused);
1730}
1731
alexmosc4cbacb2015-11-21 01:29:221732RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost(
1733 RenderWidgetHostImpl* receiving_widget) {
alexmosc4d183e2015-11-06 00:46:521734 if (!SiteIsolationPolicy::AreCrossProcessFramesPossible())
alexmosc4cbacb2015-11-21 01:29:221735 return receiving_widget;
1736
1737 // Events for widgets other than the main frame (e.g., popup menus) should be
1738 // forwarded directly to the widget they arrived on.
1739 if (receiving_widget != GetMainFrame()->GetRenderWidgetHost())
1740 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521741
1742 FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame();
1743 if (!focused_frame)
alexmosc4cbacb2015-11-21 01:29:221744 return receiving_widget;
alexmosc4d183e2015-11-06 00:46:521745
alexmos732ca3a2015-12-08 02:01:021746 // The view may be null if a subframe's renderer process has crashed while
1747 // the subframe has focus. Drop the event in that case. Do not give
1748 // it to the main frame, so that the user doesn't unexpectedly type into the
1749 // wrong frame if a focused subframe renderer crashes while they type.
1750 RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView();
1751 if (!view)
1752 return nullptr;
1753
1754 return RenderWidgetHostImpl::From(view->GetRenderWidgetHost());
alexmosc4d183e2015-11-06 00:46:521755}
1756
mlamouri7a78d6fd2015-01-17 13:23:531757void WebContentsImpl::EnterFullscreenMode(const GURL& origin) {
1758 // This method is being called to enter renderer-initiated fullscreen mode.
1759 // Make sure any existing fullscreen widget is shut down first.
[email protected]4aebbca2013-09-17 22:26:491760 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371761 if (widget_view) {
1762 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1763 ->ShutdownAndDestroyWidget(true);
1764 }
[email protected]4aebbca2013-09-17 22:26:491765
[email protected]8a5e0ca2011-08-25 06:30:471766 if (delegate_)
mlamouri7a78d6fd2015-01-17 13:23:531767 delegate_->EnterFullscreenModeForTab(this, origin);
1768
1769 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461770 DidToggleFullscreenModeForTab(
1771 IsFullscreenForCurrentTab(
1772 GetRenderViewHost()->GetWidget()),
1773 false));
mlamouri7a78d6fd2015-01-17 13:23:531774}
1775
bokanece34a82016-01-28 19:49:461776void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:531777 // This method is being called to leave renderer-initiated fullscreen mode.
1778 // Make sure any existing fullscreen widget is shut down first.
1779 RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView();
avi85a4cef2015-12-18 20:13:371780 if (widget_view) {
1781 RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost())
1782 ->ShutdownAndDestroyWidget(true);
1783 }
mlamouri7a78d6fd2015-01-17 13:23:531784
hugo.holgersson61288e6c2015-01-28 17:04:401785#if defined(OS_ANDROID)
1786 ContentVideoView* video_view = ContentVideoView::GetInstance();
1787 if (video_view != NULL)
watk98292292016-01-19 22:24:081788 video_view->ExitFullscreen();
hugo.holgersson61288e6c2015-01-28 17:04:401789#endif
1790
mlamouri7a78d6fd2015-01-17 13:23:531791 if (delegate_)
1792 delegate_->ExitFullscreenModeForTab(this);
[email protected]657c8e02014-03-19 19:18:371793
bokanece34a82016-01-28 19:49:461794 // The fullscreen state is communicated to the renderer through a resize
1795 // message. If the change in fullscreen state doesn't cause a view resize
1796 // then we must ensure web contents exit the fullscreen state by explicitly
1797 // sending a resize message. This is required for the situation of the browser
1798 // moving the view into a "browser fullscreen" state and then the contents
1799 // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't
1800 // have the side effect of the view resizing, hence the explicit call here is
1801 // required.
1802 if (!will_cause_resize) {
1803 if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) {
1804 if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost())
1805 render_widget_host->WasResized();
1806 }
scheib3dcb6c932015-02-23 10:55:581807 }
1808
avibf58fa0c2015-11-11 01:45:521809 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
bokanece34a82016-01-28 19:49:461810 DidToggleFullscreenModeForTab(
1811 IsFullscreenForCurrentTab(
1812 GetRenderViewHost()->GetWidget()),
1813 will_cause_resize));
[email protected]8a5e0ca2011-08-25 06:30:471814}
1815
avibf58fa0c2015-11-11 01:45:521816bool WebContentsImpl::IsFullscreenForCurrentTab(
1817 RenderWidgetHostImpl* render_widget_host) const {
1818 if (!RenderViewHostImpl::From(render_widget_host))
1819 return false;
1820
[email protected]199bba6e2012-04-04 16:19:381821 return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false;
[email protected]5d5f7af2011-10-01 01:38:121822}
1823
avibf58fa0c2015-11-11 01:45:521824blink::WebDisplayMode WebContentsImpl::GetDisplayMode(
1825 RenderWidgetHostImpl* render_widget_host) const {
1826 if (!RenderViewHostImpl::From(render_widget_host))
1827 return blink::WebDisplayModeBrowser;
1828
mikhail.pozdnyakovc0e251b2015-04-15 06:51:121829 return delegate_ ? delegate_->GetDisplayMode(this)
1830 : blink::WebDisplayModeBrowser;
1831}
1832
avic3aa8422015-11-09 20:57:221833void WebContentsImpl::RequestToLockMouse(
1834 RenderWidgetHostImpl* render_widget_host,
1835 bool user_gesture,
1836 bool last_unlocked_by_target) {
1837 if (render_widget_host != GetRenderViewHost()->GetWidget()) {
1838 render_widget_host->GotResponseToLockMouseRequest(false);
1839 return;
[email protected]e9621112011-10-17 05:38:371840 }
avic3aa8422015-11-09 20:57:221841
1842 if (delegate_)
1843 delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target);
1844 else
1845 GotResponseToLockMouseRequest(false);
[email protected]e9621112011-10-17 05:38:371846}
1847
avi3e4b8512015-11-11 01:55:491848void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) {
1849 if (!RenderViewHostImpl::From(render_widget_host))
1850 return;
1851
[email protected]e9621112011-10-17 05:38:371852 if (delegate_)
1853 delegate_->LostMouseLock();
1854}
1855
dtrainor5ef644e2015-11-19 00:12:471856void WebContentsImpl::ForwardCompositorProto(
1857 RenderWidgetHostImpl* render_widget_host,
1858 const std::vector<uint8_t>& proto) {
dtrainor5ef644e2015-11-19 00:12:471859 if (delegate_)
khushalsagar6b649b902016-02-23 00:23:291860 delegate_->ForwardCompositorProto(render_widget_host, proto);
dtrainor5ef644e2015-11-19 00:12:471861}
1862
ekaramada4f42692016-02-11 19:48:371863void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) {
1864 if (visible)
1865 WasShown();
1866 else
1867 WasHidden();
1868}
1869
[email protected]bafe6cd2012-05-23 23:09:501870void WebContentsImpl::CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:431871 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:551872 int32_t route_id,
1873 int32_t main_frame_route_id,
1874 int32_t main_frame_widget_route_id,
[email protected]97714c82012-06-06 10:15:131875 const ViewHostMsg_CreateWindow_Params& params,
1876 SessionStorageNamespace* session_storage_namespace) {
[email protected]bafe6cd2012-05-23 23:09:501877 // We usually create the new window in the same BrowsingInstance (group of
1878 // script-related windows), by passing in the current SiteInstance. However,
[email protected]c4538072013-03-18 02:17:551879 // if the opener is being suppressed (in a non-guest), we create a new
1880 // SiteInstance in its own BrowsingInstance.
[email protected]a24efc22014-05-26 15:50:251881 bool is_guest = BrowserPluginGuest::IsGuest(this);
[email protected]c4538072013-03-18 02:17:551882
[email protected]04cbd3d2013-12-04 04:58:201883 // If the opener is to be suppressed, the new window can be in any process.
1884 // Since routing ids are process specific, we must not have one passed in
1885 // as argument here.
1886 DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE);
1887
[email protected]bafe6cd2012-05-23 23:09:501888 scoped_refptr<SiteInstance> site_instance =
alexmos4cf2aa32015-07-15 23:40:431889 params.opener_suppressed && !is_guest
1890 ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url)
1891 : source_site_instance;
[email protected]bafe6cd2012-05-23 23:09:501892
alexmos4cf2aa32015-07-15 23:40:431893 // A message to create a new window can only come from a process for a frame
1894 // in this WebContents' FrameTree. If any other process sends the request, it
1895 // is invalid and the process must be terminated.
1896 int render_process_id = source_site_instance->GetProcess()->GetID();
dcheng57e39e22016-01-21 00:25:381897 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
alexmos4cf2aa32015-07-15 23:40:431898 RenderProcessHost* rph = source_site_instance->GetProcess();
jaekyun37e572a32014-12-04 23:33:351899 base::ProcessHandle process_handle = rph->GetHandle();
[email protected]04cbd3d2013-12-04 04:58:201900 if (process_handle != base::kNullProcessHandle) {
1901 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:391902 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow"));
jaekyun37e572a32014-12-04 23:33:351903 rph->Shutdown(RESULT_CODE_KILLED, false);
[email protected]04cbd3d2013-12-04 04:58:201904 }
1905 return;
1906 }
1907
[email protected]d1198fd2012-08-13 22:50:191908 // We must assign the SessionStorageNamespace before calling Init().
[email protected]4c3a23582012-08-18 08:54:341909 //
1910 // http://crbug.com/142685
[email protected]fdac6ade2013-07-20 01:06:301911 const std::string& partition_id =
1912 GetContentClient()->browser()->
1913 GetStoragePartitionIdForSite(GetBrowserContext(),
1914 site_instance->GetSiteURL());
[email protected]fc72bb12013-06-02 21:13:461915 StoragePartition* partition = BrowserContext::GetStoragePartition(
1916 GetBrowserContext(), site_instance.get());
[email protected]5f2aa722013-08-07 16:59:411917 DOMStorageContextWrapper* dom_storage_context =
1918 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
[email protected]d1198fd2012-08-13 22:50:191919 SessionStorageNamespaceImpl* session_storage_namespace_impl =
1920 static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace);
1921 CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context));
[email protected]dd6730412013-08-14 15:03:371922
1923 if (delegate_ &&
dcheng3ce04b62015-10-26 23:30:551924 !delegate_->ShouldCreateWebContents(
1925 this, route_id, main_frame_route_id, main_frame_widget_route_id,
1926 params.window_container_type, params.frame_name, params.target_url,
1927 partition_id, session_storage_namespace)) {
[email protected]f1cd3362014-01-07 20:43:011928 if (route_id != MSG_ROUTING_NONE &&
1929 !RenderViewHost::FromID(render_process_id, route_id)) {
1930 // If the embedder didn't create a WebContents for this route, we need to
1931 // delete the RenderView that had already been created.
1932 Send(new ViewMsg_Close(route_id));
1933 }
csharrisona2280cd2016-02-03 23:21:151934 // It's safe to only target the frame because the render process will not
1935 // have a chance to create more frames at this point.
1936 ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
1937 GlobalFrameRoutingId(render_process_id, main_frame_route_id));
[email protected]dd6730412013-08-14 15:03:371938 return;
1939 }
1940
1941 // Create the new web contents. This will automatically create the new
1942 // WebContentsView. In the future, we may want to create the view separately.
[email protected]fc72bb12013-06-02 21:13:461943 CreateParams create_params(GetBrowserContext(), site_instance.get());
[email protected]54944cde2012-12-09 09:24:591944 create_params.routing_id = route_id;
[email protected]227692c52013-05-31 22:43:041945 create_params.main_frame_routing_id = main_frame_route_id;
dcheng3ce04b62015-10-26 23:30:551946 create_params.main_frame_widget_routing_id = main_frame_widget_route_id;
nasko48321ca32015-07-02 20:44:121947 create_params.main_frame_name = params.frame_name;
alexmos4cf2aa32015-07-15 23:40:431948 create_params.opener_render_process_id = render_process_id;
alexmose201c7cd2015-06-10 17:14:211949 create_params.opener_render_frame_id = params.opener_render_frame_id;
[email protected]50d326e2014-05-20 17:59:061950 create_params.opener_suppressed = params.opener_suppressed;
1951 if (params.disposition == NEW_BACKGROUND_TAB)
1952 create_params.initially_hidden = true;
lfg269b702f2015-06-08 19:28:191953 create_params.renderer_initiated_creation =
1954 main_frame_route_id != MSG_ROUTING_NONE;
[email protected]50d326e2014-05-20 17:59:061955
[email protected]4858e432014-06-23 18:14:171956 WebContentsImpl* new_contents = NULL;
[email protected]c4538072013-03-18 02:17:551957 if (!is_guest) {
1958 create_params.context = view_->GetNativeView();
[email protected]fc2b46b2014-05-03 16:33:451959 create_params.initial_size = GetContainerBounds().size();
[email protected]4858e432014-06-23 18:14:171960 new_contents = static_cast<WebContentsImpl*>(
1961 WebContents::Create(create_params));
1962 } else {
1963 new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params);
[email protected]c4538072013-03-18 02:17:551964 }
[email protected]50d326e2014-05-20 17:59:061965 new_contents->GetController().SetSessionStorageNamespace(
1966 partition_id,
1967 session_storage_namespace);
[email protected]d1198fd2012-08-13 22:50:191968
alexmos646fec02015-07-25 00:11:491969 // If the new frame has a name, make sure any SiteInstances that can find
1970 // this named frame have proxies for it. Must be called after
1971 // SetSessionStorageNamespace, since this calls CreateRenderView, which uses
1972 // GetSessionStorageNamespace.
1973 if (!params.frame_name.empty())
1974 new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame();
1975
[email protected]c4538072013-03-18 02:17:551976 // Save the window for later if we're not suppressing the opener (since it
[email protected]d70bea92013-04-05 04:23:341977 // will be shown immediately).
1978 if (!params.opener_suppressed) {
1979 if (!is_guest) {
[email protected]fc2b46b2014-05-03 16:33:451980 WebContentsView* new_view = new_contents->view_.get();
[email protected]bafe6cd2012-05-23 23:09:501981
[email protected]d70bea92013-04-05 04:23:341982 // TODO(brettw): It seems bogus that we have to call this function on the
1983 // newly created object and give it one of its own member variables.
avi3627ecac2015-10-16 17:40:431984 new_view->CreateViewForWidget(
1985 new_contents->GetRenderViewHost()->GetWidget(), false);
[email protected]d70bea92013-04-05 04:23:341986 }
[email protected]bafe6cd2012-05-23 23:09:501987 // Save the created window associated with the route so we can show it
1988 // later.
1989 DCHECK_NE(MSG_ROUTING_NONE, route_id);
1990 pending_contents_[route_id] = new_contents;
[email protected]7fff43e2013-05-21 20:21:101991 AddDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:501992 }
1993
1994 if (delegate_) {
1995 delegate_->WebContentsCreated(
[email protected]a7531d772014-03-25 16:15:071996 this, params.opener_render_frame_id, params.frame_name,
[email protected]50de3222013-03-20 15:36:131997 params.target_url, new_contents);
[email protected]bafe6cd2012-05-23 23:09:501998 }
1999
2000 if (params.opener_suppressed) {
2001 // When the opener is suppressed, the original renderer cannot access the
2002 // new window. As a result, we need to show and navigate the window here.
[email protected]eda238a12012-09-07 23:44:002003 bool was_blocked = false;
2004 if (delegate_) {
bokan107a47f2015-02-03 23:23:392005 gfx::Rect initial_rect;
[email protected]eda238a12012-09-07 23:44:002006 delegate_->AddNewContents(
bokan107a47f2015-02-03 23:23:392007 this, new_contents, params.disposition, initial_rect,
[email protected]eda238a12012-09-07 23:44:002008 params.user_gesture, &was_blocked);
2009 }
2010 if (!was_blocked) {
[email protected]8ff00d72012-10-23 19:12:212011 OpenURLParams open_params(params.target_url,
2012 Referrer(),
2013 CURRENT_TAB,
Sylvain Defresnec6ccc77d2014-09-19 10:19:352014 ui::PAGE_TRANSITION_LINK,
[email protected]8ff00d72012-10-23 19:12:212015 true /* is_renderer_initiated */);
[email protected]e7f2e7c2013-07-15 09:41:302016 open_params.user_gesture = params.user_gesture;
mariakhomenkoa4971c12015-07-21 19:04:372017
2018 if (delegate_ && !is_guest &&
2019 !delegate_->ShouldResumeRequestsForCreatedWindow()) {
2020 // We are in asynchronous add new contents path, delay opening url
2021 new_contents->delayed_open_url_params_.reset(
2022 new OpenURLParams(open_params));
2023 } else {
2024 new_contents->OpenURL(open_params);
2025 }
[email protected]eda238a12012-09-07 23:44:002026 }
[email protected]bafe6cd2012-05-23 23:09:502027 }
2028}
2029
avib7348942015-12-25 20:57:102030void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2031 int32_t route_id,
[email protected]180ef242013-11-07 06:50:462032 blink::WebPopupType popup_type) {
piman5d36dae2015-09-24 22:47:052033 CreateNewWidget(render_process_id, route_id, false, popup_type);
[email protected]bafe6cd2012-05-23 23:09:502034}
2035
avib7348942015-12-25 20:57:102036void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id,
2037 int32_t route_id) {
piman5d36dae2015-09-24 22:47:052038 CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone);
[email protected]bafe6cd2012-05-23 23:09:502039}
2040
avib7348942015-12-25 20:57:102041void WebContentsImpl::CreateNewWidget(int32_t render_process_id,
2042 int32_t route_id,
[email protected]bafe6cd2012-05-23 23:09:502043 bool is_fullscreen,
[email protected]180ef242013-11-07 06:50:462044 blink::WebPopupType popup_type) {
kenrba26d15092016-02-10 22:00:252045 RenderProcessHost* process = RenderProcessHost::FromID(render_process_id);
kenrbb46f86a2015-12-07 07:53:232046 // A message to create a new widget can only come from an active process for
[email protected]a8504022013-12-04 20:23:512047 // this WebContentsImpl instance. If any other process sends the request,
2048 // it is invalid and the process must be terminated.
dcheng57e39e22016-01-21 00:25:382049 if (!HasMatchingProcess(&frame_tree_, render_process_id)) {
kenrba26d15092016-02-10 22:00:252050 base::ProcessHandle process_handle = process->GetHandle();
[email protected]a8504022013-12-04 20:23:512051 if (process_handle != base::kNullProcessHandle) {
2052 RecordAction(
[email protected]e6e30ac2014-01-13 21:24:392053 base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget"));
kenrba26d15092016-02-10 22:00:252054 process->Shutdown(RESULT_CODE_KILLED, false);
[email protected]a8504022013-12-04 20:23:512055 }
2056 return;
2057 }
2058
[email protected]bafe6cd2012-05-23 23:09:502059 RenderWidgetHostImpl* widget_host =
piman5d36dae2015-09-24 22:47:052060 new RenderWidgetHostImpl(this, process, route_id, IsHidden());
[email protected]b24b68a2012-09-24 21:57:262061
[email protected]cfd80b02014-05-01 17:46:482062 RenderWidgetHostViewBase* widget_view =
2063 static_cast<RenderWidgetHostViewBase*>(
2064 view_->CreateViewForPopupWidget(widget_host));
[email protected]83918ec2013-01-10 15:37:192065 if (!widget_view)
2066 return;
[email protected]bafe6cd2012-05-23 23:09:502067 if (!is_fullscreen) {
2068 // Popups should not get activated.
2069 widget_view->SetPopupType(popup_type);
2070 }
2071 // Save the created widget associated with the route so we can show it later.
2072 pending_widget_views_[route_id] = widget_view;
2073
2074#if defined(OS_MACOSX)
2075 // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
2076 // to allow it to survive the trip without being hosted.
2077 base::mac::NSObjectRetain(widget_view->GetNativeView());
2078#endif
2079}
2080
2081void WebContentsImpl::ShowCreatedWindow(int route_id,
2082 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:392083 const gfx::Rect& initial_rect,
[email protected]bafe6cd2012-05-23 23:09:502084 bool user_gesture) {
2085 WebContentsImpl* contents = GetCreatedWindow(route_id);
[email protected]eda238a12012-09-07 23:44:002086 if (contents) {
2087 WebContentsDelegate* delegate = GetDelegate();
dfalcantarae6b7b46752015-07-10 18:14:162088 contents->is_resume_pending_ = true;
mariakhomenko44bdc4732015-04-29 01:55:382089 if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
2090 contents->ResumeLoadingCreatedWebContents();
2091
[email protected]eda238a12012-09-07 23:44:002092 if (delegate) {
2093 delegate->AddNewContents(
bokan107a47f2015-02-03 23:23:392094 this, contents, disposition, initial_rect, user_gesture, NULL);
[email protected]eda238a12012-09-07 23:44:002095 }
2096 }
[email protected]bafe6cd2012-05-23 23:09:502097}
2098
2099void WebContentsImpl::ShowCreatedWidget(int route_id,
bokan107a47f2015-02-03 23:23:392100 const gfx::Rect& initial_rect) {
2101 ShowCreatedWidget(route_id, false, initial_rect);
[email protected]bafe6cd2012-05-23 23:09:502102}
2103
2104void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) {
2105 ShowCreatedWidget(route_id, true, gfx::Rect());
2106}
2107
2108void WebContentsImpl::ShowCreatedWidget(int route_id,
2109 bool is_fullscreen,
bokan107a47f2015-02-03 23:23:392110 const gfx::Rect& initial_rect) {
[email protected]cfd80b02014-05-01 17:46:482111 RenderWidgetHostViewBase* widget_host_view =
2112 static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id));
[email protected]bafe6cd2012-05-23 23:09:502113 if (!widget_host_view)
2114 return;
[email protected]cfd80b02014-05-01 17:46:482115
2116 RenderWidgetHostView* view = NULL;
lfgc740d4b22016-04-15 16:45:332117 if (GetOuterWebContents()) {
2118 view = GetOuterWebContents()->GetRenderWidgetHostView();
[email protected]cfd80b02014-05-01 17:46:482119 } else {
2120 view = GetRenderWidgetHostView();
2121 }
2122
[email protected]4aebbca2013-09-17 22:26:492123 if (is_fullscreen) {
[email protected]d7f80ba2013-10-12 07:42:312124 DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_);
[email protected]0b431992014-06-24 00:08:032125 view_->StoreFocus();
[email protected]d7f80ba2013-10-12 07:42:312126 fullscreen_widget_routing_id_ = route_id;
[email protected]4aebbca2013-09-17 22:26:492127 if (delegate_ && delegate_->EmbedsFullscreenWidget()) {
2128 widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView());
mlamouri7a78d6fd2015-01-17 13:23:532129 delegate_->EnterFullscreenModeForTab(this, GURL());
[email protected]4aebbca2013-09-17 22:26:492130 } else {
[email protected]cfd80b02014-05-01 17:46:482131 widget_host_view->InitAsFullscreen(view);
[email protected]4aebbca2013-09-17 22:26:492132 }
[email protected]4aebbca2013-09-17 22:26:492133 FOR_EACH_OBSERVER(WebContentsObserver,
2134 observers_,
2135 DidShowFullscreenWidget(route_id));
2136 if (!widget_host_view->HasFocus())
2137 widget_host_view->Focus();
2138 } else {
bokan107a47f2015-02-03 23:23:392139 widget_host_view->InitAsPopup(view, initial_rect);
[email protected]4aebbca2013-09-17 22:26:492140 }
[email protected]89054502012-06-03 10:29:242141
2142 RenderWidgetHostImpl* render_widget_host_impl =
2143 RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost());
2144 render_widget_host_impl->Init();
[email protected]d7f80ba2013-10-12 07:42:312145 // Only allow privileged mouse lock for fullscreen render widget, which is
2146 // used to implement Pepper Flash fullscreen.
2147 render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen);
[email protected]bafe6cd2012-05-23 23:09:502148
2149#if defined(OS_MACOSX)
2150 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
2151 // properly embedded (or purposefully ignored) we can release the retain we
2152 // took in CreateNewWidget().
2153 base::mac::NSObjectRelease(widget_host_view->GetNativeView());
2154#endif
2155}
2156
2157WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
2158 PendingContents::iterator iter = pending_contents_.find(route_id);
2159
2160 // Certain systems can block the creation of new windows. If we didn't succeed
2161 // in creating one, just return NULL.
2162 if (iter == pending_contents_.end()) {
2163 return NULL;
2164 }
2165
2166 WebContentsImpl* new_contents = iter->second;
2167 pending_contents_.erase(route_id);
[email protected]7fff43e2013-05-21 20:21:102168 RemoveDestructionObserver(new_contents);
[email protected]bafe6cd2012-05-23 23:09:502169
[email protected]d70bea92013-04-05 04:23:342170 // Don't initialize the guest WebContents immediately.
[email protected]a24efc22014-05-26 15:50:252171 if (BrowserPluginGuest::IsGuest(new_contents))
[email protected]d70bea92013-04-05 04:23:342172 return new_contents;
2173
[email protected]bafe6cd2012-05-23 23:09:502174 if (!new_contents->GetRenderProcessHost()->HasConnection() ||
avi3627ecac2015-10-16 17:40:432175 !new_contents->GetRenderViewHost()->GetWidget()->GetView())
[email protected]bafe6cd2012-05-23 23:09:502176 return NULL;
2177
[email protected]bafe6cd2012-05-23 23:09:502178 return new_contents;
2179}
2180
2181RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) {
2182 PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
2183 if (iter == pending_widget_views_.end()) {
2184 DCHECK(false);
2185 return NULL;
2186 }
2187
2188 RenderWidgetHostView* widget_host_view = iter->second;
2189 pending_widget_views_.erase(route_id);
2190
2191 RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
2192 if (!widget_host->GetProcess()->HasConnection()) {
2193 // The view has gone away or the renderer crashed. Nothing to do.
2194 return NULL;
2195 }
2196
2197 return widget_host_view;
2198}
2199
[email protected]f13b4202012-06-12 23:53:232200void WebContentsImpl::RequestMediaAccessPermission(
[email protected]33662e52013-01-07 21:31:092201 const MediaStreamRequest& request,
[email protected]8ff00d72012-10-23 19:12:212202 const MediaResponseCallback& callback) {
[email protected]d19b84b2014-03-14 11:52:372203 if (delegate_) {
[email protected]f13b4202012-06-12 23:53:232204 delegate_->RequestMediaAccessPermission(this, request, callback);
[email protected]d19b84b2014-03-14 11:52:372205 } else {
dcheng59716272016-04-09 05:19:082206 callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN,
2207 std::unique_ptr<MediaStreamUI>());
[email protected]d19b84b2014-03-14 11:52:372208 }
[email protected]f13b4202012-06-12 23:53:232209}
2210
grunell657d4d82014-09-18 00:09:432211bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin,
2212 MediaStreamType type) {
2213 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE ||
2214 type == MEDIA_DEVICE_VIDEO_CAPTURE);
2215 return delegate_ &&
2216 delegate_->CheckMediaAccessPermission(this, security_origin, type);
2217}
2218
[email protected]cc9200432013-07-23 23:02:402219SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace(
2220 SiteInstance* instance) {
2221 return controller_.GetSessionStorageNamespace(instance);
2222}
2223
[email protected]6de7fc482014-06-06 10:46:442224SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() {
2225 return controller_.GetSessionStorageNamespaceMap();
2226}
2227
[email protected]9b159a52013-10-03 17:24:552228FrameTree* WebContentsImpl::GetFrameTree() {
2229 return &frame_tree_;
2230}
2231
lukendc35e7f2014-11-10 19:06:142232void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) {
2233 virtual_keyboard_requested_ = requested;
2234}
2235
2236bool WebContentsImpl::IsVirtualKeyboardRequested() {
2237 return virtual_keyboard_requested_;
2238}
2239
aelias5252baa2016-04-10 01:18:022240bool WebContentsImpl::IsOverridingUserAgent() {
2241 return GetController().GetVisibleEntry() &&
2242 GetController().GetVisibleEntry()->GetIsOverridingUserAgent();
2243}
2244
[email protected]95640212014-07-26 18:14:302245AccessibilityMode WebContentsImpl::GetAccessibilityMode() const {
2246 return accessibility_mode_;
2247}
2248
[email protected]31a71eaf2014-03-13 01:47:362249void WebContentsImpl::AccessibilityEventReceived(
2250 const std::vector<AXEventNotificationDetails>& details) {
2251 FOR_EACH_OBSERVER(
2252 WebContentsObserver, observers_, AccessibilityEventReceived(details));
2253}
2254
dmazzonia656928e2014-09-15 20:28:542255RenderFrameHost* WebContentsImpl::GetGuestByInstanceID(
fsamuel833ee7c2015-02-13 23:40:402256 RenderFrameHost* render_frame_host,
dmazzonia656928e2014-09-15 20:28:542257 int browser_plugin_instance_id) {
2258 BrowserPluginGuestManager* guest_manager =
2259 GetBrowserContext()->GetGuestManager();
fsamuel9cbc00a2015-04-17 20:30:202260 if (!guest_manager)
2261 return nullptr;
2262
dmazzonia656928e2014-09-15 20:28:542263 WebContents* guest = guest_manager->GetGuestByInstanceID(
fsamuel2e9413d2015-02-25 01:25:442264 render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id);
dmazzonia656928e2014-09-15 20:28:542265 if (!guest)
fsamuel9cbc00a2015-04-17 20:30:202266 return nullptr;
2267
dmazzonia656928e2014-09-15 20:28:542268 return guest->GetMainFrame();
2269}
2270
blundellc57b93f2014-10-29 13:19:572271GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() {
2272 return geolocation_service_context_.get();
2273}
2274
alogvinovf50445a2015-10-30 13:00:122275WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() {
2276 return wake_lock_service_context_.get();
2277}
2278
[email protected]edc3af82013-12-12 21:24:072279void WebContentsImpl::OnShowValidationMessage(
2280 const gfx::Rect& anchor_in_root_view,
[email protected]6ff9c8f2013-12-20 09:05:292281 const base::string16& main_text,
2282 const base::string16& sub_text) {
[email protected]edc3af82013-12-12 21:24:072283 if (delegate_)
2284 delegate_->ShowValidationMessage(
2285 this, anchor_in_root_view, main_text, sub_text);
2286}
2287
2288void WebContentsImpl::OnHideValidationMessage() {
2289 if (delegate_)
2290 delegate_->HideValidationMessage(this);
2291}
2292
2293void WebContentsImpl::OnMoveValidationMessage(
2294 const gfx::Rect& anchor_in_root_view) {
2295 if (delegate_)
2296 delegate_->MoveValidationMessage(this, anchor_in_root_view);
2297}
2298
lfgbb9c28a2016-03-01 03:19:492299void WebContentsImpl::SendScreenRects() {
kenrbc52e1b4e2016-03-20 01:03:372300 for (FrameTreeNode* node : frame_tree_.Nodes()) {
2301 if (node->current_frame_host()->GetRenderWidgetHost())
2302 node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects();
2303 }
lfgbb9c28a2016-03-01 03:19:492304
lfgdb5c4ed2016-03-04 23:09:072305 RenderWidgetHostViewBase* rwhv =
2306 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2307 if (rwhv) {
2308 SendPageMessage(new PageMsg_UpdateWindowScreenRect(
2309 MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow()));
2310 }
2311
[email protected]32deec62013-05-15 23:55:042312 if (browser_plugin_embedder_)
[email protected]a7568e62013-06-14 07:50:442313 browser_plugin_embedder_->DidSendScreenRects();
[email protected]32deec62013-05-15 23:55:042314}
2315
ekaramad2bd4a2f2016-04-06 20:12:462316const TextInputState* WebContentsImpl::GetTextInputState() {
2317 if (GetOuterWebContents())
2318 return GetOuterWebContents()->GetTextInputState();
2319 // A RWHV should update WebContentsImpl in its destruction path so that state
2320 // type is reset to none.
2321 DCHECK(view_with_active_text_input_ ||
2322 text_input_state_->type == ui::TEXT_INPUT_TYPE_NONE);
2323 return text_input_state_.get();
2324}
2325
2326void WebContentsImpl::UpdateTextInputState(RenderWidgetHostViewBase* rwhv,
2327 bool text_input_state_changed) {
2328 // If there is an outer WebContents, let it process this update.
2329 if (GetOuterWebContents()) {
2330 return GetOuterWebContents()->UpdateTextInputState(
2331 rwhv, text_input_state_changed);
2332 }
2333
2334 // If this RWHV has a text input type of NONE, then there is nothing to
2335 // report to the tab RWHV.
2336 if (view_with_active_text_input_.get() != rwhv &&
2337 rwhv->text_input_state()->type == ui::TEXT_INPUT_TYPE_NONE)
2338 return;
2339
2340 if (rwhv->text_input_state()->type != ui::TEXT_INPUT_TYPE_NONE)
2341 view_with_active_text_input_ = rwhv->GetWeakPtr();
2342 else
2343 view_with_active_text_input_.reset();
2344
2345 *text_input_state_ = *rwhv->text_input_state();
2346
2347 // The top level RWHV should know about the change.
2348 RenderWidgetHostViewBase* tab_rwhv =
2349 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
2350 if (tab_rwhv)
2351 tab_rwhv->UpdateInputMethodIfNecessary(text_input_state_changed);
2352}
2353
[email protected]95640212014-07-26 18:14:302354BrowserAccessibilityManager*
2355 WebContentsImpl::GetRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452356 RenderFrameHostImpl* rfh = GetMainFrame();
2357 return rfh ? rfh->browser_accessibility_manager() : nullptr;
[email protected]95640212014-07-26 18:14:302358}
2359
2360BrowserAccessibilityManager*
2361 WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() {
creisc014b402015-04-23 16:41:452362 RenderFrameHostImpl* rfh = GetMainFrame();
2363 return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr;
[email protected]95640212014-07-26 18:14:302364}
2365
mohsen7ab1ec16ec2015-07-02 18:26:232366void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) {
2367 RenderFrameHost* focused_frame = GetFocusedFrame();
2368 if (!focused_frame)
2369 return;
2370
2371 focused_frame->Send(new InputMsg_MoveRangeSelectionExtent(
2372 focused_frame->GetRoutingID(), extent));
2373}
2374
2375void WebContentsImpl::SelectRange(const gfx::Point& base,
2376 const gfx::Point& extent) {
2377 RenderFrameHost* focused_frame = GetFocusedFrame();
2378 if (!focused_frame)
2379 return;
2380
2381 focused_frame->Send(
2382 new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent));
2383}
2384
aurimasab0319022015-07-10 21:57:382385void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust,
2386 int end_adjust) {
2387 RenderFrameHost* focused_frame = GetFocusedFrame();
2388 if (!focused_frame)
2389 return;
2390
2391 focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset(
2392 focused_frame->GetRoutingID(), start_adjust, end_adjust));
2393}
2394
[email protected]b172aee2012-04-10 17:05:262395void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) {
[email protected]222f5822014-02-05 23:40:492396 const gfx::Size old_size = GetPreferredSize();
[email protected]bcd2815602012-01-14 18:17:232397 preferred_size_ = pref_size;
[email protected]222f5822014-02-05 23:40:492398 OnPreferredSizeChanged(old_size);
[email protected]0548c5352011-09-07 00:33:332399}
2400
avic3aa8422015-11-09 20:57:222401void WebContentsImpl::ResizeDueToAutoResize(
2402 RenderWidgetHostImpl* render_widget_host,
2403 const gfx::Size& new_size) {
2404 if (render_widget_host != GetRenderViewHost()->GetWidget())
2405 return;
2406
[email protected]61e2b3cc2012-03-02 16:13:342407 if (delegate_)
2408 delegate_->ResizeDueToAutoResize(this, new_size);
2409}
2410
[email protected]b172aee2012-04-10 17:05:262411WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) {
[email protected]e5d549d2011-12-28 01:29:202412 if (!delegate_)
2413 return NULL;
[email protected]00c37fc2011-08-02 00:22:502414
[email protected]e5d549d2011-12-28 01:29:202415 WebContents* new_contents = delegate_->OpenURLFromTab(this, params);
[email protected]e5d549d2011-12-28 01:29:202416 return new_contents;
[email protected]d5f942ba2008-09-26 19:30:342417}
2418
[email protected]6b618e62012-08-16 12:59:182419bool WebContentsImpl::Send(IPC::Message* message) {
2420 if (!GetRenderViewHost()) {
2421 delete message;
2422 return false;
2423 }
2424
2425 return GetRenderViewHost()->Send(message);
2426}
2427
[email protected]a86c0e962013-12-17 17:10:392428void WebContentsImpl::RenderFrameForInterstitialPageCreated(
2429 RenderFrameHost* render_frame_host) {
[email protected]ba45bfd2012-05-22 21:51:442430 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]a86c0e962013-12-17 17:10:392431 RenderFrameForInterstitialPageCreated(render_frame_host));
[email protected]ba45bfd2012-05-22 21:51:442432}
2433
[email protected]20ca0382013-02-28 19:50:072434void WebContentsImpl::AttachInterstitialPage(
2435 InterstitialPageImpl* interstitial_page) {
2436 DCHECK(interstitial_page);
[email protected]fa944cb82013-11-15 17:51:212437 GetRenderManager()->set_interstitial_page(interstitial_page);
[email protected]90fb08ed2013-09-24 17:43:292438
2439 // Cancel any visible dialogs so that they don't interfere with the
2440 // interstitial.
creis89a0f782015-05-27 16:13:172441 CancelActiveAndPendingDialogs();
[email protected]90fb08ed2013-09-24 17:43:292442
[email protected]20ca0382013-02-28 19:50:072443 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2444 DidAttachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252445
2446 // Stop the throbber if needed while the interstitial page is shown.
2447 if (frame_tree_.IsLoading())
2448 LoadingStateChanged(true, true, nullptr);
2449}
2450
2451void WebContentsImpl::DidProceedOnInterstitial() {
2452 // The interstitial page should no longer be pausing the throbber.
2453 DCHECK(!(ShowingInterstitialPage() &&
2454 GetRenderManager()->interstitial_page()->pause_throbber()));
2455
2456 // Restart the throbber now that the interstitial page no longer pauses it.
2457 if (ShowingInterstitialPage() && frame_tree_.IsLoading())
2458 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072459}
2460
2461void WebContentsImpl::DetachInterstitialPage() {
clamy44e84ce2016-02-22 15:38:252462 bool interstitial_pausing_throbber =
2463 ShowingInterstitialPage() &&
2464 GetRenderManager()->interstitial_page()->pause_throbber();
[email protected]6832c8bc2014-04-29 07:20:572465 if (ShowingInterstitialPage())
[email protected]fa944cb82013-11-15 17:51:212466 GetRenderManager()->remove_interstitial_page();
[email protected]20ca0382013-02-28 19:50:072467 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2468 DidDetachInterstitialPage());
clamy44e84ce2016-02-22 15:38:252469
2470 // Restart the throbber if needed now that the interstitial page is going
2471 // away.
2472 if (interstitial_pausing_throbber && frame_tree_.IsLoading())
2473 LoadingStateChanged(true, true, nullptr);
[email protected]20ca0382013-02-28 19:50:072474}
2475
avi2b177592014-12-10 02:08:022476void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset,
2477 int history_length) {
2478 SetHistoryOffsetAndLengthForView(
2479 GetRenderViewHost(), history_offset, history_length);
2480}
2481
2482void WebContentsImpl::SetHistoryOffsetAndLengthForView(
2483 RenderViewHost* render_view_host,
2484 int history_offset,
2485 int history_length) {
2486 render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength(
2487 render_view_host->GetRoutingID(), history_offset, history_length));
[email protected]796931a92011-08-10 01:32:142488}
2489
toyoshim24a4c7ab2016-04-05 09:24:142490void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) {
[email protected]1f3fc1d2014-04-03 14:50:172491 RenderFrameHost* focused_frame = GetFocusedFrame();
2492 if (!focused_frame)
2493 return;
2494
[email protected]959be4c2014-04-08 15:01:332495 focused_frame->Send(new FrameMsg_Reload(
toyoshim24a4c7ab2016-04-05 09:24:142496 focused_frame->GetRoutingID(), bypass_cache));
[email protected]959be4c2014-04-08 15:01:332497}
2498
megjablon3f5941072016-02-04 23:27:522499void WebContentsImpl::ReloadLoFiImages() {
2500 SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE));
2501}
2502
[email protected]959be4c2014-04-08 15:01:332503void WebContentsImpl::Undo() {
2504 RenderFrameHost* focused_frame = GetFocusedFrame();
2505 if (!focused_frame)
2506 return;
2507
2508 focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID()));
2509 RecordAction(base::UserMetricsAction("Undo"));
2510}
2511
2512void WebContentsImpl::Redo() {
2513 RenderFrameHost* focused_frame = GetFocusedFrame();
2514 if (!focused_frame)
2515 return;
2516 focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID()));
2517 RecordAction(base::UserMetricsAction("Redo"));
2518}
2519
2520void WebContentsImpl::Cut() {
2521 RenderFrameHost* focused_frame = GetFocusedFrame();
2522 if (!focused_frame)
2523 return;
2524
2525 focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID()));
2526 RecordAction(base::UserMetricsAction("Cut"));
2527}
2528
2529void WebContentsImpl::Copy() {
2530 RenderFrameHost* focused_frame = GetFocusedFrame();
2531 if (!focused_frame)
2532 return;
2533
2534 focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID()));
2535 RecordAction(base::UserMetricsAction("Copy"));
2536}
2537
2538void WebContentsImpl::CopyToFindPboard() {
2539#if defined(OS_MACOSX)
2540 RenderFrameHost* focused_frame = GetFocusedFrame();
2541 if (!focused_frame)
2542 return;
2543
2544 // Windows/Linux don't have the concept of a find pasteboard.
2545 focused_frame->Send(
2546 new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID()));
2547 RecordAction(base::UserMetricsAction("CopyToFindPboard"));
2548#endif
2549}
2550
2551void WebContentsImpl::Paste() {
2552 RenderFrameHost* focused_frame = GetFocusedFrame();
2553 if (!focused_frame)
2554 return;
2555
2556 focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID()));
2557 RecordAction(base::UserMetricsAction("Paste"));
2558}
2559
2560void WebContentsImpl::PasteAndMatchStyle() {
2561 RenderFrameHost* focused_frame = GetFocusedFrame();
2562 if (!focused_frame)
2563 return;
2564
2565 focused_frame->Send(new InputMsg_PasteAndMatchStyle(
2566 focused_frame->GetRoutingID()));
2567 RecordAction(base::UserMetricsAction("PasteAndMatchStyle"));
2568}
2569
2570void WebContentsImpl::Delete() {
2571 RenderFrameHost* focused_frame = GetFocusedFrame();
2572 if (!focused_frame)
2573 return;
2574
2575 focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID()));
2576 RecordAction(base::UserMetricsAction("DeleteSelection"));
2577}
2578
2579void WebContentsImpl::SelectAll() {
2580 RenderFrameHost* focused_frame = GetFocusedFrame();
2581 if (!focused_frame)
2582 return;
2583
2584 focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID()));
2585 RecordAction(base::UserMetricsAction("SelectAll"));
2586}
2587
2588void WebContentsImpl::Unselect() {
2589 RenderFrameHost* focused_frame = GetFocusedFrame();
2590 if (!focused_frame)
2591 return;
2592
2593 focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID()));
2594 RecordAction(base::UserMetricsAction("Unselect"));
[email protected]1f3fc1d2014-04-03 14:50:172595}
2596
2597void WebContentsImpl::Replace(const base::string16& word) {
2598 RenderFrameHost* focused_frame = GetFocusedFrame();
2599 if (!focused_frame)
2600 return;
2601
[email protected]959be4c2014-04-08 15:01:332602 focused_frame->Send(new InputMsg_Replace(
2603 focused_frame->GetRoutingID(), word));
[email protected]1f3fc1d2014-04-03 14:50:172604}
2605
2606void WebContentsImpl::ReplaceMisspelling(const base::string16& word) {
2607 RenderFrameHost* focused_frame = GetFocusedFrame();
2608 if (!focused_frame)
2609 return;
2610
[email protected]959be4c2014-04-08 15:01:332611 focused_frame->Send(new InputMsg_ReplaceMisspelling(
2612 focused_frame->GetRoutingID(), word));
2613}
2614
2615void WebContentsImpl::NotifyContextMenuClosed(
2616 const CustomContextMenuContext& context) {
2617 RenderFrameHost* focused_frame = GetFocusedFrame();
2618 if (!focused_frame)
2619 return;
2620
2621 focused_frame->Send(new FrameMsg_ContextMenuClosed(
2622 focused_frame->GetRoutingID(), context));
2623}
2624
2625void WebContentsImpl::ExecuteCustomContextMenuCommand(
2626 int action, const CustomContextMenuContext& context) {
2627 RenderFrameHost* focused_frame = GetFocusedFrame();
2628 if (!focused_frame)
2629 return;
2630
2631 focused_frame->Send(new FrameMsg_CustomContextMenuAction(
2632 focused_frame->GetRoutingID(), context, action));
[email protected]4fed3702014-04-01 09:08:002633}
2634
[email protected]fc2b46b2014-05-03 16:33:452635gfx::NativeView WebContentsImpl::GetNativeView() {
2636 return view_->GetNativeView();
2637}
2638
2639gfx::NativeView WebContentsImpl::GetContentNativeView() {
2640 return view_->GetContentNativeView();
2641}
2642
2643gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() {
2644 return view_->GetTopLevelNativeWindow();
2645}
2646
2647gfx::Rect WebContentsImpl::GetViewBounds() {
2648 return view_->GetViewBounds();
2649}
2650
2651gfx::Rect WebContentsImpl::GetContainerBounds() {
2652 gfx::Rect rv;
2653 view_->GetContainerBounds(&rv);
2654 return rv;
2655}
2656
2657DropData* WebContentsImpl::GetDropData() {
2658 return view_->GetDropData();
2659}
2660
2661void WebContentsImpl::Focus() {
miu9e14e492014-10-25 02:39:042662 view_->Focus();
[email protected]fc2b46b2014-05-03 16:33:452663}
2664
2665void WebContentsImpl::SetInitialFocus() {
miu9e14e492014-10-25 02:39:042666 view_->SetInitialFocus();
[email protected]fc2b46b2014-05-03 16:33:452667}
2668
2669void WebContentsImpl::StoreFocus() {
miu9e14e492014-10-25 02:39:042670 view_->StoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452671}
2672
2673void WebContentsImpl::RestoreFocus() {
miu9e14e492014-10-25 02:39:042674 view_->RestoreFocus();
[email protected]fc2b46b2014-05-03 16:33:452675}
2676
[email protected]b172aee2012-04-10 17:05:262677void WebContentsImpl::FocusThroughTabTraversal(bool reverse) {
[email protected]0bfbf882011-12-22 18:19:272678 if (ShowingInterstitialPage()) {
[email protected]fa944cb82013-11-15 17:51:212679 GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse);
[email protected]7e383692009-06-12 19:14:542680 return;
2681 }
[email protected]0b431992014-06-24 00:08:032682 RenderWidgetHostView* const fullscreen_view =
2683 GetFullscreenRenderWidgetHostView();
2684 if (fullscreen_view) {
2685 fullscreen_view->Focus();
2686 return;
2687 }
creisc014b402015-04-23 16:41:452688 GetRenderViewHost()->SetInitialFocus(reverse);
[email protected]96d185d2009-04-24 03:28:542689}
2690
[email protected]b172aee2012-04-10 17:05:262691bool WebContentsImpl::ShowingInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212692 return GetRenderManager()->interstitial_page() != NULL;
[email protected]96d185d2009-04-24 03:28:542693}
2694
[email protected]b172aee2012-04-10 17:05:262695InterstitialPage* WebContentsImpl::GetInterstitialPage() const {
[email protected]fa944cb82013-11-15 17:51:212696 return GetRenderManager()->interstitial_page();
[email protected]686493142011-07-15 21:47:222697}
2698
[email protected]b172aee2012-04-10 17:05:262699bool WebContentsImpl::IsSavable() {
[email protected]a53209b2012-01-20 16:48:162700 // WebKit creates Document object when MIME type is application/xhtml+xml,
2701 // so we also support this MIME type.
2702 return contents_mime_type_ == "text/html" ||
2703 contents_mime_type_ == "text/xml" ||
2704 contents_mime_type_ == "application/xhtml+xml" ||
2705 contents_mime_type_ == "text/plain" ||
2706 contents_mime_type_ == "text/css" ||
rsleevic327b48f82015-04-30 02:03:252707 mime_util::IsSupportedJavascriptMimeType(contents_mime_type_);
[email protected]a53209b2012-01-20 16:48:162708}
2709
[email protected]b172aee2012-04-10 17:05:262710void WebContentsImpl::OnSavePage() {
[email protected]c7dd2f62011-07-18 15:57:592711 // If we can not save the page, try to download it.
[email protected]a53209b2012-01-20 16:48:162712 if (!IsSavable()) {
[email protected]35869622012-10-26 23:23:552713 RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML);
nasko89ad7742015-03-05 22:14:192714 SaveFrame(GetLastCommittedURL(), Referrer());
[email protected]27678b2a2012-02-04 22:09:142715 return;
[email protected]c7dd2f62011-07-18 15:57:592716 }
2717
2718 Stop();
2719
2720 // Create the save package and possibly prompt the user for the name to save
2721 // the page as. The user prompt is an asynchronous operation that runs on
2722 // another thread.
2723 save_package_ = new SavePackage(this);
2724 save_package_->GetSaveInfo();
2725}
2726
2727// Used in automated testing to bypass prompting the user for file names.
2728// Instead, the names and paths are hard coded rather than running them through
2729// file name sanitation and extension / mime checking.
[email protected]2dec8ec2013-02-07 19:20:342730bool WebContentsImpl::SavePage(const base::FilePath& main_file,
2731 const base::FilePath& dir_path,
[email protected]8ff00d72012-10-23 19:12:212732 SavePageType save_type) {
[email protected]c7dd2f62011-07-18 15:57:592733 // Stop the page from navigating.
2734 Stop();
2735
2736 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]8ff00d72012-10-23 19:12:212737 return save_package_->Init(SavePackageDownloadCreatedCallback());
[email protected]c7dd2f62011-07-18 15:57:592738}
2739
[email protected]3c71576ce2013-07-23 02:00:012740void WebContentsImpl::SaveFrame(const GURL& url,
2741 const Referrer& referrer) {
kundaji6c7f9692015-03-09 18:00:372742 SaveFrameWithHeaders(url, referrer, std::string());
2743}
2744
2745void WebContentsImpl::SaveFrameWithHeaders(const GURL& url,
2746 const Referrer& referrer,
2747 const std::string& headers) {
nasko89ad7742015-03-05 22:14:192748 if (!GetLastCommittedURL().is_valid())
[email protected]3c71576ce2013-07-23 02:00:012749 return;
sammc92af61552014-11-19 23:27:402750 if (delegate_ && delegate_->SaveFrame(url, referrer))
2751 return;
2752
nasko89ad7742015-03-05 22:14:192753 // TODO(nasko): This check for main frame is incorrect and should be fixed
2754 // by explicitly passing in which frame this method should target.
2755 bool is_main_frame = (url == GetLastCommittedURL());
[email protected]3c71576ce2013-07-23 02:00:012756
2757 DownloadManager* dlm =
2758 BrowserContext::GetDownloadManager(GetBrowserContext());
2759 if (!dlm)
2760 return;
avib7348942015-12-25 20:57:102761 int64_t post_id = -1;
[email protected]3c71576ce2013-07-23 02:00:012762 if (is_main_frame) {
[email protected]6286a372013-10-09 04:03:272763 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3c71576ce2013-07-23 02:00:012764 if (entry)
2765 post_id = entry->GetPostID();
2766 }
dcheng59716272016-04-09 05:19:082767 std::unique_ptr<DownloadUrlParameters> params(
[email protected]3c71576ce2013-07-23 02:00:012768 DownloadUrlParameters::FromWebContents(this, url));
2769 params->set_referrer(referrer);
2770 params->set_post_id(post_id);
[email protected]3c71576ce2013-07-23 02:00:012771 if (post_id >= 0)
2772 params->set_method("POST");
2773 params->set_prompt(true);
kundaji6c7f9692015-03-09 18:00:372774
2775 if (headers.empty()) {
2776 params->set_prefer_cache(true);
2777 } else {
brettw26dab8f02015-08-08 00:28:472778 for (const base::StringPiece& key_value :
2779 base::SplitStringPiece(
2780 headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
2781 std::vector<std::string> pair = base::SplitString(
2782 key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
kundaji6c7f9692015-03-09 18:00:372783 DCHECK_EQ(2ul, pair.size());
2784 params->add_request_header(pair[0], pair[1]);
2785 }
2786 }
dcheng36b6aec92015-12-26 06:16:362787 dlm->DownloadUrl(std::move(params));
[email protected]3c71576ce2013-07-23 02:00:012788}
2789
[email protected]b172aee2012-04-10 17:05:262790void WebContentsImpl::GenerateMHTML(
[email protected]2dec8ec2013-02-07 19:20:342791 const base::FilePath& file,
avib7348942015-12-25 20:57:102792 const base::Callback<void(int64_t)>& callback) {
[email protected]18516cf92013-08-28 18:19:482793 MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback);
[email protected]aa4f3972012-03-01 18:12:122794}
2795
[email protected]b172aee2012-04-10 17:05:262796const std::string& WebContentsImpl::GetContentsMimeType() const {
[email protected]0bfbf882011-12-22 18:19:272797 return contents_mime_type_;
2798}
2799
[email protected]b172aee2012-04-10 17:05:262800bool WebContentsImpl::WillNotifyDisconnection() const {
[email protected]0bfbf882011-12-22 18:19:272801 return notify_disconnection_;
2802}
2803
[email protected]b172aee2012-04-10 17:05:262804void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) {
[email protected]be1f56ab2011-12-22 06:55:312805 SetEncoding(encoding);
[email protected]6b618e62012-08-16 12:59:182806 Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding));
[email protected]8cb5d5b2010-02-09 11:36:162807}
2808
[email protected]b172aee2012-04-10 17:05:262809void WebContentsImpl::ResetOverrideEncoding() {
[email protected]ef3adfc2014-05-11 00:04:542810 canonical_encoding_.clear();
[email protected]6b618e62012-08-16 12:59:182811 Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID()));
[email protected]8cb5d5b2010-02-09 11:36:162812}
2813
[email protected]8ff00d72012-10-23 19:12:212814RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() {
[email protected]0bfbf882011-12-22 18:19:272815 return &renderer_preferences_;
2816}
2817
[email protected]e35ccd52012-05-23 16:22:472818void WebContentsImpl::Close() {
2819 Close(GetRenderViewHost());
2820}
2821
[email protected]cf200a562013-05-03 16:24:292822void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y,
[email protected]180ef242013-11-07 06:50:462823 int screen_x, int screen_y, blink::WebDragOperation operation) {
[email protected]cf200a562013-05-03 16:24:292824 if (browser_plugin_embedder_.get())
2825 browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y,
2826 screen_x, screen_y, operation);
2827 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452828 GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x,
2829 screen_y, operation);
[email protected]cf200a562013-05-03 16:24:292830}
2831
[email protected]d60f3702013-12-26 16:30:242832void WebContentsImpl::DidGetResourceResponseStart(
2833 const ResourceRequestDetails& details) {
2834 controller_.ssl_manager()->DidStartResourceResponse(details);
2835
2836 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
2837 DidGetResourceResponseStart(details));
[email protected]d60f3702013-12-26 16:30:242838}
2839
2840void WebContentsImpl::DidGetRedirectForResourceRequest(
creis114ca1b2014-11-13 23:51:462841 RenderFrameHost* render_frame_host,
[email protected]d60f3702013-12-26 16:30:242842 const ResourceRedirectDetails& details) {
2843 controller_.ssl_manager()->DidReceiveResourceRedirect(details);
2844
2845 FOR_EACH_OBSERVER(
2846 WebContentsObserver,
2847 observers_,
creis114ca1b2014-11-13 23:51:462848 DidGetRedirectForResourceRequest(render_frame_host, details));
[email protected]d60f3702013-12-26 16:30:242849
2850 // TODO(avi): Remove. http://crbug.com/170921
2851 NotificationService::current()->Notify(
2852 NOTIFICATION_RESOURCE_RECEIVED_REDIRECT,
2853 Source<WebContents>(this),
2854 Details<const ResourceRedirectDetails>(&details));
2855}
2856
calamity7fe55ce2015-04-10 03:59:372857void WebContentsImpl::NotifyWebContentsFocused() {
2858 FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused());
2859}
2860
[email protected]b172aee2012-04-10 17:05:262861void WebContentsImpl::SystemDragEnded() {
[email protected]151a63d2011-12-20 22:32:522862 if (GetRenderViewHost())
creisc014b402015-04-23 16:41:452863 GetRenderViewHost()->DragSourceSystemDragEnded();
[email protected]cf200a562013-05-03 16:24:292864 if (browser_plugin_embedder_.get())
2865 browser_plugin_embedder_->SystemDragEnded();
[email protected]7813bd72011-02-05 02:19:342866}
2867
[email protected]e35ccd52012-05-23 16:22:472868void WebContentsImpl::UserGestureDone() {
dominickn9c7ceaa32016-02-27 01:52:532869 OnUserInteraction(GetRenderViewHost()->GetWidget(),
2870 blink::WebInputEvent::Undefined);
[email protected]e35ccd52012-05-23 16:22:472871}
2872
[email protected]b172aee2012-04-10 17:05:262873void WebContentsImpl::SetClosedByUserGesture(bool value) {
[email protected]0bfbf882011-12-22 18:19:272874 closed_by_user_gesture_ = value;
2875}
2876
[email protected]b172aee2012-04-10 17:05:262877bool WebContentsImpl::GetClosedByUserGesture() const {
[email protected]0bfbf882011-12-22 18:19:272878 return closed_by_user_gesture_;
2879}
2880
[email protected]b172aee2012-04-10 17:05:262881void WebContentsImpl::ViewSource() {
[email protected]1788e772010-12-15 16:40:502882 if (!delegate_)
2883 return;
2884
[email protected]6286a372013-10-09 04:03:272885 NavigationEntry* entry = GetController().GetLastCommittedEntry();
2886 if (!entry)
[email protected]1788e772010-12-15 16:40:502887 return;
2888
[email protected]6286a372013-10-09 04:03:272889 delegate_->ViewSourceForTab(this, entry->GetURL());
[email protected]77d8d622010-12-15 10:30:122890}
2891
[email protected]b172aee2012-04-10 17:05:262892void WebContentsImpl::ViewFrameSource(const GURL& url,
[email protected]691aa2f2013-05-28 22:52:042893 const PageState& page_state) {
[email protected]932b7a12011-03-09 12:50:272894 if (!delegate_)
2895 return;
2896
[email protected]691aa2f2013-05-28 22:52:042897 delegate_->ViewSourceForFrame(this, url, page_state);
[email protected]932b7a12011-03-09 12:50:272898}
2899
[email protected]b172aee2012-04-10 17:05:262900int WebContentsImpl::GetMinimumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272901 return minimum_zoom_percent_;
2902}
2903
[email protected]b172aee2012-04-10 17:05:262904int WebContentsImpl::GetMaximumZoomPercent() const {
[email protected]0bfbf882011-12-22 18:19:272905 return maximum_zoom_percent_;
2906}
2907
mcnee432e47d2015-11-09 19:37:462908void WebContentsImpl::SetPageScale(float page_scale_factor) {
2909 Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor));
ccameronb7c1d6c2015-03-09 17:08:242910}
2911
[email protected]b172aee2012-04-10 17:05:262912gfx::Size WebContentsImpl::GetPreferredSize() const {
[email protected]222f5822014-02-05 23:40:492913 return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_;
[email protected]bcd2815602012-01-14 18:17:232914}
2915
[email protected]b172aee2012-04-10 17:05:262916bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) {
[email protected]660f18e2014-05-15 20:53:052917 if (GetBrowserPluginGuest())
2918 return GetBrowserPluginGuest()->LockMouse(allowed);
2919
creisc014b402015-04-23 16:41:452920 return GetRenderViewHost()
avi3627ecac2015-10-16 17:40:432921 ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest(
2922 allowed)
creisc014b402015-04-23 16:41:452923 : false;
[email protected]0bfbf882011-12-22 18:19:272924}
2925
[email protected]b172aee2012-04-10 17:05:262926bool WebContentsImpl::HasOpener() const {
alexmose201c7cd2015-06-10 17:14:212927 return GetOpener() != NULL;
[email protected]a0358d72012-03-09 14:06:502928}
2929
alexmose201c7cd2015-06-10 17:14:212930WebContentsImpl* WebContentsImpl::GetOpener() const {
2931 FrameTreeNode* opener_ftn = frame_tree_.root()->opener();
2932 return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr;
jochen55ff3502014-12-18 20:52:572933}
2934
[email protected]cb805452013-05-22 15:16:212935void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) {
[email protected]8ed16472014-04-11 19:02:482936 if (!color_chooser_info_.get())
2937 return;
2938 RenderFrameHost* rfh = RenderFrameHost::FromID(
2939 color_chooser_info_->render_process_id,
2940 color_chooser_info_->render_frame_id);
2941 if (!rfh)
2942 return;
2943
2944 rfh->Send(new FrameMsg_DidChooseColorResponse(
2945 rfh->GetRoutingID(), color_chooser_info_->identifier, color));
[email protected]da8543762012-03-20 08:52:202946}
2947
[email protected]cb805452013-05-22 15:16:212948void WebContentsImpl::DidEndColorChooser() {
[email protected]8ed16472014-04-11 19:02:482949 if (!color_chooser_info_.get())
2950 return;
2951 RenderFrameHost* rfh = RenderFrameHost::FromID(
2952 color_chooser_info_->render_process_id,
2953 color_chooser_info_->render_frame_id);
2954 if (!rfh)
2955 return;
2956
2957 rfh->Send(new FrameMsg_DidEndColorChooser(
2958 rfh->GetRoutingID(), color_chooser_info_->identifier));
2959 color_chooser_info_.reset();
[email protected]da8543762012-03-20 08:52:202960}
2961
halton.huoca2eabd2015-07-06 08:17:402962int WebContentsImpl::DownloadImage(
2963 const GURL& url,
2964 bool is_favicon,
2965 uint32_t max_bitmap_size,
2966 bool bypass_cache,
2967 const WebContents::ImageDownloadCallback& callback) {
amistry9f01b772015-07-29 01:54:552968 DCHECK_CURRENTLY_ON(BrowserThread::UI);
halton.huoca2eabd2015-07-06 08:17:402969 static int next_image_download_id = 0;
leon.han6e9dee22016-02-25 03:44:062970 const content::mojom::ImageDownloaderPtr& mojo_image_downloader =
halton.huoca2eabd2015-07-06 08:17:402971 GetMainFrame()->GetMojoImageDownloader();
amistry9f01b772015-07-29 01:54:552972 const int download_id = ++next_image_download_id;
2973 if (!mojo_image_downloader) {
2974 // If the renderer process is dead (i.e. crash, or memory pressure on
2975 // Android), the downloader service will be invalid. Pre-Mojo, this would
2976 // hang the callback indefinetly since the IPC would be dropped. Now,
2977 // respond with a 400 HTTP error code to indicate that something went wrong.
2978 BrowserThread::PostTask(
2979 BrowserThread::UI, FROM_HERE,
pkotwicz75ca8ffd2016-02-16 23:10:192980 base::Bind(&WebContentsImpl::OnDidDownloadImage,
leon.hancbc4bc3c2016-02-26 07:08:522981 weak_factory_.GetWeakPtr(), callback, download_id, url, 400,
2982 nullptr, nullptr));
amistry9f01b772015-07-29 01:54:552983 return download_id;
2984 }
2985
halton.huoca2eabd2015-07-06 08:17:402986 mojo_image_downloader->DownloadImage(
leon.hancbc4bc3c2016-02-26 07:08:522987 mojo::String::From(url), is_favicon, max_bitmap_size, bypass_cache,
2988 base::Bind(&WebContentsImpl::OnDidDownloadImage,
2989 weak_factory_.GetWeakPtr(), callback, download_id, url));
amistry9f01b772015-07-29 01:54:552990 return download_id;
[email protected]795c28972012-12-06 06:13:392991}
2992
[email protected]5dcaf8e2013-12-28 01:31:422993bool WebContentsImpl::IsSubframe() const {
2994 return is_subframe_;
2995}
2996
[email protected]36ec24f2014-01-09 00:32:082997void WebContentsImpl::Find(int request_id,
2998 const base::string16& search_text,
2999 const blink::WebFindOptions& options) {
thestig6057a6b22015-11-12 23:01:333000 // Cowardly refuse to search for no text.
3001 if (search_text.empty()) {
3002 NOTREACHED();
3003 return;
3004 }
3005
raymes0fa0be52014-10-13 20:38:093006 // See if a top level browser plugin handles the find request first.
paulmeyerc0b762b2016-04-13 11:55:173007 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473008 if (browser_plugin_embedder_ &&
3009 browser_plugin_embedder_->Find(request_id, search_text, options)) {
3010 return;
raymes0fa0be52014-10-13 20:38:093011 }
paulmeyerc0b762b2016-04-13 11:55:173012
3013 GetOrCreateFindRequestManager()->Find(request_id, search_text, options);
[email protected]36ec24f2014-01-09 00:32:083014}
3015
3016void WebContentsImpl::StopFinding(StopFindAction action) {
raymes2bc64182015-02-06 01:23:013017 // See if a top level browser plugin handles the stop finding request first.
paulmeyerc0b762b2016-04-13 11:55:173018 // TODO(paulmeyer): Remove this after find-in-page works across GuestViews.
paulmeyer95703b92015-08-10 17:38:473019 if (browser_plugin_embedder_ &&
3020 browser_plugin_embedder_->StopFinding(action)) {
3021 return;
raymes2bc64182015-02-06 01:23:013022 }
paulmeyerc0b762b2016-04-13 11:55:173023
3024 GetOrCreateFindRequestManager()->StopFinding(action);
[email protected]36ec24f2014-01-09 00:32:083025}
3026
[email protected]4fe53add2014-04-08 19:53:363027void WebContentsImpl::InsertCSS(const std::string& css) {
3028 GetMainFrame()->Send(new FrameMsg_CSSInsertRequest(
3029 GetMainFrame()->GetRoutingID(), css));
3030}
3031
dalecurtisbc6572e12014-09-12 19:22:303032bool WebContentsImpl::WasRecentlyAudible() {
avayvodcc85bbd2015-08-28 19:11:153033 return audio_stream_monitor_.WasRecentlyAudible();
dalecurtisbc6572e12014-09-12 19:22:303034}
3035
mlamouriefdca9d2014-09-16 16:55:403036void WebContentsImpl::GetManifest(const GetManifestCallback& callback) {
3037 manifest_manager_host_->GetManifest(GetMainFrame(), callback);
3038}
3039
dominickn6919ce32015-10-15 01:52:283040void WebContentsImpl::HasManifest(const HasManifestCallback& callback) {
3041 manifest_manager_host_->HasManifest(GetMainFrame(), callback);
3042}
3043
bokanece34a82016-01-28 19:49:463044void WebContentsImpl::ExitFullscreen(bool will_cause_resize) {
mlamouri7a78d6fd2015-01-17 13:23:533045 // Clean up related state and initiate the fullscreen exit.
avi3627ecac2015-10-16 17:40:433046 GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary();
bokanece34a82016-01-28 19:49:463047 ExitFullscreenMode(will_cause_resize);
mlamouri7a78d6fd2015-01-17 13:23:533048}
3049
mariakhomenko44bdc4732015-04-29 01:55:383050void WebContentsImpl::ResumeLoadingCreatedWebContents() {
mariakhomenkoa4971c12015-07-21 19:04:373051 if (delayed_open_url_params_.get()) {
3052 OpenURL(*delayed_open_url_params_.get());
3053 delayed_open_url_params_.reset(nullptr);
3054 return;
3055 }
3056
mariakhomenko44bdc4732015-04-29 01:55:383057 // Resume blocked requests for both the RenderViewHost and RenderFrameHost.
3058 // TODO(brettw): It seems bogus to reach into here and initialize the host.
dfalcantarae6b7b46752015-07-10 18:14:163059 if (is_resume_pending_) {
3060 is_resume_pending_ = false;
avi0f1bbc9712015-11-17 02:58:133061 GetRenderViewHost()->GetWidget()->Init();
dfalcantarae6b7b46752015-07-10 18:14:163062 GetMainFrame()->Init();
3063 }
mariakhomenko44bdc4732015-04-29 01:55:383064}
3065
[email protected]b172aee2012-04-10 17:05:263066bool WebContentsImpl::FocusLocationBarByDefault() {
palmerc70cb1f2016-03-04 23:41:263067 // When the browser is started with about:blank as the startup URL, focus
3068 // the location bar (which will also select its contents) so people can
3069 // simply begin typing to navigate elsewhere.
3070 //
3071 // We need to be careful not to trigger this for anything other than the
3072 // startup navigation. In particular, if we allow an attacker to open a
3073 // popup to about:blank, then navigate, focusing the Omnibox will cause the
3074 // end of the new URL to be scrolled into view instead of the start,
3075 // allowing the attacker to spoof other URLs. The conditions checked here
3076 // are all aimed at ensuring no such attacker-controlled navigation can
3077 // trigger this.
3078 //
3079 // Note that we check the pending entry instead of the visible one; for the
3080 // startup URL case these are the same, but for the attacker-controlled
3081 // navigation case the visible entry is the committed "about:blank" URL and
3082 // the pending entry is the problematic navigation elsewhere.
3083 NavigationEntryImpl* entry = controller_.GetPendingEntry();
3084 if (controller_.IsInitialNavigation() && entry &&
3085 !entry->is_renderer_initiated() &&
3086 entry->GetURL() == GURL(url::kAboutBlankURL)) {
[email protected]0c9406632013-02-08 01:13:333087 return true;
palmerc70cb1f2016-03-04 23:41:263088 }
[email protected]0c9406632013-02-08 01:13:333089 return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this);
[email protected]0bfbf882011-12-22 18:19:273090}
3091
[email protected]b172aee2012-04-10 17:05:263092void WebContentsImpl::SetFocusToLocationBar(bool select_all) {
[email protected]0bfbf882011-12-22 18:19:273093 if (delegate_)
3094 delegate_->SetFocusToLocationBar(select_all);
[email protected]c40d6232011-03-25 00:16:213095}
3096
clamy0e119882015-07-31 16:12:333097void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) {
3098 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3099 DidStartNavigation(navigation_handle));
3100}
3101
3102void WebContentsImpl::DidRedirectNavigation(
3103 NavigationHandle* navigation_handle) {
3104 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3105 DidRedirectNavigation(navigation_handle));
3106}
3107
clamyefca29e2015-09-17 00:22:113108void WebContentsImpl::ReadyToCommitNavigation(
3109 NavigationHandle* navigation_handle) {
3110 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3111 ReadyToCommitNavigation(navigation_handle));
3112}
3113
clamy0e119882015-07-31 16:12:333114void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) {
3115 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3116 DidFinishNavigation(navigation_handle));
3117}
3118
[email protected]52913802013-12-10 05:52:183119void WebContentsImpl::DidStartProvisionalLoad(
3120 RenderFrameHostImpl* render_frame_host,
[email protected]52913802013-12-10 05:52:183121 const GURL& validated_url,
3122 bool is_error_page,
3123 bool is_iframe_srcdoc) {
[email protected]0d60f0192011-04-14 12:40:103124 // Notify observers about the start of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483125 FOR_EACH_OBSERVER(
3126 WebContentsObserver,
3127 observers_,
3128 DidStartProvisionalLoadForFrame(
3129 render_frame_host, validated_url, is_error_page, is_iframe_srcdoc));
dmazzonibf8cec42015-02-08 08:28:083130
3131 // Notify accessibility if this is a reload.
3132 NavigationEntry* entry = controller_.GetVisibleEntry();
3133 if (entry && ui::PageTransitionCoreTypeIs(
3134 entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) {
3135 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3136 BrowserAccessibilityManager* manager =
3137 ftn->current_frame_host()->browser_accessibility_manager();
3138 if (manager)
3139 manager->UserIsReloading();
3140 }
[email protected]400992b2012-06-14 00:03:543141}
3142
[email protected]3109fbb72014-01-06 23:57:153143void WebContentsImpl::DidFailProvisionalLoadWithError(
3144 RenderFrameHostImpl* render_frame_host,
3145 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
3146 GURL validated_url(params.url);
[email protected]860234a2014-07-01 00:35:313147 FOR_EACH_OBSERVER(WebContentsObserver,
3148 observers_,
3149 DidFailProvisionalLoad(render_frame_host,
[email protected]860234a2014-07-01 00:35:313150 validated_url,
3151 params.error_code,
gsennton6fbb38692015-06-24 19:23:553152 params.error_description,
3153 params.was_ignored_by_handler));
dmazzonibf8cec42015-02-08 08:28:083154
3155 FrameTreeNode* ftn = render_frame_host->frame_tree_node();
3156 BrowserAccessibilityManager* manager =
3157 ftn->current_frame_host()->browser_accessibility_manager();
3158 if (manager)
3159 manager->NavigationFailed();
[email protected]3109fbb72014-01-06 23:57:153160}
3161
[email protected]b80624c2014-02-09 02:46:553162void WebContentsImpl::DidFailLoadWithError(
3163 RenderFrameHostImpl* render_frame_host,
[email protected]b80624c2014-02-09 02:46:553164 const GURL& url,
[email protected]b80624c2014-02-09 02:46:553165 int error_code,
gsennton6fbb38692015-06-24 19:23:553166 const base::string16& error_description,
3167 bool was_ignored_by_handler) {
[email protected]3619ca82014-07-09 15:45:143168 FOR_EACH_OBSERVER(
3169 WebContentsObserver,
3170 observers_,
gsennton6fbb38692015-06-24 19:23:553171 DidFailLoad(render_frame_host, url, error_code, error_description,
3172 was_ignored_by_handler));
[email protected]b80624c2014-02-09 02:46:553173}
3174
[email protected]52913802013-12-10 05:52:183175void WebContentsImpl::NotifyChangedNavigationState(
3176 InvalidateTypes changed_flags) {
3177 NotifyNavigationStateChanged(changed_flags);
3178}
3179
[email protected]3691e5cf2014-01-22 10:16:203180void WebContentsImpl::DidStartNavigationToPendingEntry(
[email protected]3691e5cf2014-01-22 10:16:203181 const GURL& url,
3182 NavigationController::ReloadType reload_type) {
3183 // Notify observers about navigation.
3184 FOR_EACH_OBSERVER(
3185 WebContentsObserver,
3186 observers_,
3187 DidStartNavigationToPendingEntry(url, reload_type));
3188}
3189
[email protected]8cb834e2014-03-06 14:23:233190void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host,
3191 const OpenURLParams& params) {
dchengb907f7332015-01-07 20:35:503192 // OpenURL can blow away the source RFH. Use the process/frame routing ID as a
3193 // weak pointer of sorts.
3194 const int32_t process_id = render_frame_host->GetProcess()->GetID();
3195 const int32_t frame_id = render_frame_host->GetRoutingID();
3196
[email protected]65920f332014-03-04 21:14:183197 WebContents* new_contents = OpenURL(params);
3198
dchengb907f7332015-01-07 20:35:503199 if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) {
[email protected]65920f332014-03-04 21:14:183200 // Notify observers.
3201 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3202 DidOpenRequestedURL(new_contents,
creis114ca1b2014-11-13 23:51:463203 render_frame_host,
[email protected]65920f332014-03-04 21:14:183204 params.url,
3205 params.referrer,
3206 params.disposition,
creis114ca1b2014-11-13 23:51:463207 params.transition));
[email protected]65920f332014-03-04 21:14:183208 }
3209}
3210
creis29460272015-12-16 04:38:223211bool WebContentsImpl::ShouldTransferNavigation() {
3212 if (!delegate_)
3213 return true;
3214 return delegate_->ShouldTransferNavigation();
3215}
3216
[email protected]aa62afd2014-04-22 19:22:463217bool WebContentsImpl::ShouldPreserveAbortedURLs() {
3218 if (!delegate_)
3219 return false;
3220 return delegate_->ShouldPreserveAbortedURLs(this);
3221}
3222
[email protected]37567b432014-02-12 01:12:223223void WebContentsImpl::DidCommitProvisionalLoad(
[email protected]27dd82fd2014-03-03 22:11:433224 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223225 const GURL& url,
Sylvain Defresnec6ccc77d2014-09-19 10:19:353226 ui::PageTransition transition_type) {
[email protected]37567b432014-02-12 01:12:223227 // Notify observers about the commit of the provisional load.
[email protected]e2d2d4202014-07-03 12:17:483228 FOR_EACH_OBSERVER(WebContentsObserver,
3229 observers_,
3230 DidCommitProvisionalLoadForFrame(
3231 render_frame_host, url, transition_type));
dmazzonibf8cec42015-02-08 08:28:083232
3233 BrowserAccessibilityManager* manager =
3234 render_frame_host->browser_accessibility_manager();
3235 if (manager)
3236 manager->NavigationSucceeded();
[email protected]37567b432014-02-12 01:12:223237}
3238
[email protected]0d0f4c492014-04-02 06:42:573239void WebContentsImpl::DidNavigateMainFramePreCommit(
[email protected]5cfbddc2014-06-23 23:52:233240 bool navigation_is_within_page) {
[email protected]0d0f4c492014-04-02 06:42:573241 // Ensure fullscreen mode is exited before committing the navigation to a
3242 // different page. The next page will not start out assuming it is in
3243 // fullscreen mode.
[email protected]5cfbddc2014-06-23 23:52:233244 if (navigation_is_within_page) {
[email protected]dfc39cb2014-04-09 22:58:193245 // No page change? Then, the renderer and browser can remain in fullscreen.
[email protected]0d0f4c492014-04-02 06:42:573246 return;
3247 }
avibf58fa0c2015-11-11 01:45:523248 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:463249 ExitFullscreen(false);
avibf58fa0c2015-11-11 01:45:523250 DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()));
[email protected]0d0f4c492014-04-02 06:42:573251}
3252
[email protected]37567b432014-02-12 01:12:223253void WebContentsImpl::DidNavigateMainFramePostCommit(
sky8b00392d2015-01-10 00:30:283254 RenderFrameHostImpl* render_frame_host,
[email protected]37567b432014-02-12 01:12:223255 const LoadCommittedDetails& details,
3256 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
3257 if (details.is_navigation_to_different_page()) {
3258 // Clear the status bubble. This is a workaround for a bug where WebKit
3259 // doesn't let us know that the cursor left an element during a
3260 // transition (this is also why the mouse cursor remains as a hand after
3261 // clicking on a link); see bugs 1184641 and 980803. We don't want to
3262 // clear the bubble when a user navigates to a named anchor in the same
3263 // page.
sky8b00392d2015-01-10 00:30:283264 UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL());
lanwei9d343ad22015-02-11 01:46:003265
3266 RenderWidgetHostViewBase* rwhvb =
3267 static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView());
3268 if (rwhvb)
3269 rwhvb->OnDidNavigateMainFrameToNewPage();
yusufod41c5f92015-03-06 00:14:283270
peter90afaba2015-06-01 12:05:293271 did_first_visually_non_empty_paint_ = false;
3272
yusufod41c5f92015-03-06 00:14:283273 // Reset theme color on navigation to new page.
3274 theme_color_ = SK_ColorTRANSPARENT;
[email protected]37567b432014-02-12 01:12:223275 }
3276
3277 if (!details.is_in_page) {
3278 // Once the main frame is navigated, we're no longer considered to have
3279 // displayed insecure content.
3280 displayed_insecure_content_ = false;
3281 SSLManager::NotifySSLInternalStateChanged(
3282 GetController().GetBrowserContext());
3283 }
3284
3285 // Notify observers about navigation.
3286 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3287 DidNavigateMainFrame(details, params));
3288
[email protected]e85165c642014-06-10 14:34:313289 if (delegate_)
[email protected]37567b432014-02-12 01:12:223290 delegate_->DidNavigateMainFramePostCommit(this);
[email protected]e85165c642014-06-10 14:34:313291 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]37567b432014-02-12 01:12:223292}
3293
3294void WebContentsImpl::DidNavigateAnyFramePostCommit(
3295 RenderFrameHostImpl* render_frame_host,
3296 const LoadCommittedDetails& details,
3297 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {
[email protected]b4c84012014-04-28 19:51:103298 // Now that something has committed, we don't need to track whether the
3299 // initial page has been accessed.
3300 has_accessed_initial_document_ = false;
3301
[email protected]37567b432014-02-12 01:12:223302 // If we navigate off the page, close all JavaScript dialogs.
creis89a0f782015-05-27 16:13:173303 if (!details.is_in_page)
3304 CancelActiveAndPendingDialogs();
[email protected]37567b432014-02-12 01:12:223305
avid53461d2016-02-25 17:15:043306 // If this is a user-initiated navigation, start allowing JavaScript dialogs
3307 // again.
3308 if (params.gesture == NavigationGestureUser && dialog_manager_)
3309 dialog_manager_->ResetDialogState(this);
3310
[email protected]37567b432014-02-12 01:12:223311 // Notify observers about navigation.
3312 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
mlamouri2d2fd2f2014-10-08 16:00:093313 DidNavigateAnyFrame(render_frame_host, details, params));
[email protected]37567b432014-02-12 01:12:223314}
3315
3316void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) {
3317 contents_mime_type_ = mime_type;
3318}
3319
[email protected]277857a2014-06-03 10:38:013320bool WebContentsImpl::CanOverscrollContent() const {
[email protected]e85165c642014-06-10 14:34:313321 // Disable overscroll when touch emulation is on. See crbug.com/369938.
[email protected]34ff1cfc2014-08-20 06:16:053322 if (force_disable_overscroll_content_)
[email protected]e85165c642014-06-10 14:34:313323 return false;
3324
[email protected]37567b432014-02-12 01:12:223325 if (delegate_)
3326 return delegate_->CanOverscrollContent();
3327
3328 return false;
3329}
3330
[email protected]37b64c52014-07-11 21:14:053331void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) {
peter90afaba2015-06-01 12:05:293332 // Update the theme color. This is to be published to observers after the
3333 // first visually non-empty paint.
yusufod41c5f92015-03-06 00:14:283334 theme_color_ = theme_color;
peter90afaba2015-06-01 12:05:293335
3336 if (did_first_visually_non_empty_paint_ &&
3337 last_sent_theme_color_ != theme_color_) {
3338 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3339 DidChangeThemeColor(theme_color_));
3340 last_sent_theme_color_ = theme_color_;
3341 }
[email protected]e7104762014-06-20 19:17:253342}
3343
[email protected]b172aee2012-04-10 17:05:263344void WebContentsImpl::OnDidLoadResourceFromMemoryCache(
[email protected]724159a2010-12-30 01:11:183345 const GURL& url,
[email protected]70435962011-08-02 20:13:283346 const std::string& security_info,
3347 const std::string& http_method,
[email protected]6d6cfb3a2012-05-23 22:53:183348 const std::string& mime_type,
[email protected]6c1e05212014-07-31 00:59:403349 ResourceType resource_type) {
estarka5635c42015-07-14 00:06:533350 SSLStatus status;
3351 if (!DeserializeSecurityInfo(security_info, &status)) {
3352 bad_message::ReceivedBadMessage(
3353 GetRenderProcessHost(),
3354 bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO);
3355 return;
3356 }
[email protected]724159a2010-12-30 01:11:183357
3358 // Send out a notification that we loaded a resource from our memory cache.
avie0d90182015-07-08 19:33:593359 // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details.
[email protected]8ff00d72012-10-23 19:12:213360 LoadFromMemoryCacheDetails details(
rob1ca070f2016-01-12 01:06:263361 url, status.cert_id, status.cert_status, http_method, mime_type,
3362 resource_type);
[email protected]724159a2010-12-30 01:11:183363
[email protected]b0f724c2013-09-05 04:21:133364 controller_.ssl_manager()->DidLoadFromMemoryCache(details);
3365
3366 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3367 DidLoadResourceFromMemoryCache(details));
3368
[email protected]8bfc8272013-09-09 20:10:533369 if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
3370 scoped_refptr<net::URLRequestContextGetter> request_context(
[email protected]6c1e05212014-07-31 00:59:403371 resource_type == RESOURCE_TYPE_MEDIA ?
[email protected]8bfc8272013-09-09 20:10:533372 GetBrowserContext()->GetMediaRequestContextForRenderProcess(
3373 GetRenderProcessHost()->GetID()) :
jam608f2992016-03-31 16:35:343374 GetRenderProcessHost()->GetStoragePartition()->
3375 GetURLRequestContext());
[email protected]8bfc8272013-09-09 20:10:533376 BrowserThread::PostTask(
3377 BrowserThread::IO,
3378 FROM_HERE,
3379 base::Bind(&NotifyCacheOnIO, request_context, url, http_method));
3380 }
[email protected]724159a2010-12-30 01:11:183381}
3382
[email protected]b172aee2012-04-10 17:05:263383void WebContentsImpl::OnDidDisplayInsecureContent() {
[email protected]e6e30ac2014-01-13 21:24:393384 RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent"));
[email protected]724159a2010-12-30 01:11:183385 displayed_insecure_content_ = true;
[email protected]e67ebf32013-02-13 11:07:193386 SSLManager::NotifySSLInternalStateChanged(
3387 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183388}
3389
estark910b4572015-12-09 20:55:413390void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin,
3391 const GURL& target_url) {
[email protected]9450c462013-11-23 01:22:583392 LOG(WARNING) << security_origin << " ran insecure content from "
3393 << target_url.possibly_invalid_spec();
[email protected]e6e30ac2014-01-13 21:24:393394 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent"));
estark910b4572015-12-09 20:55:413395 if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom,
brettwa7ff1b292015-07-16 17:49:293396 base::CompareCase::INSENSITIVE_ASCII))
[email protected]e6e30ac2014-01-13 21:24:393397 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle"));
[email protected]330614de2012-02-13 17:07:183398 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e67ebf32013-02-13 11:07:193399 SSLManager::NotifySSLInternalStateChanged(
3400 GetController().GetBrowserContext());
[email protected]724159a2010-12-30 01:11:183401}
3402
estark910b4572015-12-09 20:55:413403void WebContentsImpl::OnDidDisplayContentWithCertificateErrors(
3404 const GURL& url,
3405 const std::string& security_info) {
3406 SSLStatus ssl;
3407 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3408 bad_message::ReceivedBadMessage(
3409 GetRenderProcessHost(),
3410 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3411 return;
3412 }
3413
3414 displayed_insecure_content_ = true;
3415 SSLManager::NotifySSLInternalStateChanged(
3416 GetController().GetBrowserContext());
3417}
3418
3419void WebContentsImpl::OnDidRunContentWithCertificateErrors(
3420 const GURL& security_origin,
3421 const GURL& url,
3422 const std::string& security_info) {
3423 SSLStatus ssl;
3424 if (!DeserializeSecurityInfo(security_info, &ssl)) {
3425 bad_message::ReceivedBadMessage(
3426 GetRenderProcessHost(),
3427 bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO);
3428 return;
3429 }
3430
3431 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
3432 SSLManager::NotifySSLInternalStateChanged(
3433 GetController().GetBrowserContext());
3434}
3435
[email protected]501052ff2014-02-21 22:19:073436void WebContentsImpl::OnDocumentLoadedInFrame() {
nasko907fcb62015-01-28 04:24:113437 if (!HasValidFrameSource())
naskofbd033392015-01-27 02:34:473438 return;
naskofbd033392015-01-27 02:34:473439
[email protected]1d62cf72014-02-07 21:31:573440 RenderFrameHostImpl* rfh =
3441 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143442 FOR_EACH_OBSERVER(
3443 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh));
[email protected]724159a2010-12-30 01:11:183444}
3445
naskofbd033392015-01-27 02:34:473446void WebContentsImpl::OnDidFinishLoad(const GURL& url) {
nasko907fcb62015-01-28 04:24:113447 if (!HasValidFrameSource())
[email protected]8b3af1e2014-01-24 13:29:123448 return;
[email protected]a1b99262013-12-27 21:56:223449
[email protected]8b3af1e2014-01-24 13:29:123450 GURL validated_url(url);
[email protected]f114fa42013-12-06 17:06:443451 RenderProcessHost* render_process_host =
[email protected]028053d42014-03-05 22:20:373452 render_frame_message_source_->GetProcess();
[email protected]5dcaf8e2013-12-28 01:31:423453 render_process_host->FilterURL(false, &validated_url);
[email protected]028053d42014-03-05 22:20:373454
[email protected]61ac9e242014-03-21 20:55:263455 RenderFrameHostImpl* rfh =
3456 static_cast<RenderFrameHostImpl*>(render_frame_message_source_);
[email protected]3619ca82014-07-09 15:45:143457 FOR_EACH_OBSERVER(
3458 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url));
[email protected]1a55c5be2011-11-29 11:36:313459}
3460
[email protected]b172aee2012-04-10 17:05:263461void WebContentsImpl::OnGoToEntryAtOffset(int offset) {
avi6ddfcae2015-06-30 15:50:573462 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
3463 controller_.GoToOffset(offset);
[email protected]216813952011-05-19 22:21:263464}
3465
[email protected]b172aee2012-04-10 17:05:263466void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent,
[email protected]fce823222014-05-30 16:24:303467 int maximum_percent) {
[email protected]216813952011-05-19 22:21:263468 minimum_zoom_percent_ = minimum_percent;
3469 maximum_zoom_percent_ = maximum_percent;
[email protected]216813952011-05-19 22:21:263470}
3471
mcnee432e47d2015-11-09 19:37:463472void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) {
3473 bool is_one = page_scale_factor == 1.f;
3474 if (is_one != page_scale_factor_is_one_) {
3475 page_scale_factor_is_one_ = is_one;
3476
3477 HostZoomMapImpl* host_zoom_map =
3478 static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this));
3479
3480 if (host_zoom_map && GetRenderProcessHost()) {
3481 host_zoom_map->SetPageScaleFactorIsOneForView(
3482 GetRenderProcessHost()->GetID(), GetRoutingID(),
3483 page_scale_factor_is_one_);
3484 }
3485 }
3486
3487 FOR_EACH_OBSERVER(WebContentsObserver,
3488 observers_,
3489 OnPageScaleFactorChanged(page_scale_factor));
3490}
3491
[email protected]b172aee2012-04-10 17:05:263492void WebContentsImpl::OnEnumerateDirectory(int request_id,
[email protected]2dec8ec2013-02-07 19:20:343493 const base::FilePath& path) {
[email protected]e5f2de02012-07-20 22:15:433494 if (!delegate_)
3495 return;
3496
[email protected]b9535422012-02-09 01:47:593497 ChildProcessSecurityPolicyImpl* policy =
3498 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]45d5c602013-10-07 18:33:223499 if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path))
[email protected]b9535422012-02-09 01:47:593500 delegate_->EnumerateDirectory(this, request_id, path);
[email protected]3a29a6e2011-08-24 18:26:213501}
3502
[email protected]b172aee2012-04-10 17:05:263503void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol,
3504 const GURL& url,
[email protected]fcf75d42013-12-03 20:11:263505 const base::string16& title,
[email protected]3a3b75a2012-06-01 08:38:363506 bool user_gesture) {
[email protected]e5f2de02012-07-20 22:15:433507 if (!delegate_)
3508 return;
3509
[email protected]b9535422012-02-09 01:47:593510 ChildProcessSecurityPolicyImpl* policy =
3511 ChildProcessSecurityPolicyImpl::GetInstance();
[email protected]8f810632013-06-06 22:33:323512 if (policy->IsPseudoScheme(protocol))
[email protected]b9535422012-02-09 01:47:593513 return;
[email protected]8f810632013-06-06 22:33:323514
[email protected]c125e532014-05-10 20:39:063515 delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture);
[email protected]7d189022011-08-25 22:54:203516}
3517
[email protected]f5273e52014-07-14 16:30:203518void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol,
3519 const GURL& url,
3520 bool user_gesture) {
3521 if (!delegate_)
3522 return;
3523
3524 ChildProcessSecurityPolicyImpl* policy =
3525 ChildProcessSecurityPolicyImpl::GetInstance();
3526 if (policy->IsPseudoScheme(protocol))
3527 return;
3528
3529 delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture);
3530}
3531
kouhei40f03cb2015-09-24 07:47:013532void WebContentsImpl::OnUpdatePageImportanceSignals(
3533 const PageImportanceSignals& signals) {
3534 page_importance_signals_ = signals;
3535}
3536
[email protected]b172aee2012-04-10 17:05:263537void WebContentsImpl::OnFindReply(int request_id,
3538 int number_of_matches,
3539 const gfx::Rect& selection_rect,
3540 int active_match_ordinal,
3541 bool final_update) {
paulmeyerc0b762b2016-04-13 11:55:173542 // Forward the find reply to the FindRequestManager, along with the
3543 // RenderFrameHost associated with the frame that the reply came from.
3544 GetOrCreateFindRequestManager()->OnFindReply(render_frame_message_source_,
3545 request_id,
3546 number_of_matches,
3547 selection_rect,
3548 active_match_ordinal,
3549 final_update);
[email protected]b888919c2011-09-02 00:32:163550}
3551
mfomitchev2b8b066a2016-01-28 19:23:153552#if defined(OS_ANDROID)
[email protected]59363fc92012-09-05 03:46:313553void WebContentsImpl::OnFindMatchRectsReply(
3554 int version,
3555 const std::vector<gfx::RectF>& rects,
3556 const gfx::RectF& active_rect) {
paulmeyerc0b762b2016-04-13 11:55:173557 GetOrCreateFindRequestManager()->OnFindMatchRectsReply(
3558 render_frame_message_source_, version, rects, active_rect);
[email protected]59363fc92012-09-05 03:46:313559}
[email protected]583418cc2013-01-17 14:01:103560
[email protected]1ff427972013-02-07 21:14:073561void WebContentsImpl::OnOpenDateTimeDialog(
3562 const ViewHostMsg_DateTimeDialogValue_Params& value) {
ajith.v9e47ab52014-10-30 20:24:173563 date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(),
[email protected]ee59cbec2013-08-16 14:59:093564 GetRenderViewHost(),
3565 value.dialog_type,
[email protected]e8072562013-12-04 06:04:133566 value.dialog_value,
[email protected]ee59cbec2013-08-16 14:59:093567 value.minimum,
3568 value.maximum,
[email protected]6e08bfb2013-12-07 02:56:173569 value.step,
3570 value.suggestions);
[email protected]583418cc2013-01-17 14:01:103571}
[email protected]59363fc92012-09-05 03:46:313572#endif
3573
avi60bd4902015-09-23 20:39:243574void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) {
3575 std::string json = json_string;
3576 NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE,
3577 Source<WebContents>(this),
3578 Details<std::string>(&json));
[email protected]cfa856d62014-02-22 07:58:403579}
3580
[email protected]b172aee2012-04-10 17:05:263581void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url,
3582 bool blocked_by_policy) {
[email protected]7fc4bbb2011-09-08 21:23:103583 // Notify observers about navigation.
[email protected]d8c660432011-12-22 20:51:253584 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7fc4bbb2011-09-08 21:23:103585 AppCacheAccessed(manifest_url, blocked_by_policy));
3586}
3587
[email protected]8bc5ff02013-11-29 06:34:033588void WebContentsImpl::OnOpenColorChooser(
[email protected]8ed16472014-04-11 19:02:483589 int color_chooser_id,
3590 SkColor color,
3591 const std::vector<ColorSuggestion>& suggestions) {
nasko907fcb62015-01-28 04:24:113592 if (!HasValidFrameSource())
mukai38b1e4f2015-01-23 00:24:003593 return;
nasko907fcb62015-01-28 04:24:113594
[email protected]aa62afd2014-04-22 19:22:463595 ColorChooser* new_color_chooser = delegate_ ?
3596 delegate_->OpenColorChooser(this, color, suggestions) :
3597 NULL;
[email protected]820957a2014-01-14 14:56:303598 if (!new_color_chooser)
[email protected]cb805452013-05-22 15:16:213599 return;
[email protected]8ed16472014-04-11 19:02:483600 if (color_chooser_info_.get())
3601 color_chooser_info_->chooser->End();
3602
3603 color_chooser_info_.reset(new ColorChooserInfo(
3604 render_frame_message_source_->GetProcess()->GetID(),
3605 render_frame_message_source_->GetRoutingID(),
3606 new_color_chooser,
3607 color_chooser_id));
[email protected]da8543762012-03-20 08:52:203608}
3609
[email protected]b172aee2012-04-10 17:05:263610void WebContentsImpl::OnEndColorChooser(int color_chooser_id) {
[email protected]8ed16472014-04-11 19:02:483611 if (color_chooser_info_ &&
3612 color_chooser_id == color_chooser_info_->identifier)
3613 color_chooser_info_->chooser->End();
[email protected]da8543762012-03-20 08:52:203614}
3615
[email protected]b172aee2012-04-10 17:05:263616void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id,
[email protected]55578b0a2012-04-18 14:31:323617 SkColor color) {
[email protected]8ed16472014-04-11 19:02:483618 if (color_chooser_info_ &&
3619 color_chooser_id == color_chooser_info_->identifier)
3620 color_chooser_info_->chooser->SetSelectedColor(color);
[email protected]da8543762012-03-20 08:52:203621}
3622
[email protected]d0759f492012-04-19 22:50:503623// This exists for render views that don't have a WebUI, but do have WebUI
3624// bindings enabled.
3625void WebContentsImpl::OnWebUISend(const GURL& source_url,
3626 const std::string& name,
3627 const base::ListValue& args) {
3628 if (delegate_)
3629 delegate_->WebUISend(this, source_url, name, args);
3630}
3631
thestigc4cac8f2014-09-04 21:17:503632#if defined(ENABLE_PLUGINS)
emaxxe70f5e12015-05-29 11:26:003633void WebContentsImpl::OnPepperInstanceCreated() {
3634 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated());
3635}
3636
3637void WebContentsImpl::OnPepperInstanceDeleted() {
3638 FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted());
3639}
3640
tommyclie6633ca72014-10-31 00:40:423641void WebContentsImpl::OnPepperPluginHung(int plugin_child_id,
3642 const base::FilePath& path,
3643 bool is_hung) {
3644 UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1);
3645
3646 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3647 PluginHungStatusChanged(plugin_child_id, path, is_hung));
3648}
3649
3650void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path,
3651 base::ProcessId plugin_pid) {
3652 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3653 PluginCrashed(plugin_path, plugin_pid));
3654}
3655
[email protected]d8415ad92012-08-23 14:40:503656void WebContentsImpl::OnRequestPpapiBrokerPermission(
[email protected]ea0309c2013-08-06 19:35:443657 int routing_id,
[email protected]d8415ad92012-08-23 14:40:503658 const GURL& url,
[email protected]2dec8ec2013-02-07 19:20:343659 const base::FilePath& plugin_path) {
[email protected]8c8fc292012-11-23 18:57:163660 if (!delegate_) {
[email protected]ea0309c2013-08-06 19:35:443661 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163662 return;
[email protected]d8415ad92012-08-23 14:40:503663 }
3664
[email protected]8c8fc292012-11-23 18:57:163665 if (!delegate_->RequestPpapiBrokerPermission(
3666 this, url, plugin_path,
3667 base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult,
[email protected]ea0309c2013-08-06 19:35:443668 base::Unretained(this), routing_id))) {
[email protected]8c8fc292012-11-23 18:57:163669 NOTIMPLEMENTED();
[email protected]ea0309c2013-08-06 19:35:443670 OnPpapiBrokerPermissionResult(routing_id, false);
[email protected]8c8fc292012-11-23 18:57:163671 }
[email protected]d8415ad92012-08-23 14:40:503672}
3673
[email protected]ea0309c2013-08-06 19:35:443674void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id,
[email protected]d8415ad92012-08-23 14:40:503675 bool result) {
[email protected]ea0309c2013-08-06 19:35:443676 Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result));
[email protected]d8415ad92012-08-23 14:40:503677}
3678
fsamuel833ee7c2015-02-13 23:40:403679void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host,
3680 const IPC::Message& message) {
[email protected]7a846df2012-09-20 19:17:393681 CHECK(!browser_plugin_embedder_.get());
fsamuel60b42282015-03-10 03:29:143682 CreateBrowserPluginEmbedderIfNecessary();
fsamuel833ee7c2015-02-13 23:40:403683 browser_plugin_embedder_->OnMessageReceived(message, render_frame_host);
[email protected]19be7a62012-10-01 23:03:373684}
tommyclie6633ca72014-10-31 00:40:423685#endif // defined(ENABLE_PLUGINS)
[email protected]19be7a62012-10-01 23:03:373686
[email protected]795c28972012-12-06 06:13:393687void WebContentsImpl::OnUpdateFaviconURL(
[email protected]795c28972012-12-06 06:13:393688 const std::vector<FaviconURL>& candidates) {
pkotwiczf9bc20592015-04-21 18:57:063689 // We get updated favicon URLs after the page stops loading. If a cross-site
3690 // navigation occurs while a page is still loading, the initial page
3691 // may stop loading and send us updated favicon URLs after the navigation
3692 // for the new page has committed.
3693 RenderViewHostImpl* rvhi =
3694 static_cast<RenderViewHostImpl*>(render_view_message_source_);
3695 if (!rvhi->is_active())
3696 return;
3697
[email protected]795c28972012-12-06 06:13:393698 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293699 DidUpdateFaviconURL(candidates));
[email protected]795c28972012-12-06 06:13:393700}
3701
avayvod41634b12015-07-08 17:07:053702void WebContentsImpl::OnMediaSessionStateChanged() {
3703 MediaSession* session = MediaSession::Get(this);
3704 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3705 MediaSessionStateChanged(session->IsControllable(),
mlamouri2d1bfbd2016-03-17 13:14:543706 session->IsSuspended(),
3707 session->metadata()));
avayvod41634b12015-07-08 17:07:053708}
3709
3710void WebContentsImpl::ResumeMediaSession() {
mlamouri918734092016-03-12 04:47:523711 MediaSession::Get(this)->Resume(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053712}
3713
3714void WebContentsImpl::SuspendMediaSession() {
mlamouri918734092016-03-12 04:47:523715 MediaSession::Get(this)->Suspend(MediaSession::SuspendType::UI);
avayvod41634b12015-07-08 17:07:053716}
3717
mlamouri4c4fbed2015-08-17 15:51:013718void WebContentsImpl::StopMediaSession() {
mlamouri918734092016-03-12 04:47:523719 MediaSession::Get(this)->Stop(MediaSession::SuspendType::UI);
mlamouri4c4fbed2015-08-17 15:51:013720}
3721
[email protected]50279492014-05-05 23:24:293722void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() {
[email protected]9f268072013-11-07 00:02:153723 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:293724 DidFirstVisuallyNonEmptyPaint());
yusufod41c5f92015-03-06 00:14:283725
peter90afaba2015-06-01 12:05:293726 did_first_visually_non_empty_paint_ = true;
3727
yusufod41c5f92015-03-06 00:14:283728 if (theme_color_ != last_sent_theme_color_) {
3729 // Theme color should have updated by now if there was one.
3730 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3731 DidChangeThemeColor(theme_color_));
3732 last_sent_theme_color_ = theme_color_;
3733 }
[email protected]9f268072013-11-07 00:02:153734}
[email protected]d9030b82013-07-19 08:26:063735
[email protected]e67ebf32013-02-13 11:07:193736void WebContentsImpl::DidChangeVisibleSSLState() {
lgarron662dd522015-06-08 23:20:013737 if (delegate_) {
[email protected]25af6ec2014-06-06 19:35:073738 delegate_->VisibleSSLStateChanged(this);
lgarron662dd522015-06-08 23:20:013739
estark5ea80e52015-06-19 18:43:123740 SecurityStyleExplanations security_style_explanations;
3741 SecurityStyle security_style =
3742 delegate_->GetSecurityStyle(this, &security_style_explanations);
3743 FOR_EACH_OBSERVER(
3744 WebContentsObserver, observers_,
3745 SecurityStyleChanged(security_style, security_style_explanations));
lgarron662dd522015-06-08 23:20:013746 }
[email protected]e67ebf32013-02-13 11:07:193747}
3748
[email protected]17e286e2013-03-01 23:29:393749void WebContentsImpl::NotifyBeforeFormRepostWarningShow() {
3750 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
3751 BeforeFormRepostWarningShow());
3752}
3753
[email protected]ec6c05f2013-10-23 18:41:573754void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() {
3755 Activate();
3756 if (delegate_)
3757 delegate_->ShowRepostFormWarningDialog(this);
3758}
3759
[email protected]b4c84012014-04-28 19:51:103760bool WebContentsImpl::HasAccessedInitialDocument() {
3761 return has_accessed_initial_document_;
3762}
3763
[email protected]b172aee2012-04-10 17:05:263764void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) {
[email protected]74ce1ad2011-12-16 21:51:463765 // If we are creating a RVH for a restored controller, then we need to make
3766 // sure the RenderView starts with a next_page_id_ larger than the number
3767 // of restored entries. This must be called before the RenderView starts
3768 // navigating (to avoid a race between the browser updating max_page_id and
3769 // the renderer updating next_page_id_). Because of this, we only call this
3770 // from CreateRenderView and allow that to notify the RenderView for us.
[email protected]71fde352011-12-29 03:29:563771 int max_restored_page_id = controller_.GetMaxRestoredPageID();
[email protected]9f76c1e2012-03-05 15:15:583772 if (max_restored_page_id >
3773 GetMaxPageIDForSiteInstance(rvh->GetSiteInstance()))
3774 UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(),
3775 max_restored_page_id);
[email protected]420ae012009-04-24 05:16:323776}
3777
[email protected]b172aee2012-04-10 17:05:263778bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry,
[email protected]fcf75d42013-12-03 20:11:263779 const base::string16& title) {
[email protected]420ae012009-04-24 05:16:323780 // For file URLs without a title, use the pathname instead. In the case of a
3781 // synthesized title, we don't want the update to count toward the "one set
3782 // per page of the title to history."
[email protected]fcf75d42013-12-03 20:11:263783 base::string16 final_title;
[email protected]420ae012009-04-24 05:16:323784 bool explicit_set;
[email protected]36fc0392011-12-25 03:59:513785 if (entry && entry->GetURL().SchemeIsFile() && title.empty()) {
[email protected]32956122013-12-25 07:29:243786 final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName());
[email protected]420ae012009-04-24 05:16:323787 explicit_set = false; // Don't count synthetic titles toward the set limit.
3788 } else {
[email protected]8af69c6c2014-03-03 19:05:313789 base::TrimWhitespace(title, base::TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:323790 explicit_set = true;
3791 }
3792
[email protected]987fc3a2011-05-26 14:18:093793 // If a page is created via window.open and never navigated,
3794 // there will be no navigation entry. In this situation,
[email protected]73eb2602012-02-09 19:50:553795 // |page_title_when_no_navigation_entry_| will be used for page title.
[email protected]987fc3a2011-05-26 14:18:093796 if (entry) {
[email protected]36fc0392011-12-25 03:59:513797 if (final_title == entry->GetTitle())
[email protected]987fc3a2011-05-26 14:18:093798 return false; // Nothing changed, don't bother.
[email protected]420ae012009-04-24 05:16:323799
[email protected]36fc0392011-12-25 03:59:513800 entry->SetTitle(final_title);
[email protected]987fc3a2011-05-26 14:18:093801 } else {
3802 if (page_title_when_no_navigation_entry_ == final_title)
3803 return false; // Nothing changed, don't bother.
3804
3805 page_title_when_no_navigation_entry_ = final_title;
3806 }
[email protected]420ae012009-04-24 05:16:323807
[email protected]420ae012009-04-24 05:16:323808 // Lastly, set the title for the view.
[email protected]790e2fd2011-09-21 20:28:233809 view_->SetPageTitle(final_title);
[email protected]420ae012009-04-24 05:16:323810
[email protected]66798902013-10-01 18:40:163811 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]1ef02d242013-10-07 16:18:533812 TitleWasSet(entry, explicit_set));
[email protected]66798902013-10-01 18:40:163813
[email protected]420ae012009-04-24 05:16:323814 return true;
3815}
3816
fdegansa696e5112015-04-17 01:57:593817void WebContentsImpl::SendChangeLoadProgress() {
[email protected]960b0372014-05-19 18:01:003818 loading_last_progress_update_ = base::TimeTicks::Now();
[email protected]960b0372014-05-19 18:01:003819 if (delegate_)
fdegansa696e5112015-04-17 01:57:593820 delegate_->LoadProgressChanged(this, frame_tree_.load_progress());
[email protected]960b0372014-05-19 18:01:003821}
3822
3823void WebContentsImpl::ResetLoadProgressState() {
fdegans1d16355162015-03-26 11:58:343824 frame_tree_.ResetLoadProgress();
[email protected]960b0372014-05-19 18:01:003825 loading_weak_factory_.InvalidateWeakPtrs();
3826 loading_last_progress_update_ = base::TimeTicks();
3827}
3828
clamy44e84ce2016-02-22 15:38:253829// Notifies the RenderWidgetHost instance about the fact that the page is
3830// loading, or done loading.
3831void WebContentsImpl::LoadingStateChanged(bool to_different_document,
3832 bool due_to_interstitial,
3833 LoadNotificationDetails* details) {
3834 // Do not send notifications about loading changes in the FrameTree while the
3835 // interstitial page is pausing the throbber.
3836 if (ShowingInterstitialPage() &&
3837 GetRenderManager()->interstitial_page()->pause_throbber() &&
3838 !due_to_interstitial) {
3839 return;
3840 }
3841
3842 bool is_loading = IsLoading();
3843
3844 if (!is_loading) {
3845 load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE,
3846 base::string16());
3847 load_state_host_.clear();
3848 upload_size_ = 0;
3849 upload_position_ = 0;
3850 }
3851
3852 GetRenderManager()->SetIsLoading(is_loading);
3853
3854 waiting_for_response_ = is_loading;
3855 is_load_to_different_document_ = to_different_document;
3856
3857 if (delegate_)
3858 delegate_->LoadingStateChanged(this, to_different_document);
3859 NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD);
3860
3861 std::string url = (details ? details->url.possibly_invalid_spec() : "NULL");
3862 if (is_loading) {
3863 TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading",
3864 this, "URL", url, "Main FrameTreeNode id",
3865 GetFrameTree()->root()->frame_tree_node_id());
3866 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading());
3867 } else {
3868 TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading",
3869 this, "URL", url);
3870 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading());
3871 }
3872
3873 // TODO(avi): Remove. http://crbug.com/170921
3874 int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP;
3875 NotificationDetails det = NotificationService::NoDetails();
3876 if (details)
3877 det = Details<LoadNotificationDetails>(details);
3878 NotificationService::current()->Notify(
3879 type, Source<NavigationController>(&controller_), det);
3880}
3881
[email protected]02d7b6e2014-06-24 21:01:503882void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host,
3883 RenderViewHost* new_host) {
[email protected]420ae012009-04-24 05:16:323884 // After sending out a swap notification, we need to send a disconnect
3885 // notification so that clients that pick up a pointer to |this| can NULL the
3886 // pointer. See Bug 1230284.
3887 notify_disconnection_ = true;
[email protected]da7a7182013-09-06 08:11:113888 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]7b712ee22013-10-03 00:57:283889 RenderViewHostChanged(old_host, new_host));
[email protected]da7a7182013-09-06 08:11:113890
[email protected]7a846df2012-09-20 19:17:393891 // Ensure that the associated embedder gets cleared after a RenderViewHost
3892 // gets swapped, so we don't reuse the same embedder next time a
3893 // RenderViewHost is attached to this WebContents.
3894 RemoveBrowserPluginEmbedder();
[email protected]420ae012009-04-24 05:16:323895}
3896
[email protected]02d7b6e2014-06-24 21:01:503897void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host,
3898 RenderFrameHost* new_host) {
3899 FOR_EACH_OBSERVER(WebContentsObserver,
3900 observers_,
3901 RenderFrameHostChanged(old_host, new_host));
3902}
3903
[email protected]da7a7182013-09-06 08:11:113904// TODO(avi): Remove this entire function because this notification is already
3905// covered by two observer functions. http://crbug.com/170921
[email protected]b172aee2012-04-10 17:05:263906void WebContentsImpl::NotifyDisconnected() {
[email protected]420ae012009-04-24 05:16:323907 if (!notify_disconnection_)
3908 return;
3909
3910 notify_disconnection_ = false;
[email protected]8ff00d72012-10-23 19:12:213911 NotificationService::current()->Notify(
3912 NOTIFICATION_WEB_CONTENTS_DISCONNECTED,
3913 Source<WebContents>(this),
3914 NotificationService::NoDetails());
[email protected]420ae012009-04-24 05:16:323915}
3916
[email protected]cbb1ef592013-06-05 19:49:463917void WebContentsImpl::NotifyNavigationEntryCommitted(
3918 const LoadCommittedDetails& load_details) {
3919 FOR_EACH_OBSERVER(
3920 WebContentsObserver, observers_, NavigationEntryCommitted(load_details));
3921}
3922
[email protected]f114fa42013-12-06 17:06:443923bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host,
3924 const IPC::Message& message) {
3925 return OnMessageReceived(NULL, render_frame_host, message);
[email protected]271ff5792013-12-04 22:29:313926}
3927
[email protected]c31a84802014-04-03 15:55:493928const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const {
3929 return GetLastCommittedURL();
3930}
3931
[email protected]b849847b2013-12-10 21:57:583932void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) {
[email protected]b849847b2013-12-10 21:57:583933 FOR_EACH_OBSERVER(WebContentsObserver,
3934 observers_,
3935 RenderFrameCreated(render_frame_host));
[email protected]95640212014-07-26 18:14:303936 SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host);
clamy91b7abf2016-03-24 15:17:453937
3938 if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent())
3939 return;
3940
3941 NavigationEntry* entry = controller_.GetPendingEntry();
3942 if (entry && entry->IsViewSourceMode()) {
3943 // Put the renderer in view source mode.
3944 render_frame_host->Send(
3945 new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID()));
3946 }
[email protected]b849847b2013-12-10 21:57:583947}
3948
3949void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) {
3950 FOR_EACH_OBSERVER(WebContentsObserver,
3951 observers_,
3952 RenderFrameDeleted(render_frame_host));
3953}
3954
[email protected]a09d53ce2014-01-31 00:46:423955void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host,
3956 const ContextMenuParams& params) {
[email protected]077e704b2014-05-23 19:24:103957 ContextMenuParams context_menu_params(params);
[email protected]a09d53ce2014-01-31 00:46:423958 // Allow WebContentsDelegates to handle the context menu operation first.
[email protected]077e704b2014-05-23 19:24:103959 if (delegate_ && delegate_->HandleContextMenu(context_menu_params))
[email protected]a09d53ce2014-01-31 00:46:423960 return;
3961
[email protected]077e704b2014-05-23 19:24:103962 render_view_host_delegate_view_->ShowContextMenu(render_frame_host,
3963 context_menu_params);
[email protected]a09d53ce2014-01-31 00:46:423964}
3965
[email protected]87de04b02014-04-08 22:14:493966void WebContentsImpl::RunJavaScriptMessage(
[email protected]39f2f9252014-05-03 00:54:013967 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:493968 const base::string16& message,
3969 const base::string16& default_prompt,
3970 const GURL& frame_url,
3971 JavaScriptMessageType javascript_message_type,
3972 IPC::Message* reply_msg) {
3973 // Suppress JavaScript dialogs when requested. Also suppress messages when
3974 // showing an interstitial as it's shown over the previous page and we don't
3975 // want the hidden page's dialogs to interfere with the interstitial.
3976 bool suppress_this_message =
mathiash72a5e462014-11-19 08:18:503977 ShowingInterstitialPage() || !delegate_ ||
3978 delegate_->ShouldSuppressDialogs(this) ||
3979 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493980
3981 if (!suppress_this_message) {
mathiash72a5e462014-11-19 08:18:503982 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:493983 dialog_manager_->RunJavaScriptDialog(
jshin1fb76462016-04-05 22:13:033984 this, frame_url, javascript_message_type, message, default_prompt,
palmer4e0ae10d2015-09-03 23:38:413985 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:013986 render_frame_host->GetProcess()->GetID(),
palmer4e0ae10d2015-09-03 23:38:413987 render_frame_host->GetRoutingID(), reply_msg, false),
[email protected]87de04b02014-04-08 22:14:493988 &suppress_this_message);
3989 }
3990
3991 if (suppress_this_message) {
3992 // If we are suppressing messages, just reply as if the user immediately
3993 // pressed "Cancel", passing true to |dialog_was_suppressed|.
[email protected]39f2f9252014-05-03 00:54:013994 OnDialogClosed(render_frame_host->GetProcess()->GetID(),
3995 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:283996 true, false, base::string16());
[email protected]87de04b02014-04-08 22:14:493997 }
3998
3999 // OnDialogClosed (two lines up) may have caused deletion of this object (see
4000 // http://crbug.com/288961 ). The only safe thing to do here is return.
4001}
4002
4003void WebContentsImpl::RunBeforeUnloadConfirm(
[email protected]39f2f9252014-05-03 00:54:014004 RenderFrameHost* render_frame_host,
[email protected]87de04b02014-04-08 22:14:494005 bool is_reload,
4006 IPC::Message* reply_msg) {
[email protected]39f2f9252014-05-03 00:54:014007 RenderFrameHostImpl* rfhi =
4008 static_cast<RenderFrameHostImpl*>(render_frame_host);
[email protected]87de04b02014-04-08 22:14:494009 if (delegate_)
4010 delegate_->WillRunBeforeUnloadConfirm();
4011
4012 bool suppress_this_message =
nasko19736cc9f2016-04-08 22:38:454013 !rfhi->is_active() ||
creis36e228b2015-06-08 18:48:024014 ShowingInterstitialPage() || !delegate_ ||
mathiash72a5e462014-11-19 08:18:504015 delegate_->ShouldSuppressDialogs(this) ||
4016 !delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494017 if (suppress_this_message) {
4018 rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true);
4019 return;
4020 }
4021
4022 is_showing_before_unload_dialog_ = true;
mathiash72a5e462014-11-19 08:18:504023 dialog_manager_ = delegate_->GetJavaScriptDialogManager(this);
[email protected]87de04b02014-04-08 22:14:494024 dialog_manager_->RunBeforeUnloadDialog(
avi141dbc1322016-03-11 22:27:424025 this, is_reload,
[email protected]87de04b02014-04-08 22:14:494026 base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this),
[email protected]39f2f9252014-05-03 00:54:014027 render_frame_host->GetProcess()->GetID(),
4028 render_frame_host->GetRoutingID(), reply_msg,
[email protected]6fba26d2014-04-29 09:38:284029 false));
[email protected]87de04b02014-04-08 22:14:494030}
4031
[email protected]a86c0e962013-12-17 17:10:394032WebContents* WebContentsImpl::GetAsWebContents() {
4033 return this;
4034}
4035
[email protected]7912e822014-04-16 02:37:034036bool WebContentsImpl::IsNeverVisible() {
4037 if (!delegate_)
4038 return false;
4039 return delegate_->IsNeverVisible(this);
4040}
4041
[email protected]5a3bdf52012-05-24 15:12:574042RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() {
4043 return render_view_host_delegate_view_;
[email protected]420ae012009-04-24 05:16:324044}
4045
[email protected]8ff00d72012-10-23 19:12:214046RendererPreferences WebContentsImpl::GetRendererPrefs(
4047 BrowserContext* browser_context) const {
[email protected]840b1512009-07-21 16:53:464048 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:514049}
4050
avic3aa8422015-11-09 20:57:224051gfx::Rect WebContentsImpl::GetRootWindowResizerRect(
4052 RenderWidgetHostImpl* render_widget_host) const {
4053 if (!RenderViewHostImpl::From(render_widget_host))
4054 return gfx::Rect();
4055
[email protected]b7a756d42012-01-23 18:08:174056 if (delegate_)
4057 return delegate_->GetRootWindowResizerRect();
4058 return gfx::Rect();
4059}
4060
[email protected]7a846df2012-09-20 19:17:394061void WebContentsImpl::RemoveBrowserPluginEmbedder() {
[email protected]59383c782013-04-17 16:43:274062 if (browser_plugin_embedder_)
[email protected]7a846df2012-09-20 19:17:394063 browser_plugin_embedder_.reset();
4064}
4065
[email protected]b172aee2012-04-10 17:05:264066void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]14392a52012-05-02 20:28:444067 // Don't send notifications if we are just creating a swapped-out RVH for
4068 // the opener chain. These won't be used for view-source or WebUI, so it's
4069 // ok to return early.
creiscce56cd2014-09-29 22:45:224070 if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active())
[email protected]14392a52012-05-02 20:28:444071 return;
4072
[email protected]86f98a22013-03-20 14:35:004073 if (delegate_)
[email protected]e85165c642014-06-10 14:34:314074 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]a6b73c62013-02-11 23:05:084075
[email protected]8ff00d72012-10-23 19:12:214076 NotificationService::current()->Notify(
4077 NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED,
4078 Source<WebContents>(this),
4079 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:324080
[email protected]60780f412013-02-25 16:34:104081 view_->RenderViewCreated(render_view_host);
[email protected]11f764bb2011-05-25 19:45:264082
4083 FOR_EACH_OBSERVER(
[email protected]d8c660432011-12-22 20:51:254084 WebContentsObserver, observers_, RenderViewCreated(render_view_host));
[email protected]420ae012009-04-24 05:16:324085}
4086
[email protected]b172aee2012-04-10 17:05:264087void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) {
[email protected]151a63d2011-12-20 22:32:524088 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324089 // Don't notify the world, since this came from a renderer in the
4090 // background.
4091 return;
4092 }
4093
[email protected]da7a7182013-09-06 08:11:114094 notify_disconnection_ = true;
4095 // TODO(avi): Remove. http://crbug.com/170921
4096 NotificationService::current()->Notify(
4097 NOTIFICATION_WEB_CONTENTS_CONNECTED,
4098 Source<WebContents>(this),
4099 NotificationService::NoDetails());
4100
[email protected]be1f56ab2011-12-22 06:55:314101 bool was_crashed = IsCrashed();
[email protected]443b80e2010-12-14 00:42:234102 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:304103
4104 // Restore the focus to the tab (otherwise the focus will be on the top
4105 // window).
[email protected]484ae5912010-09-29 19:16:144106 if (was_crashed && !FocusLocationBarByDefault() &&
4107 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]f3615f02013-02-26 06:09:064108 view_->Focus();
[email protected]484ae5912010-09-29 19:16:144109 }
[email protected]32ded2212011-11-10 18:51:434110
[email protected]d8c660432011-12-22 20:51:254111 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady());
[email protected]420ae012009-04-24 05:16:324112}
4113
[email protected]ec6a7eb2013-04-22 17:34:224114void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh,
4115 base::TerminationStatus status,
4116 int error_code) {
[email protected]151a63d2011-12-20 22:32:524117 if (rvh != GetRenderViewHost()) {
[email protected]420ae012009-04-24 05:16:324118 // The pending page's RenderViewHost is gone.
4119 return;
4120 }
4121
[email protected]2fcdcc32014-03-05 02:14:074122 // Ensure fullscreen mode is exited in the |delegate_| since a crashed
4123 // renderer may not have made a clean exit.
avibf58fa0c2015-11-11 01:45:524124 if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget()))
bokanece34a82016-01-28 19:49:464125 ExitFullscreenMode(false);
[email protected]2fcdcc32014-03-05 02:14:074126
[email protected]698191dc2014-02-25 01:06:134127 // Cancel any visible dialogs so they are not left dangling over the sad tab.
creis89a0f782015-05-27 16:13:174128 CancelActiveAndPendingDialogs();
[email protected]698191dc2014-02-25 01:06:134129
[email protected]f738bdcb2014-07-11 20:40:444130 if (delegate_)
4131 delegate_->HideValidationMessage(this);
4132
[email protected]960b0372014-05-19 18:01:004133 // Reset the loading progress. TODO(avi): What does it mean to have a
4134 // "renderer crash" when there is more than one renderer process serving a
4135 // webpage? Once this function is called at a more granular frame level, we
4136 // probably will need to more granularly reset the state here.
4137 ResetLoadProgressState();
clamy44e84ce2016-02-22 15:38:254138 NotifyDisconnected();
4139 SetIsCrashed(status, error_code);
[email protected]960b0372014-05-19 18:01:004140
[email protected]d8c660432011-12-22 20:51:254141 FOR_EACH_OBSERVER(WebContentsObserver,
[email protected]9cddb1a22011-11-15 15:04:274142 observers_,
[email protected]58d5cfe2013-07-10 02:40:524143 RenderProcessGone(GetCrashedStatus()));
[email protected]420ae012009-04-24 05:16:324144}
4145
[email protected]b172aee2012-04-10 17:05:264146void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]d8c660432011-12-22 20:51:254147 FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh));
[email protected]2e4633c2009-07-09 16:58:064148}
4149
[email protected]b172aee2012-04-10 17:05:264150void WebContentsImpl::UpdateState(RenderViewHost* rvh,
avib7348942015-12-25 20:57:104151 int32_t page_id,
[email protected]691aa2f2013-05-28 22:52:044152 const PageState& page_state) {
creis8eb8ef22015-11-04 22:51:384153 DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries());
4154
creise1d3e5b2014-12-01 18:21:574155 // Ensure that this state update comes from a RenderViewHost that belongs to
4156 // this WebContents.
[email protected]94d0cc12013-12-18 00:07:414157 // TODO(nasko): This should go through RenderFrameHost.
creise1d3e5b2014-12-01 18:21:574158 if (rvh->GetDelegate()->GetAsWebContents() != this)
[email protected]94d0cc12013-12-18 00:07:414159 return;
[email protected]420ae012009-04-24 05:16:324160
avi286019ce2015-07-29 01:26:584161 // We must be prepared to handle state updates for any page. They occur
[email protected]420ae012009-04-24 05:16:324162 // when the user is scrolling and entering form data, as well as when we're
4163 // leaving a page, in which case our state may have already been moved to
4164 // the next page. The navigation controller will look up the appropriate
4165 // NavigationEntry and update it when it is notified via the delegate.
avi286019ce2015-07-29 01:26:584166 RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh);
avi47179332015-05-20 21:01:114167 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584168 rvhi->GetSiteInstance(), page_id);
avi47179332015-05-20 21:01:114169 if (!entry)
[email protected]420ae012009-04-24 05:16:324170 return;
[email protected]420ae012009-04-24 05:16:324171
nasko346969912015-12-16 22:36:474172 // Sanity check that ensures nav_entry_id and page_id point to the same
4173 // navigation entry.
4174 if (rvhi->GetMainFrame()) {
4175 NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID(
4176 static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame())
4177 ->nav_entry_id());
creisd63f6c4a2015-11-06 19:05:534178
nasko346969912015-12-16 22:36:474179 DCHECK_EQ(entry, new_entry);
4180 }
creisd63f6c4a2015-11-06 19:05:534181
[email protected]691aa2f2013-05-28 22:52:044182 if (page_state == entry->GetPageState())
[email protected]420ae012009-04-24 05:16:324183 return; // Nothing to update.
[email protected]691aa2f2013-05-28 22:52:044184 entry->SetPageState(page_state);
avi47179332015-05-20 21:01:114185 controller_.NotifyEntryChanged(entry);
[email protected]420ae012009-04-24 05:16:324186}
4187
sky8b00392d2015-01-10 00:30:284188void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host,
4189 const GURL& url) {
4190 if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) {
4191 // If we're fullscreen only update the url if it's from the fullscreen
4192 // renderer.
4193 RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView();
avif9ab5d942015-10-15 14:05:444194 if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget())
sky8b00392d2015-01-10 00:30:284195 return;
4196 }
[email protected]6934a702011-12-20 00:04:514197 if (delegate_)
avi450ce00e2014-09-24 01:58:524198 delegate_->UpdateTargetURL(this, url);
[email protected]420ae012009-04-24 05:16:324199}
4200
[email protected]b172aee2012-04-10 17:05:264201void WebContentsImpl::Close(RenderViewHost* rvh) {
[email protected]60780f412013-02-25 16:34:104202#if defined(OS_MACOSX)
[email protected]07707302009-11-06 00:50:294203 // The UI may be in an event-tracking loop, such as between the
4204 // mouse-down and mouse-up in text selection or a button click.
4205 // Defer the close until after tracking is complete, so that we
4206 // don't free objects out from under the UI.
[email protected]07707302009-11-06 00:50:294207 // TODO(shess): This could get more fine-grained. For instance,
4208 // closing a tab in another window while selecting text in the
4209 // current window's Omnibox should be just fine.
[email protected]60780f412013-02-25 16:34:104210 if (view_->IsEventTracking()) {
4211 view_->CloseTabAfterEventTracking();
[email protected]07707302009-11-06 00:50:294212 return;
4213 }
[email protected]60780f412013-02-25 16:34:104214#endif
[email protected]07707302009-11-06 00:50:294215
[email protected]420ae012009-04-24 05:16:324216 // Ignore this if it comes from a RenderViewHost that we aren't showing.
[email protected]151a63d2011-12-20 22:32:524217 if (delegate_ && rvh == GetRenderViewHost())
[email protected]6934a702011-12-20 00:04:514218 delegate_->CloseContents(this);
[email protected]420ae012009-04-24 05:16:324219}
4220
[email protected]66bbadaf2014-03-28 16:25:544221void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) {
[email protected]0d0f4c492014-04-02 06:42:574222 if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost())
4223 delegate_->SwappedOut(this);
[email protected]cd9ed79d2011-11-15 19:22:574224}
4225
[email protected]b172aee2012-04-10 17:05:264226void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) {
[email protected]6934a702011-12-20 00:04:514227 if (delegate_ && delegate_->IsPopupOrPanel(this))
4228 delegate_->MoveContents(this, new_bounds);
[email protected]420ae012009-04-24 05:16:324229}
4230
fdegansa696e5112015-04-17 01:57:594231void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node,
[email protected]e3b10d12014-03-28 16:06:094232 bool to_different_document) {
clamy44e84ce2016-02-22 15:38:254233 LoadingStateChanged(to_different_document, false, nullptr);
dmazzonibf8cec42015-02-08 08:28:084234
4235 // Notify accessibility that the user is navigating away from the
4236 // current document.
4237 //
4238 // TODO(dmazzoni): do this using a WebContentsObserver.
dmazzonibf8cec42015-02-08 08:28:084239 BrowserAccessibilityManager* manager =
fdegansa696e5112015-04-17 01:57:594240 frame_tree_node->current_frame_host()->browser_accessibility_manager();
dmazzonibf8cec42015-02-08 08:28:084241 if (manager)
4242 manager->UserIsNavigatingAway();
[email protected]420ae012009-04-24 05:16:324243}
4244
fdegansc73eec22015-03-19 14:47:544245void WebContentsImpl::DidStopLoading() {
dcheng59716272016-04-09 05:19:084246 std::unique_ptr<LoadNotificationDetails> details;
[email protected]420ae012009-04-24 05:16:324247
[email protected]9595fd82013-04-19 21:28:494248 // Use the last committed entry rather than the active one, in case a
4249 // pending entry has been created.
4250 NavigationEntry* entry = controller_.GetLastCommittedEntry();
[email protected]3691e5cf2014-01-22 10:16:204251 Navigator* navigator = frame_tree_.root()->navigator();
[email protected]9595fd82013-04-19 21:28:494252
[email protected]420ae012009-04-24 05:16:324253 // An entry may not exist for a stop when loading an initial blank page or
4254 // if an iframe injected by script into a blank page finishes loading.
4255 if (entry) {
[email protected]3691e5cf2014-01-22 10:16:204256 base::TimeDelta elapsed =
4257 base::TimeTicks::Now() - navigator->GetCurrentLoadStart();
[email protected]420ae012009-04-24 05:16:324258
4259 details.reset(new LoadNotificationDetails(
[email protected]36fc0392011-12-25 03:59:514260 entry->GetVirtualURL(),
4261 entry->GetTransitionType(),
[email protected]420ae012009-04-24 05:16:324262 elapsed,
4263 &controller_,
4264 controller_.GetCurrentEntryIndex()));
4265 }
4266
clamy44e84ce2016-02-22 15:38:254267 LoadingStateChanged(true, false, details.get());
[email protected]420ae012009-04-24 05:16:324268}
4269
fdegansa696e5112015-04-17 01:57:594270void WebContentsImpl::DidChangeLoadProgress() {
4271 double load_progress = frame_tree_.load_progress();
4272
4273 // The delegate is notified immediately for the first and last updates. Also,
4274 // since the message loop may be pretty busy when a page is loaded, it might
4275 // not execute a posted task in a timely manner so the progress report is sent
4276 // immediately if enough time has passed.
4277 base::TimeDelta min_delay =
4278 base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS);
4279 bool delay_elapsed = loading_last_progress_update_.is_null() ||
4280 base::TimeTicks::Now() - loading_last_progress_update_ > min_delay;
4281
4282 if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) {
4283 // If there is a pending task to send progress, it is now obsolete.
4284 loading_weak_factory_.InvalidateWeakPtrs();
4285
4286 // Notify the load progress change.
4287 SendChangeLoadProgress();
4288
4289 // Clean-up the states if needed.
4290 if (load_progress == 1.0)
4291 ResetLoadProgressState();
4292 return;
4293 }
4294
4295 if (loading_weak_factory_.HasWeakPtrs())
4296 return;
4297
skyostil95082a62015-06-05 19:53:074298 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
4299 FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress,
4300 loading_weak_factory_.GetWeakPtr()),
fdegansa696e5112015-04-17 01:57:594301 min_delay);
4302}
4303
[email protected]b172aee2012-04-10 17:05:264304void WebContentsImpl::DidCancelLoading() {
[email protected]c95fa8b2011-04-28 20:26:164305 controller_.DiscardNonCommittedEntries();
4306
4307 // Update the URL display.
[email protected]8ff00d72012-10-23 19:12:214308 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]c95fa8b2011-04-28 20:26:164309}
4310
[email protected]59167c22013-06-03 18:07:324311void WebContentsImpl::DidAccessInitialDocument() {
[email protected]b4c84012014-04-28 19:51:104312 has_accessed_initial_document_ = true;
4313
[email protected]d1371bf8e2014-04-19 03:26:244314 // We may have left a failed browser-initiated navigation in the address bar
4315 // to let the user edit it and try again. Clear it now that content might
4316 // show up underneath it.
4317 if (!IsLoading() && controller_.GetPendingEntry())
avi45a72532015-04-07 21:01:454318 controller_.DiscardPendingEntry(false);
[email protected]d1371bf8e2014-04-19 03:26:244319
[email protected]59167c22013-06-03 18:07:324320 // Update the URL display.
thestigc4cac8f2014-09-04 21:17:504321 NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
[email protected]59167c22013-06-03 18:07:324322}
4323
alexmosbe2f4c32015-03-10 02:30:234324void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host,
4325 const std::string& name) {
4326 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4327 FrameNameChanged(render_frame_host, name));
4328}
4329
[email protected]39f2f9252014-05-03 00:54:014330void WebContentsImpl::DocumentOnLoadCompleted(
[email protected]50279492014-05-05 23:24:294331 RenderFrameHost* render_frame_host) {
[email protected]6578fef2013-10-14 02:35:094332 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
[email protected]50279492014-05-05 23:24:294333 DocumentOnLoadCompletedInMainFrame());
[email protected]6578fef2013-10-14 02:35:094334
4335 // TODO(avi): Remove. http://crbug.com/170921
[email protected]8ff00d72012-10-23 19:12:214336 NotificationService::current()->Notify(
4337 NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
4338 Source<WebContents>(this),
[email protected]50279492014-05-05 23:24:294339 NotificationService::NoDetails());
[email protected]25497492010-09-11 15:15:084340}
4341
creis8eb8ef22015-11-04 22:51:384342void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host,
4343 const PageState& page_state) {
4344 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
4345
4346 // The state update affects the last NavigationEntry associated with the given
4347 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4348 // in the case of an UpdateState from a frame being swapped out). We track
4349 // which entry this is in the RenderFrameHost's nav_entry_id.
4350 RenderFrameHostImpl* rfhi =
4351 static_cast<RenderFrameHostImpl*>(render_frame_host);
4352 NavigationEntryImpl* entry =
4353 controller_.GetEntryWithUniqueID(rfhi->nav_entry_id());
4354 if (!entry)
4355 return;
4356
4357 FrameNavigationEntry* frame_entry =
4358 entry->GetFrameEntry(rfhi->frame_tree_node());
4359 if (!frame_entry)
4360 return;
4361
creisd06a9422015-11-11 03:08:454362 // The SiteInstance might not match if we do a cross-process navigation with
4363 // replacement (e.g., auto-subframe), in which case the swap out of the old
4364 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4365 // has already been replaced and destroyed.
4366 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4367 return;
4368
creis8eb8ef22015-11-04 22:51:384369 if (page_state == frame_entry->page_state())
4370 return; // Nothing to update.
4371
4372 frame_entry->set_page_state(page_state);
4373 controller_.NotifyEntryChanged(entry);
4374}
4375
[email protected]ef3adfc2014-05-11 00:04:544376void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host,
avib7348942015-12-25 20:57:104377 int32_t page_id,
[email protected]ef3adfc2014-05-11 00:04:544378 const base::string16& title,
4379 base::i18n::TextDirection title_direction) {
[email protected]ef3adfc2014-05-11 00:04:544380 // If we have a title, that's a pretty good indication that we've started
4381 // getting useful data.
4382 SetNotWaitingForResponse();
4383
4384 // Try to find the navigation entry, which might not be the current one.
avi286019ce2015-07-29 01:26:584385 // For example, it might be from a recently swapped out RFH.
[email protected]ef3adfc2014-05-11 00:04:544386 NavigationEntryImpl* entry = controller_.GetEntryWithPageID(
avi286019ce2015-07-29 01:26:584387 render_frame_host->GetSiteInstance(), page_id);
4388
creis081bc102016-02-26 00:56:274389 // TODO(creis): Find a way to use nav entry IDs to locate the entry to update,
4390 // and intentionally skip updates when the most recent commit was ignored.
4391 // See https://crbug.com/577449.
[email protected]ef3adfc2014-05-11 00:04:544392
4393 // We can handle title updates when we don't have an entry in
4394 // UpdateTitleForEntry, but only if the update is from the current RVH.
4395 // TODO(avi): Change to make decisions based on the RenderFrameHost.
avi286019ce2015-07-29 01:26:584396 if (!entry && render_frame_host != GetMainFrame())
[email protected]ef3adfc2014-05-11 00:04:544397 return;
4398
4399 // TODO(evan): make use of title_direction.
4400 // http://code.google.com/p/chromium/issues/detail?id=27094
4401 if (!UpdateTitleForEntry(entry, title))
4402 return;
4403
4404 // Broadcast notifications when the UI should be updated.
4405 if (entry == controller_.GetEntryAtOffset(0))
4406 NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE);
4407}
4408
4409void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host,
4410 const std::string& encoding) {
4411 SetEncoding(encoding);
4412}
4413
[email protected]39f2f9252014-05-03 00:54:014414void WebContentsImpl::DocumentAvailableInMainFrame(
4415 RenderViewHost* render_view_host) {
4416 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4417 DocumentAvailableInMainFrame());
4418}
naskoc0fceff2015-04-30 15:53:524419
[email protected]e1c3a552012-05-04 20:51:324420void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) {
4421 // Tell the active RenderViewHost to run unload handlers and close, as long
4422 // as the request came from a RenderViewHost in the same BrowsingInstance.
4423 // In most cases, we receive this from a swapped out RenderViewHost.
4424 // It is possible to receive it from one that has just been swapped in,
4425 // in which case we might as well deliver the message anyway.
4426 if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance()))
naskoc0fceff2015-04-30 15:53:524427 ClosePage();
[email protected]e1c3a552012-05-04 20:51:324428}
4429
alexmose7da5a12015-04-09 02:22:164430bool WebContentsImpl::ShouldRouteMessageEvent(
4431 RenderFrameHost* target_rfh,
4432 SiteInstance* source_site_instance) const {
4433 // Allow the message if this WebContents is dedicated to a browser plugin
4434 // guest.
[email protected]0eba810b2012-10-18 03:19:364435 // Note: This check means that an embedder could theoretically receive a
4436 // postMessage from anyone (not just its own guests). However, this is
4437 // probably not a risk for apps since other pages won't have references
4438 // to App windows.
alexmose7da5a12015-04-09 02:22:164439 return GetBrowserPluginGuest() || GetBrowserPluginEmbedder();
4440}
[email protected]f546640b2012-05-15 00:03:494441
alexmos58729042015-06-18 23:20:004442void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {
alexmose7da5a12015-04-09 02:22:164443 WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>(
4444 WebContents::FromRenderFrameHost(source_rfh));
[email protected]f546640b2012-05-15 00:03:494445
alexmose7da5a12015-04-09 02:22:164446 if (source_web_contents) {
lazyboy6ec48b2a2015-06-29 15:18:144447 // If this message is going to outer WebContents from inner WebContents,
4448 // then we should not create a RenderView. AttachToOuterWebContentsFrame()
4449 // already created a RenderFrameProxyHost for that purpose.
4450 if (GetBrowserPluginEmbedder() &&
nickd30fd962015-07-27 21:51:084451 BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
lazyboy6ec48b2a2015-06-29 15:18:144452 return;
4453 }
4454
lfg812874d2016-02-09 22:26:134455 if (this != source_web_contents && GetBrowserPluginGuest()) {
naskob3041b98a42016-03-12 04:43:064456 // We create a RenderFrameProxyHost for the embedder in the guest's render
4457 // process but we intentionally do not expose the embedder's opener chain
4458 // to it.
4459 source_web_contents->GetRenderManager()->CreateRenderFrameProxy(
4460 GetSiteInstance());
[email protected]f546640b2012-05-15 00:03:494461 } else {
alexmos58729042015-06-18 23:20:004462 RenderFrameHostImpl* source_rfhi =
4463 static_cast<RenderFrameHostImpl*>(source_rfh);
4464 source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies(
alexmos90325cf2015-09-02 17:18:394465 GetSiteInstance(), nullptr);
[email protected]f546640b2012-05-15 00:03:494466 }
4467 }
[email protected]f546640b2012-05-15 00:03:494468}
4469
avib7348942015-12-25 20:57:104470bool WebContentsImpl::AddMessageToConsole(int32_t level,
[email protected]fcf75d42013-12-03 20:11:264471 const base::string16& message,
avib7348942015-12-25 20:57:104472 int32_t line_no,
[email protected]fcf75d42013-12-03 20:11:264473 const base::string16& source_id) {
[email protected]a796f202012-05-30 14:14:254474 if (!delegate_)
4475 return false;
4476 return delegate_->AddMessageToConsole(this, level, message, line_no,
4477 source_id);
4478}
4479
dominickn9c7ceaa32016-02-27 01:52:534480void WebContentsImpl::OnUserInteraction(
4481 RenderWidgetHostImpl* render_widget_host,
4482 const blink::WebInputEvent::Type type) {
4483 // Ignore when the renderer is swapped out.
4484 // TODO(dominickn,creis): support widgets for out-of-process iframes.
avic3aa8422015-11-09 20:57:224485 if (render_widget_host != GetRenderViewHost()->GetWidget())
4486 return;
4487
dominickn2dd142dd2015-10-29 05:30:504488 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4489 DidGetUserInteraction(type));
dominickn9c7ceaa32016-02-27 01:52:534490
4491 ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get();
4492 // Exclude scroll events as user gestures for resource load dispatches.
4493 // rdh is NULL in unittests.
4494 if (rdh && type != blink::WebInputEvent::MouseWheel)
4495 rdh->OnUserGesture(this);
dominickn2dd142dd2015-10-29 05:30:504496}
4497
[email protected]b172aee2012-04-10 17:05:264498void WebContentsImpl::OnIgnoredUIEvent() {
[email protected]31145092011-09-30 01:49:444499 // Notify observers.
[email protected]d8c660432011-12-22 20:51:254500 FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent());
[email protected]fa1cf0b82010-01-15 21:49:444501}
4502
avic3aa8422015-11-09 20:57:224503void WebContentsImpl::RendererUnresponsive(
4504 RenderWidgetHostImpl* render_widget_host) {
afakhry98241832016-03-11 19:27:474505 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4506 OnRendererUnresponsive(render_widget_host));
4507
[email protected]992db4c2011-05-12 15:37:154508 // Don't show hung renderer dialog for a swapped out RVH.
avic3aa8422015-11-09 20:57:224509 if (render_widget_host != GetRenderViewHost()->GetWidget())
[email protected]992db4c2011-05-12 15:37:154510 return;
4511
creiscce56cd2014-09-29 22:45:224512 RenderFrameHostImpl* rfhi =
avic3aa8422015-11-09 20:57:224513 static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame());
[email protected]9f76c1e2012-03-05 15:15:584514
[email protected]e5fc1632011-08-08 07:51:534515 // Ignore renderer unresponsive event if debugger is attached to the tab
4516 // since the event may be a result of the renderer sitting on a breakpoint.
4517 // See http://crbug.com/65458
[email protected]98f66112012-12-25 12:59:364518 if (DevToolsAgentHost::IsDebuggerAttached(this))
[email protected]e5fc1632011-08-08 07:51:534519 return;
4520
clamy226727e2015-06-29 10:28:474521 if (rfhi->is_waiting_for_beforeunload_ack() ||
creiscce56cd2014-09-29 22:45:224522 rfhi->IsWaitingForUnloadACK()) {
[email protected]420ae012009-04-24 05:16:324523 // Hang occurred while firing the beforeunload/unload handler.
4524 // Pretend the handler fired so tab closing continues as if it had.
avic3aa8422015-11-09 20:57:224525 GetRenderViewHost()->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:324526
[email protected]fa944cb82013-11-15 17:51:214527 if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer())
[email protected]420ae012009-04-24 05:16:324528 return;
4529
4530 // If the tab hangs in the beforeunload/unload handler there's really
[email protected]2e9d79f2013-08-16 05:45:564531 // nothing we can do to recover. If the hang is in the beforeunload handler,
4532 // pretend the beforeunload listeners have all fired and allow the delegate
4533 // to continue closing; the user will not have the option of cancelling the
4534 // close. Otherwise, pretend the unload listeners have all fired and close
4535 // the tab.
4536 bool close = true;
clamy226727e2015-06-29 10:28:474537 if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) {
[email protected]2e9d79f2013-08-16 05:45:564538 delegate_->BeforeUnloadFired(this, true, &close);
4539 }
4540 if (close)
avic3aa8422015-11-09 20:57:224541 Close();
[email protected]420ae012009-04-24 05:16:324542 return;
4543 }
4544
creisc014b402015-04-23 16:41:454545 if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive())
[email protected]55452902011-06-01 21:57:474546 return;
4547
[email protected]6934a702011-12-20 00:04:514548 if (delegate_)
4549 delegate_->RendererUnresponsive(this);
[email protected]420ae012009-04-24 05:16:324550}
4551
avic3aa8422015-11-09 20:57:224552void WebContentsImpl::RendererResponsive(
4553 RenderWidgetHostImpl* render_widget_host) {
4554 if (render_widget_host != GetRenderViewHost()->GetWidget())
4555 return;
4556
[email protected]6934a702011-12-20 00:04:514557 if (delegate_)
4558 delegate_->RendererResponsive(this);
[email protected]420ae012009-04-24 05:16:324559}
4560
[email protected]b172aee2012-04-10 17:05:264561void WebContentsImpl::LoadStateChanged(
4562 const GURL& url,
4563 const net::LoadStateWithParam& load_state,
avib7348942015-12-25 20:57:104564 uint64_t upload_position,
4565 uint64_t upload_size) {
erikchen174b78c62015-03-11 22:02:544566 // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285
4567 // is fixed.
4568 tracked_objects::ScopedTracker tracking_profile1(
4569 FROM_HERE_WITH_EXPLICIT_FUNCTION(
4570 "466285 WebContentsImpl::LoadStateChanged::Start"));
[email protected]420ae012009-04-24 05:16:324571 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:564572 upload_position_ = upload_position;
4573 upload_size_ = upload_size;
jshin1fb76462016-04-05 22:13:034574 load_state_host_ = url_formatter::IDNToUnicode(url.host());
[email protected]9c235f042011-08-10 22:28:214575 if (load_state_.state == net::LOAD_STATE_READING_RESPONSE)
[email protected]420ae012009-04-24 05:16:324576 SetNotWaitingForResponse();
[email protected]d9083482012-01-06 00:38:464577 if (IsLoading()) {
[email protected]7f924832014-08-09 05:57:224578 NotifyNavigationStateChanged(static_cast<InvalidateTypes>(
4579 INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB));
[email protected]d9083482012-01-06 00:38:464580 }
[email protected]420ae012009-04-24 05:16:324581}
4582
[email protected]b172aee2012-04-10 17:05:264583void WebContentsImpl::BeforeUnloadFiredFromRenderManager(
[email protected]feaded02012-09-25 19:12:554584 bool proceed, const base::TimeTicks& proceed_time,
[email protected]420ae012009-04-24 05:16:324585 bool* proceed_to_fire_unload) {
[email protected]6d65a462013-06-21 21:29:124586 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4587 BeforeUnloadFired(proceed_time));
[email protected]6934a702011-12-20 00:04:514588 if (delegate_)
4589 delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
[email protected]e80af492013-06-24 21:52:094590 // Note: |this| might be deleted at this point.
[email protected]420ae012009-04-24 05:16:324591}
4592
[email protected]58d5cfe2013-07-10 02:40:524593void WebContentsImpl::RenderProcessGoneFromRenderManager(
[email protected]3a3d47472010-07-15 21:03:544594 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:234595 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
[email protected]ec6a7eb2013-04-22 17:34:224596 RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:544597}
4598
[email protected]b172aee2012-04-10 17:05:264599void WebContentsImpl::UpdateRenderViewSizeForRenderManager() {
[email protected]8643e6d2012-01-18 20:26:104600 // TODO(brettw) this is a hack. See WebContentsView::SizeContents.
[email protected]dc0fd432013-08-27 15:29:214601 gfx::Size size = GetSizeForNewRenderView();
[email protected]0323ee42010-02-17 22:03:264602 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
4603 // here during container initialization and normal window size will be set
4604 // later. In case of tab duplication this resizing to 0x0 prevents setting
4605 // normal size later so just ignore it.
4606 if (!size.IsEmpty())
4607 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:324608}
4609
[email protected]af905902013-10-01 21:38:514610void WebContentsImpl::CancelModalDialogsForRenderManager() {
4611 // We need to cancel modal dialogs when doing a process swap, since the load
avi2460c762015-04-17 15:21:544612 // deferrer would prevent us from swapping out. We also clear the state
4613 // because this is a cross-process navigation, which means that it's a new
4614 // site that should not have to pay for the sins of its predecessor.
creis89a0f782015-05-27 16:13:174615 //
4616 // Note that we don't bother telling browser_plugin_embedder_ because the
4617 // cross-process navigation will either destroy the browser plugins or not
4618 // require their dialogs to close.
[email protected]af905902013-10-01 21:38:514619 if (dialog_manager_)
avi2460c762015-04-17 15:21:544620 dialog_manager_->ResetDialogState(this);
[email protected]af905902013-10-01 21:38:514621}
4622
[email protected]02d7b6e2014-06-24 21:01:504623void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host,
4624 RenderFrameHost* new_host,
4625 bool is_main_frame) {
4626 if (is_main_frame) {
naskof5940b9f2015-03-02 23:04:054627 NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr,
[email protected]02d7b6e2014-06-24 21:01:504628 new_host->GetRenderViewHost());
[email protected]a6b73c62013-02-11 23:05:084629
[email protected]02d7b6e2014-06-24 21:01:504630 // Make sure the visible RVH reflects the new delegate's preferences.
4631 if (delegate_)
4632 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
[email protected]d56a49e2013-02-23 00:47:394633
[email protected]02d7b6e2014-06-24 21:01:504634 view_->RenderViewSwappedIn(new_host->GetRenderViewHost());
4635 }
4636
4637 NotifyFrameSwapped(old_host, new_host);
[email protected]3a3d47472010-07-15 21:03:544638}
4639
naskof5940b9f2015-03-02 23:04:054640void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager(
4641 RenderViewHost* old_host,
4642 RenderViewHost* new_host) {
4643 NotifyViewSwapped(old_host, new_host);
4644}
4645
[email protected]b172aee2012-04-10 17:05:264646NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() {
[email protected]d1198fd2012-08-13 22:50:194647 return GetController();
[email protected]3a3d47472010-07-15 21:03:544648}
4649
dcheng59716272016-04-09 05:19:084650std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost(
carlosk37f793792014-11-27 15:08:294651 const GURL& url) {
dcheng59716272016-04-09 05:19:084652 return std::unique_ptr<WebUIImpl>(
4653 static_cast<WebUIImpl*>(CreateWebUI(url, std::string())));
[email protected]420ae012009-04-24 05:16:324654}
4655
[email protected]10f417c52011-12-28 21:04:234656NavigationEntry*
[email protected]b172aee2012-04-10 17:05:264657 WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() {
[email protected]420ae012009-04-24 05:16:324658 return controller_.GetLastCommittedEntry();
4659}
4660
lfgbede6392015-09-11 21:54:064661void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager(
4662 RenderViewHost* render_view_host) {
lfgc740d4b22016-04-15 16:45:334663 RenderWidgetHostViewBase* rwh_view =
4664 view_->CreateViewForWidget(render_view_host->GetWidget(), false);
[email protected]1a98a932009-11-17 00:12:524665
[email protected]420ae012009-04-24 05:16:324666 // Now that the RenderView has been created, we need to tell it its size.
[email protected]245f7d52011-11-28 15:36:444667 if (rwh_view)
[email protected]dc0fd432013-08-27 15:29:214668 rwh_view->SetSize(GetSizeForNewRenderView());
lfgbede6392015-09-11 21:54:064669}
4670
4671bool WebContentsImpl::CreateRenderViewForRenderManager(
4672 RenderViewHost* render_view_host,
4673 int opener_frame_routing_id,
4674 int proxy_routing_id,
4675 const FrameReplicationState& replicated_frame_state) {
4676 TRACE_EVENT0("browser,navigation",
4677 "WebContentsImpl::CreateRenderViewForRenderManager");
4678
4679 if (proxy_routing_id == MSG_ROUTING_NONE)
4680 CreateRenderWidgetHostViewForRenderManager(render_view_host);
[email protected]420ae012009-04-24 05:16:324681
[email protected]74ce1ad2011-12-16 21:51:464682 // Make sure we use the correct starting page_id in the new RenderView.
4683 UpdateMaxPageIDIfNecessary(render_view_host);
avib7348942015-12-25 20:57:104684 int32_t max_page_id =
[email protected]9f76c1e2012-03-05 15:15:584685 GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance());
[email protected]74ce1ad2011-12-16 21:51:464686
alexmos5ac402d2015-07-09 07:51:104687 if (!static_cast<RenderViewHostImpl*>(render_view_host)
4688 ->CreateRenderView(opener_frame_routing_id, proxy_routing_id,
4689 max_page_id, replicated_frame_state,
4690 created_with_opener_)) {
[email protected]a4127722011-04-27 23:13:524691 return false;
[email protected]14392a52012-05-02 20:28:444692 }
[email protected]a4127722011-04-27 23:13:524693
avi2b177592014-12-10 02:08:024694 SetHistoryOffsetAndLengthForView(render_view_host,
4695 controller_.GetLastCommittedEntryIndex(),
4696 controller_.GetEntryCount());
4697
[email protected]a220b5932013-09-21 03:47:444698#if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
[email protected]f8233cc2011-05-31 20:24:504699 // Force a ViewMsg_Resize to be sent, needed to make plugins show up on
4700 // linux. See crbug.com/83941.
avif9ab5d942015-10-15 14:05:444701 RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView();
[email protected]245f7d52011-11-28 15:36:444702 if (rwh_view) {
4703 if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost())
4704 render_widget_host->WasResized();
4705 }
[email protected]f8233cc2011-05-31 20:24:504706#endif
4707
[email protected]420ae012009-04-24 05:16:324708 return true;
4709}
4710
[email protected]82307f6b2014-08-07 03:30:124711bool WebContentsImpl::CreateRenderFrameForRenderManager(
4712 RenderFrameHost* render_frame_host,
alexmosa181efc2015-09-03 00:39:044713 int proxy_routing_id,
4714 int opener_routing_id,
japhete6adf142014-10-31 00:01:494715 int parent_routing_id,
alexmosa181efc2015-09-03 00:39:044716 int previous_sibling_routing_id) {
naskob8744d22014-08-28 17:07:434717 TRACE_EVENT0("browser,navigation",
4718 "WebContentsImpl::CreateRenderFrameForRenderManager");
[email protected]82307f6b2014-08-07 03:30:124719
4720 RenderFrameHostImpl* rfh =
4721 static_cast<RenderFrameHostImpl*>(render_frame_host);
alexmosa181efc2015-09-03 00:39:044722 if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id,
4723 parent_routing_id, previous_sibling_routing_id))
[email protected]82307f6b2014-08-07 03:30:124724 return false;
4725
4726 // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed
4727 // RenderFrameHost will have to be associated with the appropriate
4728 // RenderWidgetHostView or a new one should be created here.
4729
4730 return true;
4731}
4732
mfomitchev2b8b066a2016-01-28 19:23:154733#if defined(OS_ANDROID)
[email protected]fc2b46b2014-05-03 16:33:454734
[email protected]155c7f22013-12-09 17:07:184735base::android::ScopedJavaLocalRef<jobject>
4736WebContentsImpl::GetJavaWebContents() {
mostynb042582e2015-03-16 22:13:404737 DCHECK_CURRENTLY_ON(BrowserThread::UI);
[email protected]0e813a52014-08-13 10:34:564738 return GetWebContentsAndroid()->GetJavaObject();
4739}
[email protected]155c7f22013-12-09 17:07:184740
[email protected]0e813a52014-08-13 10:34:564741WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() {
[email protected]155c7f22013-12-09 17:07:184742 WebContentsAndroid* web_contents_android =
4743 static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey));
4744 if (!web_contents_android) {
4745 web_contents_android = new WebContentsAndroid(this);
4746 SetUserData(kWebContentsAndroidKey, web_contents_android);
4747 }
[email protected]0e813a52014-08-13 10:34:564748 return web_contents_android;
[email protected]155c7f22013-12-09 17:07:184749}
4750
paulmeyerc0b762b2016-04-13 11:55:174751void WebContentsImpl::ActivateNearestFindResult(float x,
4752 float y) {
4753 GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y);
4754}
4755
4756void WebContentsImpl::RequestFindMatchRects(int current_version) {
4757 GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version);
4758}
4759
[email protected]7d244f12013-08-22 21:41:514760bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() {
nasko4c0feb62015-06-05 18:37:064761 return CreateRenderViewForRenderManager(
4762 GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE,
lfgbede6392015-09-11 21:54:064763 frame_tree_.root()->current_replication_state());
[email protected]7d244f12013-08-22 21:41:514764}
[email protected]fc2b46b2014-05-03 16:33:454765
4766#elif defined(OS_MACOSX)
4767
[email protected]75f4df72014-07-16 22:39:424768void WebContentsImpl::SetAllowOtherViews(bool allow) {
4769 view_->SetAllowOtherViews(allow);
[email protected]fc2b46b2014-05-03 16:33:454770}
4771
[email protected]75f4df72014-07-16 22:39:424772bool WebContentsImpl::GetAllowOtherViews() {
4773 return view_->GetAllowOtherViews();
[email protected]fc2b46b2014-05-03 16:33:454774}
4775
[email protected]7d244f12013-08-22 21:41:514776#endif
4777
pkotwicz75ca8ffd2016-02-16 23:10:194778void WebContentsImpl::OnDidDownloadImage(
4779 const ImageDownloadCallback& callback,
4780 int id,
4781 const GURL& image_url,
leon.hancbc4bc3c2016-02-26 07:08:524782 int32_t http_status_code,
jamescook70246212016-03-25 19:56:044783 mojo::Array<skia::mojom::BitmapPtr> images,
leon.hancbc4bc3c2016-02-26 07:08:524784 mojo::Array<mojo::SizePtr> original_image_sizes) {
4785 const std::vector<SkBitmap> bitmaps = images.To<std::vector<SkBitmap>>();
4786 const std::vector<gfx::Size> sizes =
4787 original_image_sizes.To<std::vector<gfx::Size>>();
pkotwicz75ca8ffd2016-02-16 23:10:194788
leon.hancbc4bc3c2016-02-26 07:08:524789 callback.Run(id, http_status_code, image_url, bitmaps, sizes);
pkotwicz75ca8ffd2016-02-16 23:10:194790}
4791
[email protected]6fba26d2014-04-29 09:38:284792void WebContentsImpl::OnDialogClosed(int render_process_id,
4793 int render_frame_id,
[email protected]b172aee2012-04-10 17:05:264794 IPC::Message* reply_msg,
[email protected]87de04b02014-04-08 22:14:494795 bool dialog_was_suppressed,
[email protected]b172aee2012-04-10 17:05:264796 bool success,
[email protected]fcf75d42013-12-03 20:11:264797 const base::string16& user_input) {
[email protected]6fba26d2014-04-29 09:38:284798 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4799 render_frame_id);
[email protected]87de04b02014-04-08 22:14:494800 last_dialog_suppressed_ = dialog_was_suppressed;
4801
[email protected]beb440c2009-11-06 04:08:544802 if (is_showing_before_unload_dialog_ && !success) {
clamybc6f4152016-04-01 20:14:234803 // It is possible for the current RenderFrameHost to have changed in the
4804 // meantime. Do not reset the navigation state in that case.
4805 if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) {
clamy44e84ce2016-02-22 15:38:254806 rfh->frame_tree_node()->BeforeUnloadCanceled();
clamybc6f4152016-04-01 20:14:234807 controller_.DiscardNonCommittedEntries();
4808 }
[email protected]ec8e8b02013-06-19 04:57:104809
[email protected]6d65a462013-06-21 21:29:124810 FOR_EACH_OBSERVER(WebContentsObserver, observers_,
4811 BeforeUnloadDialogCancelled());
[email protected]beb440c2009-11-06 04:08:544812 }
[email protected]87de04b02014-04-08 22:14:494813
[email protected]beb440c2009-11-06 04:08:544814 is_showing_before_unload_dialog_ = false;
[email protected]6fba26d2014-04-29 09:38:284815 if (rfh) {
4816 rfh->JavaScriptDialogClosed(reply_msg, success, user_input,
4817 dialog_was_suppressed);
4818 } else {
4819 // Don't leak the sync IPC reply if the RFH or process is gone.
4820 delete reply_msg;
4821 }
[email protected]beb440c2009-11-06 04:08:544822}
4823
[email protected]b172aee2012-04-10 17:05:264824void WebContentsImpl::SetEncoding(const std::string& encoding) {
[email protected]ef3adfc2014-05-11 00:04:544825 if (encoding == last_reported_encoding_)
4826 return;
4827 last_reported_encoding_ = encoding;
4828
4829 canonical_encoding_ = GetContentClient()->browser()->
[email protected]763ec4ca2011-04-29 15:48:124830 GetCanonicalEncodingNameByAliasName(encoding);
[email protected]aacd7cc2009-09-02 14:51:104831}
[email protected]f45d2a72010-03-08 23:28:354832
[email protected]1ac10dca2013-08-20 20:47:044833bool WebContentsImpl::IsHidden() {
4834 return capturer_count_ == 0 && !should_normally_be_visible_;
4835}
4836
rob97250742015-12-10 17:45:154837int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() {
lazyboy6ec48b2a2015-06-29 15:18:144838 if (node_ && node_->outer_web_contents())
4839 return node_->outer_contents_frame_tree_node_id();
4840
nick2482a2d2015-12-18 01:39:374841 return FrameTreeNode::kFrameTreeNodeInvalidId;
lazyboy6ec48b2a2015-06-29 15:18:144842}
4843
[email protected]b0936d22013-11-28 06:47:364844RenderFrameHostManager* WebContentsImpl::GetRenderManager() const {
[email protected]fa944cb82013-11-15 17:51:214845 return frame_tree_.root()->render_manager();
4846}
4847
lazyboy8e16ddfd2015-09-28 03:41:564848WebContentsImpl* WebContentsImpl::GetOuterWebContents() {
4849 if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) {
4850 if (node_)
4851 return node_->outer_web_contents();
4852 } else {
4853 if (GetBrowserPluginGuest())
4854 return GetBrowserPluginGuest()->embedder_web_contents();
4855 }
4856 return nullptr;
4857}
4858
[email protected]f8497342013-02-05 22:15:024859BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const {
[email protected]7a846df2012-09-20 19:17:394860 return browser_plugin_guest_.get();
4861}
4862
[email protected]738f57a2013-06-29 21:06:544863void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) {
4864 CHECK(!browser_plugin_guest_);
lazyboy6ec48b2a2015-06-29 15:18:144865 CHECK(guest);
[email protected]738f57a2013-06-29 21:06:544866 browser_plugin_guest_.reset(guest);
4867}
4868
[email protected]f8497342013-02-05 22:15:024869BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const {
[email protected]7a846df2012-09-20 19:17:394870 return browser_plugin_embedder_.get();
4871}
[email protected]8ff00d72012-10-23 19:12:214872
fsamuel60b42282015-03-10 03:29:144873void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() {
4874 if (browser_plugin_embedder_)
4875 return;
4876 browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this));
4877}
4878
[email protected]fc2b46b2014-05-03 16:33:454879gfx::Size WebContentsImpl::GetSizeForNewRenderView() {
[email protected]dc0fd432013-08-27 15:29:214880 gfx::Size size;
4881 if (delegate_)
4882 size = delegate_->GetSizeForNewRenderView(this);
4883 if (size.IsEmpty())
[email protected]fc2b46b2014-05-03 16:33:454884 size = GetContainerBounds().size();
[email protected]dc0fd432013-08-27 15:29:214885 return size;
4886}
4887
[email protected]ae7eeda2014-07-04 01:53:264888void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) {
4889 FOR_EACH_OBSERVER(
nasko005282522015-01-22 02:30:024890 WebContentsObserver, observers_, FrameDeleted(render_frame_host));
[email protected]9b159a52013-10-03 17:24:554891}
4892
[email protected]222f5822014-02-05 23:40:494893void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) {
4894 if (!delegate_)
4895 return;
4896 const gfx::Size new_size = GetPreferredSize();
4897 if (new_size != old_size)
4898 delegate_->UpdatePreferredSize(this, new_size);
4899}
4900
dbeama1b926a2015-08-31 23:17:514901WebUI* WebContentsImpl::CreateWebUI(const GURL& url,
4902 const std::string& frame_name) {
4903 WebUIImpl* web_ui = new WebUIImpl(this, frame_name);
4904 WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()->
4905 CreateWebUIControllerForURL(web_ui, url);
4906 if (controller) {
4907 web_ui->AddMessageHandler(new GenericHandler());
4908 web_ui->SetController(controller);
4909 return web_ui;
4910 }
4911
4912 delete web_ui;
4913 return NULL;
4914}
4915
paulmeyerc0b762b2016-04-13 11:55:174916FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() {
4917 // TODO(paulmeyer): This method will need to access (or potentially create)
4918 // the FindRequestManager in the outermost WebContents once find-in-page
4919 // across GuestViews is implemented.
4920 if (!find_request_manager_)
4921 find_request_manager_.reset(new FindRequestManager(this));
4922
4923 return find_request_manager_.get();
4924}
4925
4926void WebContentsImpl::NotifyFindReply(int request_id,
4927 int number_of_matches,
4928 const gfx::Rect& selection_rect,
4929 int active_match_ordinal,
4930 bool final_update) {
4931 if (delegate_) {
4932 delegate_->FindReply(this, request_id, number_of_matches, selection_rect,
4933 active_match_ordinal, final_update);
4934 }
4935}
4936
4937#if defined(OS_ANDROID)
4938void WebContentsImpl::NotifyFindMatchRectsReply(
4939 int version,
4940 const std::vector<gfx::RectF>& rects,
4941 const gfx::RectF& active_rect) {
4942 if (delegate_)
4943 delegate_->FindMatchRectsReply(this, version, rects, active_rect);
4944}
4945#endif
4946
[email protected]34ff1cfc2014-08-20 06:16:054947void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) {
4948 force_disable_overscroll_content_ = force_disable;
4949 if (view_)
4950 view_->SetOverscrollControllerEnabled(CanOverscrollContent());
4951}
4952
dalecurtis88c240072015-12-09 02:11:184953void WebContentsImpl::MediaStartedPlaying(
4954 const WebContentsObserver::MediaPlayerId& id) {
4955 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4956}
4957
4958void WebContentsImpl::MediaStoppedPlaying(
4959 const WebContentsObserver::MediaPlayerId& id) {
4960 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4961}
4962
tapted65ff2ea72016-03-01 23:39:004963void WebContentsImpl::UpdateWebContentsVisibility(bool visible) {
4964 if (!did_first_set_visible_) {
4965 // If this WebContents has not yet been set to be visible for the first
4966 // time, ignore any requests to make it hidden, since resources would
4967 // immediately be destroyed and only re-created after content loaded. In
4968 // this state the window content is undefined and can show garbage.
4969 // However, the page load mechanism requires an activation call through a
4970 // visibility call to (re)load.
4971 if (visible) {
4972 did_first_set_visible_ = true;
4973 WasShown();
4974 }
4975 return;
4976 }
4977 if (visible == should_normally_be_visible_)
4978 return;
4979
4980 if (visible)
4981 WasShown();
4982 else
4983 WasHidden();
4984}
4985
aelias5252baa2016-04-10 01:18:024986void WebContentsImpl::UpdateOverridingUserAgent() {
4987 std::set<RenderViewHost*> render_view_host_set;
4988 for (FrameTreeNode* node : frame_tree_.Nodes()) {
4989 RenderWidgetHost* render_widget_host =
4990 node->current_frame_host()->GetRenderWidgetHost();
4991 if (!render_widget_host)
4992 continue;
4993 RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host);
4994 if (!render_view_host)
4995 continue;
4996 render_view_host_set.insert(render_view_host);
4997 }
4998 for (RenderViewHost* render_view_host : render_view_host_set)
4999 render_view_host->OnWebkitPreferencesChanged();
5000}
5001
avid53461d2016-02-25 17:15:045002void WebContentsImpl::SetJavaScriptDialogManagerForTesting(
5003 JavaScriptDialogManager* dialog_manager) {
5004 dialog_manager_ = dialog_manager;
5005}
5006
[email protected]8ff00d72012-10-23 19:12:215007} // namespace content